
    ^h>                        S SK r S SKrS SKrS SKJr  S SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJrJr  SSKJr  \" 0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$_5      \" 0 SS%_SS%_SS%_SS&_SS'_SS(_SS(_SS_SS_SS_SS_SS)_SS*_SS+_S!S"_S#S$_5      S,.r\R2                  " S-S.S/9=rrS S0K	7   " S1 S2\R6                  R8                  5      r " S3 S4\5      rg)5    N)box)Console)Live)Markdown)Panel)Theme)Table)escape)fill_to_widthwrap_long_lines   )BaseAssistantListenermarkdown.blockzblack on light_steel_blue1zmarkdown.paragraphzmarkdown.textzmarkdown.codebluezmarkdown.code_blockmarkdown.item.bulletz	bold bluezmarkdown.item.numberzmarkdown.h1z
bold blackzmarkdown.h2zmarkdown.h3zmarkdown.h4zmarkdown.h5commandzbold gray11 on wheat1resultzgrey35 on wheat1warningzbright_white on greenerrorzbright_white on redzbright_blue on bright_whitecyanbright_bluez	bold cyanz bold bright_blue on bright_whitezbold bright_yellow on whitezyellow on white)defaultbasicz(    
    
    
    
    
    
    
    
T)ascii)*c                   J   ^  \ rS rSrSrSrS
U 4S jjrS\S\S\	4S jr
S	rU =r$ )
MyListItemF   zAn item in a list.zmarkdown.itemreturnc                 "   > [         TU ]  5         g N)super__init__)self	__class__s    O/home/james-whalen/.local/lib/python3.13/site-packages/chatdbg/util/markdown.pyr#   MyListItem.__init__K   s        consoleoptionsc              #   T  #    UR                  UR                  S-
  S9nUR                  U R                  X0R                  S9nUR                  SSS9n[        SU5      n[        SU5      n[        S	5      n[        U5       H   u  pU	(       a  UOUv   U
 S h  vN   Uv   M"     g  N7f)
N   )width)styler   none)r   z * z   
)update	max_widthrender_lineselementsr.   	get_styleSegment
loop_first)r$   r)   r*   render_optionslinesbullet_stylebulletpaddingnew_linefirstlines              r&   render_bulletMyListItem.render_bulletN   s      g.?.?!.CD$$T]]N**$U(()?(P-'<04=%e,KE!&w.OON -s   BB(B&B( )r   N)__name__
__module____qualname____firstlineno____doc__
style_namer#   r   ConsoleOptionsRenderResultr@   __static_attributes____classcell__)r%   s   @r&   r   r   F   s/     JW ~ ,  r(   r   c                   |    \ rS rSrSS jrS rS rS rSS jrS r	S	 r
S
 rS rS rS rS rS rS rS rS rSrg)ChatDBGMarkdownPrinter\   Nc                 L   Xl         X l        X0l        SU l        [        R
                  " US4S9R                  U l        US :X  a	  [        S   O[        U   U l	        SU l
        SU l        U R                  U5      U l        US:X  a  [        [        R                   S'   SU l
        g g )	N      )fallbackr    r   list_item_openmonokai)_out_debugger_prompt_chat_prefix_left_indentshutilget_terminal_sizecolumns_width_themes_theme_code_theme	_streamed_make_console_consoler   r   r4   )r$   outdebugger_promptchat_prefixr-   themes         r&   r#   ChatDBGMarkdownPrinter.__init__^   s    	 /'..DLL,1TMgi(wu~$**3/G2<H./(D r(   c                 @    [        SXR                  U R                  S9$ )NF)	soft_wrapfilerh   r-   )r   r`   r^   )r$   re   s     r&   rc   $ChatDBGMarkdownPrinter._make_consoleo   s    S4;;WWr(   c                     g r!   rB   )r$   prompt	user_texts      r&   on_begin_query%ChatDBGMarkdownPrinter.on_begin_queryt       r(   c                     g r!   rB   )r$   statss     r&   on_end_query#ChatDBGMarkdownPrinter.on_end_queryw   rs   r(   c                 6    U R                   R                  XS9  g )Nend)rd   print)r$   
renderablerz   s      r&   _printChatDBGMarkdownPrinter._printz   s    J0r(   c                    [        S[        SS9n[        U[        U R                  R                  S5      S9n[        R
                  " SS9nUR                  SU R                  S-
  S	9  UR                  SS
9  UR                  X#5        U$ )NrT   z
on default)r   r.   r   r   )r<   leftr   )justifyr-   )r   )	r   _simple_boxrd   r5   r	   grid
add_columnrZ   add_row)r$   rich_element
left_panelright_paneltables        r&   _wrap_in_panel%ChatDBGMarkdownPrinter._wrap_in_panel}   s    2;lC
--))*:;
 

