ó
    Ãu„jð,  ã                  ó*  • S SK Jr  S SKrS SKJrJrJrJr  S SKJ	r	  S SK
Jr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  S SKJr  S SKJr  S SKJ r   \(       a  S SK!J"r"  \RF                  " S5      RH                  r% " S S\SS9r&g)é    )ÚannotationsN)ÚTYPE_CHECKINGÚIterableÚOptionalÚSequence©Úcell_len)ÚHighlighterÚReprHighlighter)ÚStyle)ÚText)Úwork)Ú
line_split)ÚLRUCache)ÚSize)Úvar)Ú
ScrollView)Ú	Selection)ÚStrip)ÚSelfz[ -]c                  óÜ  ^ • \ rS rSr% SrSrSr\\\	      " S5      r
S\S'    \" S5      rS\S	'           S               S U 4S
 jjjr\S!S j5       r\S"S j5       rS#U 4S jjrS$S jr\S%S j5       r\S&S j5       r\" SS9S'S j5       rS#S jr S(     S)S jjr S(     S*S jjr S(     S+S jjrS,S jrS-S jrS.S jrS/S jrS0S jr S1S jr!S2S3U 4S jjjr"Sr#U =r$$ )4ÚLogé   zA widget to log text.Tz¬
    Log {
        background: $surface;
        color: $text;
        overflow: scroll;
        &:focus {
            background-tint: $foreground 5%;
        }
    }
    Nzvar[int | None]Ú	max_linesz	var[bool]Úauto_scrollc                óÀ   >• [         TU ]  XEXgS9  Xl         X l        X0l        / U l        SU l        SU l        [        S5      U l	        [        5       U l         SU l        g)aT  Create a Log widget.

Args:
    highlight: Enable highlighting.
    max_lines: Maximum number of lines to display.
    auto_scroll: Scroll to end on new lines.
    name: The name of the text log.
    id: The ID of the text log in the DOM.
    classes: The CSS classes of the text log.
    disabled: Whether the text log is disabled or not.
)ÚnameÚidÚclassesÚdisabledr   i   N)ÚsuperÚ__init__Ú	highlightr   r   Ú_linesÚ_widthÚ_updatesr   Ú_render_line_cacher   ÚhighlighterÚ_clear_y)	Úselfr#   r   r   r   r   r   r    Ú	__class__s	           €Ú¢C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\textual/widgets/_log.pyr"   ÚLog.__init__/   s`   ø€ ô* 	‰Ñ˜d°7ÐÑNØ"ŒØ"Ø"ŒØ&ÔØ!#ˆŒØˆŒØˆŒÜ8@À»ˆÔÜ(7Ó(9ˆÔØEØˆ�ó    c                ó   • g)NT© ©r*   s    r,   Úallow_selectÚLog.allow_selectQ   s   € àr.   c                ó   • U R                   $ )zzThe raw lines in the Log.

Note that this attribute is read only.
Changing the lines will not update the Log's contents.

)r$   r1   s    r,   ÚlinesÚ	Log.linesU   s   € ð �{‰{Ðr.   c                óV   >• [         TU ]  5         U R                  R                  5         g)z%Called by Textual when styles update.N)r!   Únotify_style_updater'   Úclear)r*   r+   s    €r,   r8   ÚLog.notify_style_update_   s    ø€ ä‰Ñ#Ô%Ø×Ñ×%Ñ%Õ'r.   c                ó¢   • XR                   :X  a@  [        X R                  5      U l        [        U R                  U R                  5      U l        gg)znUpdate the virtual size width.

Args:
    updates: A counter of updates.
    size: Maximum size of new lines.
N)r&   Úmaxr%   r   Ú
line_countÚvirtual_size)r*   ÚupdatesÚsizes      r,   Ú_update_maximum_widthÚLog._update_maximum_widthd   s:   € ð —m‘mÓ#Ü˜d§K¡KÓ0ˆDŒKÜ $ T§[¡[°$·/±/Ó BˆDÕð $r.   c                óv   • U R                   (       a(  [        U R                   5      U R                   S   S:H  -
  $ g)zNumber of lines of content.éÿÿÿÿÚ r   )r$   Úlenr1   s    r,   r=   ÚLog.line_counto   s/   € ð �;�;Ü�t—{‘{Ó# t§{¡{°2¡¸"Ñ'<Ñ=Ð=Ør.   c                ó6   • [        SUR                  5       5      $ )z‰Process a line before it is rendered to remove control codes.

Args:
    line: A string.

Returns:
    New string with no control codes.
u   ï¿½)Ú_sub_escapeÚ
expandtabs)ÚclsÚlines     r,   Ú_process_lineÚLog._process_linev   s   € ô ˜5 $§/¡/Ó"3Ó4Ð4r.   )Úthreadc                ó¤   ^• U(       aH  U R                   m[        U4S jU 5       5      nU R                  R                  U R                  X5        gg)z™A thread worker to update the width in the background.