1%t/@/@1/DE(j.r(   c           	      f    U R                  U R                  U R                  USU5      5      5        g )Nz *** )r}   r   _wrap_and_fill_and_indent)r$   textr.   s      r&   _messageChatDBGMarkdownPrinter._message   s+     > >tWe TU	
r(   c                 (    U R                  US5        g )Nr   r   r$   r   s     r&   on_warnChatDBGMarkdownPrinter.on_warn   s    dI&r(   c                 (    U R                  US5        g )Nr   r   r   s     r&   on_errorChatDBGMarkdownPrinter.on_error   s    dG$r(   c                     U =R                   U-  sl         U R                  [        U R                   U R                  S95      nU R                  R                  U5        g )N
code_theme)rb   r   r   ra   _liver1   r$   r   ms      r&   _stream_append%ChatDBGMarkdownPrinter._stream_append   sC    $DDTDT UV

!r(   c                     SU l         g NrT   )rb   r$   s    r&   on_begin_stream&ChatDBGMarkdownPrinter.on_begin_stream   s	    r(   c                     U R                   S:X  a4  [        SU R                  S9U l        U R                  R	                  S5        U R                  U5        g )NrT   visible)vertical_overflowr)   T)rb   r   rd   r   startr   r   s     r&   on_stream_delta&ChatDBGMarkdownPrinter.on_stream_delta   s@    >>R	4==QDJJJT"D!r(   c                 Z    U R                   S:w  a  U R                  R                  5         g g r   )rb   r   stopr   s    r&   on_end_stream$ChatDBGMarkdownPrinter.on_end_stream   s!    >>RJJOO  r(   c                     U R                   S:X  a8  US :w  a2  U R                  [        XR                  S95      nU R	                  USS9  SU l         g )NrT   r   r0   ry   )rb   r   r   ra   r}   r   s      r&   on_response"ChatDBGMarkdownPrinter.on_response   sF    >>RDDL##HT>N>N$OPAKKtK$r(   c                    U R                   n[        SU U R                   U 3U R                  5      nS[	        U5       S3nXPR                  UR                  5       S-   US5      -  nU R                  U5      nU R                  USS9  g )Nr0   z	[command]z[/]
r   rT   ry   )	rY   r   rX   r^   r
   r   rstripr   r}   )r$   callr   prefixr?   entryr   s          r&   on_function_call'ChatDBGMarkdownPrinter.on_function_call   s    ""r&$*?*?)@GUF4L>///MMOd"FH
 	
 &A2r(   c                     U R                   [        U5      -
  U R                  -
  S-
  n[        UR	                  5       USS9n[        X5      n[        R                  " XS 5      n[        U5      nSU SU S3$ )Nr   z    )subsequent_indentc                     g)NTrB   )_s    r&   <lambda>BChatDBGMarkdownPrinter._wrap_and_fill_and_indent.<locals>.<lambda>   s    tr(   []z[/])	r^   lenrZ   r   
expandtabsr   textwrapindentr
   )r$   r   r   rH   
line_widths        r&   r   0ChatDBGMarkdownPrinter._wrap_and_fill_and_indent   sr    [[3v;.1B1BBQF
t0*PVWT.t^<d|:,avS))r(   )
rY   ra   rd   rX   rZ   r   rW   rb   r`   r^   r!   )rT   )rC   rD   rE   rF   r#   rc   rq   rv   r}   r   r   r   r   r   r   r   r   r   r   r   rK   rB   r(   r&   rN   rN   \   sS    )"X
1 

'%
"	*r(   rN   )osr[   r   richr   rich.consoler   	rich.liver   rich.markdownr   
rich.panelr   
rich.themer   
rich.tabler	   rich.markupr
   chatdbg.util.textr   r   assistant.listenersr   r_   Boxr   markdownListItemr   rN   rB   r(   r&   <module>r      s#   	        "     < 7 	
:	
 ">	
 9	
 V		

 "6	
 #K	
 #K	
 <	
 <	
 <	
 <	
 <	
 .	
 (	
 .	
  *!	
( 	
;	
 "?	
 :	
 V		

 "=	
 #K	
 #K	
 <	
 <	
 <	
 <	
 =	
 4	
 '	
 .	
  *!	
+)V GGKSW c '' ,e*2 e*r(   