Args:
    updates: The update index at the time of invocation.
    lines: Lines that were added.
c              3  óF   >#   • U  H  n[        T" U5      5      v •  M     g 7f©Nr   )Ú.0rL   rM   s     €r,   Ú	<genexpr>Ú#Log._update_size.<locals>.<genexpr>Œ   s   øé € ÐMÂu¸tœX¡m°DÓ&9×:Ð:Âuùs   ƒ!N)rM   r<   ÚappÚcall_from_threadrA   )r*   r?   r5   Ú
max_lengthrM   s       @r,   Ú_update_sizeÚLog._update_size‚   sB   ø€ ö Ø ×.Ñ.ˆMÜÔMÁuÓMÓMˆJØ�H‰H×%Ñ% d×&@Ñ&@À'ÕVð r.   c                ód  • U R                   c  g[        U R                  5      U R                   -
  nUS:”  au  U R                  nUR	                  5        Vs0 s H  o3U:”  d  M
  X1-
  X#   _M     nnUR                  5         UR                  5        H	  u  p5XRU'   M     U R                  SU2	 ggs  snf )z/Prune lines if there are more than the maximum.Nr   )r   rF   r$   r'   Úkeysr9   Úitems)r*   Úremove_linesÚ_cacheÚyÚupdated_cacherL   s         r,   Ú_prune_max_linesÚLog._prune_max_lines�   s°   € à�>‰>Ñ!ØÜ˜4Ÿ;™;Ó'¨$¯.©.Ñ8ˆØ˜!ÓØ×,Ñ,ˆFð 6<·[±[´]óÚ5B°È,ÑFVÓ+�Ñ  &¡)Ò+±]ð ð ð �L‰LŒNà(×.Ñ.Ö0‘�Ø �q“	ñ 1à—‘˜M˜\˜MÑ*ð ùòs   Á	B-Á"B-c           
     ó  • U R                   nU(       Ga  U R                  (       d  U R                  R                  S5        [        U5       H§  u  pEU R                  S==   U-  ss'   [	        U R
                  [        U R                  U R                  S   5      5      5      U l        U R                  [        U R                  5      S-
  5        U(       d  MŒ  U R                  R                  S5        M©     [        U R
                  U R                  5      U l        U R                  b3  [        U R                  5      U R                  :”  a  U R                  5         Uc  U R                  OUnU(       a  U R!                  SSSS9  U $ )zªWrite to the log.

Args:
    data: Data to write.
    scroll_end: Scroll to the end after writing, or `None` to use `self.auto_scroll`.

Returns:
    The `Log` instance.
rE   rD   é   FT©ÚanimateÚ	immediateÚx_axis)Úis_vertical_scroll_endr$   Úappendr   r<   r%   r	   rM   Úrefresh_linesrF   r   r=   r>   r   rb   r   Ú
scroll_end)r*   Údatarm   rj   rL   Úendingr   s          r,   ÚwriteÚ	Log.write¢   s   € ð "&×!<Ñ!<ÐßØ—;—;Ø—‘×"Ñ" 2Ô&Ü *¨4Ö 0‘�Ø—‘˜B“ 4Ñ'“Ü!Ø—K‘K¤¨$×*<Ñ*<¸T¿[¹[È¹_Ó*MÓ!Nó�”ð ×"Ñ"¤3 t§{¡{Ó#3°aÑ#7Ô8ß�6Ø—K‘K×&Ñ& rÖ*ñ !1ô !% T§[¡[°$·/±/Ó BˆDÔà�>‰>Ñ%¬#¨d¯k©kÓ*:¸T¿^¹^Ó*KØ×!Ñ!Ô#à*4Ñ*<�d×&Ò&À*ˆÞØ�O‰O E°TÀ%ˆOÑHØˆr.   c                ó,   • U R                  U/U5        U $ )zÂWrite content on a new line.

Args:
    line: String to write to the log.
    scroll_end: Scroll to the end after writing, or `None` to use `self.auto_scroll`.

Returns:
    The `Log` instance.
)Úwrite_lines)r*   rL   rm   s      r,   Ú
write_lineÚLog.write_lineÆ   s   € ð 	×Ñ˜$˜ Ô,Øˆr.   c                óÂ  • U R                   nUc  U R                  OUn/ nU H"  nUR                  UR                  5       5        M$     [	        U R
                  5      nU R
                  R                  U5        U R                  b3  [	        U R
                  5      U R                  :”  a  U R                  5         [        U R                  [	        U R
                  5      5      U l
        U R                  U R                  U5        U R                  U[	        U5      5        U(       a+  U R                  (       d  U(       a  U R                  SSSS9  U $ U R!                  5         U $ )zÇWrite an iterable of lines.

Args:
    lines: An iterable of strings to write.
    scroll_end: Scroll to the end after writing, or `None` to use `self.auto_scroll`.

Returns:
    The `Log` instance.
FTrf   )rj   r   ÚextendÚ
splitlinesrF   r$   r   rb   r   r%   r>   rY   r&   rl   Úis_vertical_scrollbar_grabbedrm   Úrefresh)r*   r5   rm   rj   r   Ú	new_linesrL   Ú
start_lines           r,   rs   ÚLog.write_lines×   s  € ð "&×!<Ñ!<ÐØ*4Ñ*<�d×&Ò&À*ˆØˆ	ÛˆDØ×Ñ˜TŸ_™_Ó.Ö/ñ ä˜Ÿ™Ó%ˆ
Ø�‰×Ñ˜9Ô%Ø�>‰>Ñ%¬#¨d¯k©kÓ*:¸T¿^¹^Ó*KØ×!Ñ!Ô#Ü  §¡¬c°$·+±+Ó.>Ó?ˆÔØ×Ñ˜$Ÿ-™-¨Ô3Ø×Ñ˜:¤s¨9£~Ô6æØ×6×6Þ&à�O‰O E°TÀ%ˆOÑHð ˆð �L‰LŒNØˆr.   c                óÖ   • U R                   R                  5         SU l        U R                  R                  5         U =R                  S-  sl        [        SS5      U l        SU l        U $ )z1Clear the Log.

Returns:
    The `Log` instance.
r   re   )r$   r9   r%   r'   r&   r   r>   r)   r1   s    r,   r9   Ú	Log.clearû   sU   € ð 	�‰×ÑÔØˆŒØ×Ñ×%Ñ%Ô'Ø�Š˜Ñ�Ü   A›JˆÔØˆŒØˆr.   c                ó^   • SR                  U R                  5      nUR                  U5      S4$ )zéGet the text under the selection.

        Args:
            selection: Selection information.

        Returns:
            Tuple of extracted text and ending (typically "
" or " "), or `None` if no text could be extracted.
        Ú
)Újoinr$   Úextract)r*   Ú	selectionÚtexts      r,   Úget_selectionÚLog.get_selection	  s,   € ð �y‰y˜Ÿ™Ó%ˆØ× Ñ  Ó&¨Ð,Ð,r.   c                óX   • U R                   R                  5         U R                  5         g rR   )r'   r9   rz   )r*   r„   s     r,   Úselection_updatedÚLog.selection_updated  s   € Ø×Ñ×%Ñ%Ô'Ø�‰�r.   c                ór   • U R                   u  p#U R                  X1-   X R                  R                  5      nU$ )z]Render a line of content.

Args:
    y: Y Coordinate of line.

Returns:
    A rendered line.
)Úscroll_offsetÚ_render_liner@   Úwidth)r*   r`   Úscroll_xÚscroll_yÚstrips        r,   Úrender_lineÚLog.render_line  s3   € ð "×/Ñ/ÑˆØ×!Ñ! (¡,°¿)¹)¿/¹/ÓJˆØˆr.   c                ó  • U R                   nU[        U R                  5      :¼  a  [        R                  " X45      $ U R                  X5      nUR                  c   eUR                  X"U-   U5      nUR                  X!5      nU$ )z»Render a line into a cropped strip.

Args:
    y: Y offset of line.
    scroll_x: Current horizontal scroll.
    width: Width of the widget.

Returns:
    A Strip suitable for rendering.
)	Ú
rich_stylerF   r$   r   ÚblankÚ_render_line_stripÚ_cell_lengthÚcrop_extendÚapply_offsets)r*   r`   r�   rŽ   r•   rL   s         r,   r�   ÚLog._render_line&  s{   € ð —_‘_ˆ
Ø”�D—K‘KÓ Ó Ü—;’;˜uÓ1Ð1à×&Ñ& qÓ5ˆØ× Ñ Ñ,Ð,Ð,Ø×Ñ °UÑ*:¸JÓGˆØ×!Ñ! (Ó.ˆØˆr.   c                ór  • U R                   nXR                  ;   a  Uc  U R                  U   $ U R                  U R                  U   5      n[	        USS9nUR                  U5        U R                  (       a  U R                  U5      nUbb  UR                  XR                  -
  5      =nbB  Uu  pxUS:X  a  [        U5      nU R                  R                  S5      n	UR                  X—U5        [        UR                  U R                  R                   5      [#        U5      5      n
Ub  X R                  U'   U
$ )z‚Render a line into a Strip.

Args:
    y: Y offset of line.
    rich_style: Rich style of line.

Returns:
    An uncropped Strip.
T)Úno_wraprD   zscreen--selection)Útext_selectionr'   rM   r$   r   Ústylizer#   r(   Úget_spanr)   rF   ÚscreenÚget_component_rich_styler   ÚrenderrV   Úconsoler	   )r*   r`   r•   r„   Ú_lineÚ	line_textÚselect_spanÚstartÚendÚselection_stylerL   s              r,   r—   ÚLog._render_line_strip;  s  € ð ×'Ñ'ˆ	Ø×'Ñ'Ó'¨IÑ,=Ø×*Ñ*¨1Ñ-Ð-à×"Ñ" 4§;¡;¨q¡>Ó2ˆä˜¨Ñ-ˆ	Ø×Ñ˜*Ô%à�>�>Ø×(Ñ(¨Ó3ˆIØÑ Ø(×1Ñ1°!·m±mÑ2CÓDÐD�ÑQØ(‘
�Ø˜"“9Ü˜i›.�Cà"&§+¡+×"FÑ"FØ'ó#�ð ×!Ñ! /¸#Ô>ä�Y×%Ñ% d§h¡h×&6Ñ&6Ó7¼À%»ÓIˆàÑ Ø)-×#Ñ# AÑ&Øˆr.   c                ó€   >• [        XU-   5       H  nU R                  R                  U5        M      [        TU ]  XS9  g)zxRefresh one or more lines.

Args:
    y_start: First line to refresh.
    line_count: Total number of lines to refresh.
)r=   N)Úranger'   Údiscardr!   rl   )r*   Úy_startr=   r`   r+   s       €r,   rl   ÚLog.refresh_linesa  s=   ø€ ô �w¨*Ñ 4Ö5ˆAØ×#Ñ#×+Ñ+¨AÖ.ñ 6ä‰Ñ˜gÐÒ=r.   )
r)   r$   r'   r&   r%   r   r#   r(   r   r>   )FNTNNNF)r#   Úboolr   z
int | Noner   r±   r   ú
str | Noner   r²   r   r²   r    r±   ÚreturnÚNone)r³   r±   )r³   zSequence[str])r³   r´   )r?   Úintr@   rµ   r³   r´   )r³   rµ   )rL   Ústrr³   r¶   )r?   rµ   r5   z	list[str]r³   r´   rR   )rn   r¶   rm   úbool | Noner³   r   )rL   r¶   rm   r·   r³   r   )r5   zIterable[str]rm   r·   r³   r   )r³   r   )r„   r   r³   ztuple[str, str] | None)r„   zSelection | Noner³   r´   )r`   rµ   r³   r   )r`   rµ   r�   rµ   rŽ   rµ   r³   r   )r`   rµ   r•   r   r³   r   )re   )r¯   rµ   r=   rµ   r³   r´   )%Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚALLOW_SELECTÚDEFAULT_CSSr   r   rµ   r   Ú__annotations__r   r"   Úpropertyr2   r5   r8   rA   r=   ÚclassmethodrM   r   rY   rb   rp   rt   rs   r9   r†   r‰   r’   r�   r—   rl   Ú__static_attributes__Ú__classcell__)r+   s   @r,   r   r      sÈ  ø‡ Ùà€Lð	€Kð "% X¨c¡]Ò!3°DÓ!9€IˆÓ9Ø)á  ›Y€K�Ó&Ø,ð  Ø $Ø ØØØ"Øð àð ð ð ð ð	 ð
 ð ð ð ð ð ð ð ð 
÷ ð  ðD óó ðð óó ð÷(ô
	Cð óó ðð ó	5ó ð	5ñ 
�Ñó
Wó ð
Wô+ð, #'ð"àð"ð  ð"ð 
õ	"ðN #'ðàðð  ðð 
õ	ð( #'ð"àð"ð  ð"ð 
õ	"ôHô
-ôôôô*$÷L	>÷ 	>r.   r   T)Ú	can_focus)'Ú
__future__r   ÚreÚtypingr   r   r   r   Ú
rich.cellsr	   Úrich.highlighterr
   r   Ú
rich.styler   Ú	rich.textr   Útextualr   Útextual._line_splitr   Útextual.cacher   Útextual.geometryr   Útextual.reactiver   Útextual.scroll_viewr   Útextual.selectionr   Útextual.stripr   Útyping_extensionsr   ÚcompileÚsubrI   r   r0   r.   r,   Ú<module>r×      s`   ðÝ "ã 	ß >Ó >å ß 9Ý Ý å Ý *Ý "Ý !Ý  Ý *Ý 'Ý æÝ&à�jŠjÐ*Ó+×/Ñ/€ôP>ˆ* ó P>r.   