
    Cj                       % S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
JrJrJr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$  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K0J1r1  SSK2J3r3  SSK4Jr  SSK5J6r6J7r7J8r8  / SQr9\S\:4   r;S\<S'    \S\\:4   r=S\<S'    \" \," SSSSSS9\," SSSSSS9S9r> \" 5       r? \R                  " S 5      rA/ S!QrBS"\<S#'   \B V s0 s H  o S_M     sn rCS"\<S$'   \C4     S-S% jjrD\R                  R                   " S& S'\5      5       rG\R                  R                  \ " S( S\85      5       5       rH " S) S*5      rI\H" S+5      rJS"\<S,'   gs  sn f ).a}  
Content is a container for text, with spans marked up with color / style.
It is equivalent to Rich's Text object, with support for more of Textual features.

Unlike Rich Text, Content is *immutable* so you can't modify it in place, and most methods will return a new Content instance.
This is more like the builtin str, and allows Textual to make some significant optimizations.

    )annotationsN)cached_propertytotal_ordering)
itemgetter)CallableIterable
NamedTupleSequenceUnion)divide_line)set_cell_size)Console)Segment)Style)TerminalTheme)Text)Final	TypeAliascell_len)
active_app)	loop_last)	FIFOCache)Color)	TextAlignTextOverflow)	Selection)Strip)RenderOptionsRulesMapVisual)ContentTypeContentSpanr#   r   r"   ContentText)ansi)
background
foregroundz\s+$)               r   _STRIP_CONTROL_CODES_CONTROL_STRIP_TRANSLATEc                $    U R                  U5      $ )zRemove control codes from text.

Args:
    text (str): A string possibly contain control codes.

Returns:
    str: String with control codes removed.
)	translate)text_translate_tables     a/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/content.py_strip_control_codesr6   D   s     >>*++    c                  V    \ rS rSr% SrS\S'   S\S'   S\S'   SS jrSS	 jrSS
 jrSr	g)r$   R   z0A style applied to a range of character offsets.intstartendStyle | strstylec              #  d   #    U R                   v   U R                  v   SU R                  4v   g 7f)Nr>   )r;   r<   r>   selfs    r5   __rich_repr__Span.__rich_repr__Z   s'     jjhhtzz!!s   .0c                <    U(       a  U u  p#n[        X#U-   U5      $ U $ )zExtend the span by the given number of cells.

Args:
    cells (int): Additional space to add to end of span.

Returns:
    Span: A span.
r$   )rA   cellsr;   r<   r>   s        r5   extendSpan.extend_   s'      $EU{E22r7   c                z    US:  a   U u  p#n[        X!-   =nS:  a  UOSX1-   U5      $ U u  p#n[        X!-   X1-   U5      $ )zShift a span a given distance.

Note that the start offset is clamped to 0.
The end offset is not clamped, as it is assumed this has already been checked by the caller.

Args:
    distance: Number of characters to move.

Returns:
    New Span.
r   rE   )rA   distancer;   r<   r>   offsets         r5   _shiftSpan._shiftm   s]     a< $E%*%556:3>SX  !%E(#.%@@r7    Nreturnzrich.repr.Result)rF   r:   rP   'Span')rJ   r:   rP   rQ   )
__name__
__module____qualname____firstlineno____doc____annotations__rB   rG   rL   __static_attributes__rN   r7   r5   r$   r$   R   s%    :J	H"
Ar7   r$   c            	         \ rS rSrSr/ SQrSSSS.r    SS         STS jjrSUS jr\	SVS j5       r
\SUS j5       r\SWS j5       r\ SX     SYS jj5       r\SZS j5       r\ S[     S\S jj5       r\   S]         S^S jj5       r\S[S_S jj5       r\SS
S.       S`S jj5       rSWS jrSaS jrSbS jrSbS jrScS jrSdS jrSeS jrSfS jrSSS S!S"S	S	S	\R<                  4	                     SgS# jjr          ShS$ jr SiS% jr!SVS& jr"SiS' jr#SjS( jr$\	SkS) j5       r%\	SiS* j5       r&\	SUS+ j5       r'\	SWS, j5       r(\	SWS- j5       r)SlS. jr*SmS/ jr+SnS0 jr,\SoS1 j5       r-SpS2 jr.SqSrS3 jjr/SsS4 jr0SSS5.       StS6 jjr1SuS7 jr2SvS8 jr3S S S9.     SwS: jjr4SxSyS; jjr5SxSyS< jjr6SxSyS= jjr7SxSzS> jjr8S{S|S? jjr9S{S|S@ jjr:S}S~SA jjr; S       SSB jjr<  S       SSC jjr=\R|                  " 5       SDS	4       SSE jjr?\R|                  " 5       S4     SSF jjr@SG rASSH jrBSSI jrC SS S SJ.       SSK jjjrDS[SSL jjrESSM jrFSSN jrGSSSO jjrHS	SP.       SSQ jjrISRrJg	)r#      zText content with marked up spans.

This object can be considered immutable, although it might update its internal state
in a way that is consistent with immutability.

)_text_spans_cell_lengthleftrightfull)r;   r<   justify NTc                    U(       a  U(       a  [        U5      OUU l        Uc  / OUU l        X0l        SU l        SU l        SU l        SU l        SU l        [        U R                  5      S:*  U l
        g)z
Initialize a Content object.

Args:
    text: text content.
    spans: Optional list of spans.
    cell_length: Cell length of text if known, otherwise `None`.
    strip_control_codes: Strip control codes that may break output?
N)Nr      )r6   r[   r\   r]   _optimal_width_cache_minimal_width_cache_height_cache_divide_cache_split_cachelen_simplified)rA   r3   spanscell_lengthstrip_control_codess        r5   __init__Content.__init__   sy    $ +>$ &D 	
 )."5'04!04!GP  	  	 t{{+q0r7   c                    U R                   $ Nr[   r@   s    r5   __str__Content.__str__   s    zzr7   c                b    U R                    H  nUR                  UR                  ::  d  M    g   g)zCheck if the line is regular (spans.end > span.start for all spans).

This is a debugging aid, and unlikely to be useful in your app.

Returns:
    `True` if the content is regular, `False` if it is not (and broken).
FT)rl   r<   r;   )rA   spans     r5   _is_regularContent._is_regular   s*     JJDxx4::%  r7   c                   SSK Jn  / nU R                  nS/S U R                   5       QS U R                   5       Q[	        U5      SS4PnUR                  [        SS5      S	9  SnUR                  nU H?  u  pxn	Xu:  a  U" U" X5U 5      5        UnU	(       d  M&  U" U(       a  S
U	 S3OSU	 S35        MA     SR                  U5      n
U
$ )zGet the content markup that would create this Content instance.

This is essentially the inverse of [`Content.from_markup`][textual.content.Content.from_markup].

Returns:
    str: A string potentially creating markup tags.
r   )escape)r   FNc              3  R   #    U  H  oR                   S UR                  4v   M     g7fFN)r;   r>   .0rw   s     r5   	<genexpr>!Content.markup.<locals>.<genexpr>   s     F+$zz5$**-+   %'c              3  R   #    U  H  oR                   S UR                  4v   M     g7fTN)r<   r>   r~   s     r5   r   r      s     C{txxtzz*{r   TNrd   keyz[/][rb   )	textual.markupr{   plainr\   rj   sortr   appendjoin)rA   r{   outputr   markup_spanspositionr   rK   closingr>   markups              r5   r   Content.markup   s     	*


F$++F
 Dt{{C
 Zt$	
 	jA./&2"FU veV456!uE7!}qq\B '3 r7   c                    [         $ )zGet an empty (blank) content)EMPTY_CONTENT)clss    r5   emptyContent.empty   s
     r7   c                    [        U[        5      (       a  U$ [        U[        5      (       a   U(       a  U R                  U5      $ U " U5      $ [        U[        5      (       a  U R                  U5      $ [        S5      e)a+  Construct content from Text or str. If the argument is already Content, then
return it unmodified.

This method exists to make (Rich) Text and Content interchangeable. While Content
is preferred, we don't want to make it harder than necessary for apps to use Text.

Args:
    markup_content_or_text: Value to create Content from.
    markup: If `True`, then str values will be parsed as markup, otherwise they will
        be considered literals.

Raises:
    TypeError: If the supplied argument is not a valid type.

Returns:
    A new Content instance.
zAThis method expects a str, a Text instance, or a Content instance)
isinstancer#   strfrom_markupr   from_rich_text	TypeError)r   markup_content_or_textr   s      r5   	from_textContent.from_text   su    * ,g66)).44'=>>122.55%%&<==S r7   c                    Sn[        U[        5      (       a  U(       a  [        S5      eU$ [        U5      nSU;  a  U(       d  [        U5      $ SSKJn  U" X=(       d    SS9nU$ )a  Create content from markup, optionally combined with template variables.

If `markup` is already a Content instance, it will be returned unmodified.

See the guide on [Content](../guide/content.md#content-class) for more details.


Example:
    ```python
    content = Content.from_markup("Hello, [b]$name[/b]!", name="Will")
    ```

Args:
    markup: Content markup, or Content.
    **variables: Optional template variables used

Returns:
    New Content instance.
Tz4A literal string is require to substitute variables.r   r   )
to_contentN)template_variables)r   r#   
ValueErrorr6   r   r   )r   r   	variables_rich_traceback_omitr   contents         r5   r   Content.from_markup  s`    *  $fg&& !WXXM%f-fY6?"-V8ITJr7   c                    [        U[        5      (       a  [        R                  " U5      nSnUb  UR                  nO, [
        R                  " 5       nUR                  R                  nUR                  (       a   [
        R                  " 5       R                  nUR                   VVVs/ s HY  u  pgn[        UU[        U[        5      (       a  [        R                  " U" U5      U5      O[        R                  " X5      5      PM[     n	nnnO/ n	U " UR                   U	5      n
UR"                  (       a{   [
        R                  " 5       R                  nU
R%                  [        UR"                  [        5      (       a  UR"                  O [        R                  " UR"                  U5      5      n
U
$ ! [         a    [        R                  n GNff = f! [         a    Sn GNHf = fs  snnnf ! [         a    Sn Nf = f)zCreate equivalent Visual Content for str or Text.

Args:
    text: String or Rich Text.
    console: A Console object to use if parsing Rich Console markup, or `None` to
        use app default.

Returns:
    New Content.
N)r   r   r   r   	get_styler   getconsoleLookupError	RichStyleparser\   
ansi_themer$   r   from_rich_styler   r>   stylize_before)r   r3   r   r   r   appr;   r<   r>   rl   r   s              r5   r   Content.from_rich_text.  s    dC  ##D)D+/
))I2 nn&  KK11	;;"'^^-88
 *. *5%E  &eS11 --i.>
K"225E *5  E Edjj%(::"'^^-88
 ,,djj#.. 

**4::zBG
 K  ,%OO	,  "!
"(  "!
"s<   F3 <G +A G'7G. 3GGG$#G$.G=<G=c           	     n    U(       d  [         $ U " UU(       a  [        S[        U5      U5      /OSUUS9nU$ )a  Create a Content instance from text and an optional style.

Args:
    text: String content.
    style: Desired style.
    cell_length: Cell length of text if known, otherwise `None`.
    strip_control_codes: Strip control codes that may break output.

Returns:
    New Content instance.
r   Nrn   )r   r$   rj   )r   r3   r>   rm   rn   new_contents         r5   styledContent.styledm  s?    &   +0T!SY&'d 3	
 r7   c                ^    U(       d  [         $ U " SU-  U(       a  [        SX5      /OSUS9nU$ )zGet a Content instance consisting of spaces.

Args:
    width: Width of blank content (number of spaces).
    style: Style of blank.

Returns:
    Content instance.
 r   Nrm   )r   r$   )r   widthr>   blanks       r5   r   Content.blank  s9       %K',T!U"#$

 r7   )r<   rn   c                  / n/ n[         nUR                  nSnU GH  n	[        U	[        5      (       a  U" U	5        U[	        U	5      -  nM1  [        U	[
        5      (       aG  U	u  pU" U
5        U(       a$  UR                  U" X[	        U
5      -   U5      5        U[	        U
5      -  nM  [        U	[        5      (       d  M  U" U	R                  5        U	R                  (       a?  UR                  U	R                   VVVs/ s H  u  pnU" X-   X-   U5      PM     snnn5        U[	        U	R                  5      -  nGM!     W(       a  U" U5        U " SR                  U5      XRS9nU$ s  snnnf )a  Construct new content from string, content, or tuples of (TEXT, STYLE).

This is an efficient way of constructing Content composed of smaller pieces of
text and / or other Content objects.

Example:
    ```python
    content = Content.assemble(
        Content.from_markup("[b]assemble[/b]: "),  # Other content
        "pieces of text or content into a",  # Simple string of text
        ("a single Content instance", "underline"),  # A tuple of text and a style
    )
    ```

Args:
    *parts: Parts to join to gether. A *part* may be a simple string, another Content
    instance, or tuple containing text and a style.
    end: Optional end to the Content.
    strip_control_codes: Strip control codes that may break output.
r   rb   r   )r$   r   r   r   rj   tupler#   r   rl   rG   r   )r   r<   rn   partsr3   rl   _Spantext_appendr   part	part_text
part_styler;   r>   assembled_contents                  r5   assembleContent.assemble  sC   6 kkD$$$D!CI%D%(((,%	I&LLh3y>(A:N C	N*D'**DJJ'::LL 6:ZZ5? 1E "%"2CNEJ5? C

O++ , GGDM5
 ! s   =E%c                   U R                   =n(       a  U R                  (       a  U $ [        SSS5      n/ nSnU H}  nUR                  UR                  :X  aM  UR
                  UR
                  :X  a3  [        UR                  UR                  UR
                  5      =o#S'   SnMj  UR                  U5        UnM     U(       a  X0R                   SS& SU l        U $ )ar  Simplify spans by joining contiguous spans together.

This may produce faster renders if you have concatenated a large number of small pieces
of content with repeating styles.

Note that this modifies the Content instance in-place, which might appear
to violate the immutability constraints, but it will not change the rendered output,
nor its hash.

Returns:
    Self.
r&   rb   FTN)r\   rk   r$   r;   r<   r>   r   )rA   rl   	last_span	new_spanschangedrw   s         r5   simplifyContent.simplify  s     $$)9)9KR$	 "	DzzY]]*tzzY__/L,0$((DJJ,WW	bM  & 	  &KKNr7   c                p    U(       a.  [        U R                  / U R                  QUQU R                  SS9$ U $ )znAdds spans to this Content instance.

Args:
    spans: A sequence of spans.

Returns:
    A Content instance.
Fr   )r#   r   r\   r]   )rA   rl   s     r5   	add_spansContent.add_spans  s?     

&$++&&!!$)	  r7   c                    [        U[        5      (       a  U R                  U:H  $ [        U[        5      (       a  U R                  UR                  :H  $ [        $ )z:Compares text only, so that markup doesn't effect sorting.r   r   r   r#   NotImplementedrA   others     r5   __eq__Content.__eq__  sD    eS!!::&&w''::,,r7   c                    [        U[        5      (       a  U R                  U:  $ [        U[        5      (       a  U R                  UR                  :  $ [        $ rr   r   r   s     r5   __lt__Content.__lt__  sD    eS!!::%%eW%%::++r7   c                t    XL a  gU R                   UR                   :w  a  gU R                  UR                  :H  $ )am  Compare to another Content object.

Two Content objects are the same if their text *and* spans match.
Note that if you use the `==` operator to compare Content instances, it will only consider
the plain text portion of the content (and not the spans).

Args:
    content: Content instance.

Returns:
    `True` if this is identical to `content`, otherwise `False`.
TF)r   rl   rA   r   s     r5   is_sameContent.is_same  s2     ?::&zzW]]**r7   c                    U R                   c3  [        S U R                  R                  S5       5       5      =U l         nOU R                   nX1R	                  SS5      S-  -   $ )a`  Get optimal width of the Visual to display its content.

The exact definition of "optimal width" is dependant on the Visual, but
will typically be wide enough to display output without cropping or wrapping,
and without superfluous space.

Args:
    rules: A mapping of style rules, such as the Widgets `styles` object.

Returns:
    A width in cells.

c              3  8   #    U  H  n[        U5      v   M     g 7frr   r   )r   lines     r5   r   ,Content.get_optimal_width.<locals>.<genexpr>=  s      4+A4+As   
line_padr      )re   maxr   splitr   )rA   rulescontainer_widthr   s       r5   get_optimal_widthContent.get_optimal_width.  sf     $$,03 4+/::+;+;D+A4 1 D% --EyyQ/!333r7   c                   U R                   R                  5       (       d  gU R                  c2  [        S U R                   R	                  5        5       5      =U l        nOU R                  nX!R                  SS5      S-  -   $ )z)Minimal width is the largest single word.r   c              3     #    U  H?  nUR                  5         H'  nUR                  5       (       d  M  [        U5      v   M)     MA     g 7frr   )r   stripr   )r   r   words      r5   r   ,Content.get_minimal_width.<locals>.<genexpr>I  s;      43D JJLD::< ( 3s
   -A	A	r   r   )r   r   rf   r   
splitlinesr   )rA   r   r   s      r5   get_minimal_widthContent.get_minimal_widthD  sx    zz!!$$,03 4 JJ1134 1 D% --EyyQ/!333r7   c                   UR                   nU" SS5      S-  nU" SS5      nU" SS5      S:H  nX$-   XV4nU R                  S   U:X  a  U R                  S	   nU$ U R                  R                  X$-
  XVS
9n	[	        U	5      nXx4U l        U$ )zGet the height of the Visual if rendered at the given width.

Args:
    rules: A mapping of style rules, such as the Widgets `styles` object.
    width: Width of visual in cells.

Returns:
    A height in lines.
r   r   r   text_overflowfold	text_wrapwrapnowraprd   )overflowno_wrap)r   rg   without_spans_wrap_and_formatrj   )
rA   r   r   get_ruler   r   r   	cache_keyheightliness
             r5   
get_heightContent.get_heightS  s     99J*Q.OV4;/8;%x9	a I-''*F  &&77 8 8 E ZF"+!4Dr7   r   Fr   r+   c                j   / nUb  UR                   nOSS jn[        U R                  SS95       GH  u  pU	b  UR                  U	5      nUb>  U" U5      =nb3  Uu  nnUS:X  a  [	        UR
                  5      nUR                  UUU5      nUR                  U5      nU(       av  US:X  aO  [        [        SUR                  U5      5      SS nUR                  U5       Vs/ s H  n[        XXUS	9PM     nnGOUR                  XS
:H  S9n[        XXUS	9nU/nO[        XXUS	9n[        UR
                  XS-  -
  US:H  S9nUR                  R                  U5      nUS
:H  n[        U5       VVs/ s H;  u  nnU(       a  UR                  UUS9OUR!                  5       R                  UUS9PM=     nnn[#        US/UQ5       VVs/ s H2  u  nn[        U
UR%                  U5      R'                  XU5      UUUUS9PM4     nnnSUS   l        UR+                  U5        GM     U$ s  snf s  snnf s  snnf )ak  Wraps the text and applies formatting.

Args:
    width: Desired width.
    align: Text alignment.
    overflow: Overflow method.
    no_wrap: Disabled wrapping.
    tab_size: Cell with of tabs.
    selection: Selection information or `None` if no selection.
    selection_style: Selection style, or `None` if no selection.

Returns:
    List of formatted lines.
Nc                    g rr   rN   )ys    r5   get_span*Content._wrap_and_format.<locals>.get_span  s    r7   T)allow_blankr&   r   r   rd   )r
  alignellipsisr  r   )r   )r  )r
  r:   rP   ztuple[int, int] | None)r  	enumerater   stylizerj   r   expand_tabslistrangerm   divide_FormattedLinetruncater   r   r   rstripzip
rstrip_endpadline_endrG   )rA   r   r  r   r   r   tab_size	selectionselection_style
post_styler   output_linesr  r
  r   rw   r;   r<   cuts	new_linescontent_lineoffsetsdivided_linesr  lastr   rK   s                              r5   r  Content._wrap_and_formatl  s   6 .0  ))H !!=>GA%||J/*0C/P!
s"9djj/C||OUC@##H-Dv%a)9)95 AB12FD %)KK$5!$5D 'y%P$5  !I
  ==Z9O=PD#1!5$L ".I-iuQVW%JJ1 48v;M !- 4 4 ; ;G D#z1 '0&>! '?
d   eh?![[]33EH3MN '?  !$ ,/}qm7m+L
 ,M #!**5155hI# ,M  
 *.	"&	*m ?p S!"!
s   H$/AH)9H/c                j   U(       d  / $ UR                   R                  nU R                  UU" SS5      U" SS5      U" SS5      S:H  U" SS	5      S
UR                  UR                  UR
                  UR                  S9
nUb  USU nU Vs/ s H  n[        UR                  U5      6 PM     nnU$ s  snf )a-  Render the Visual into an iterable of strips. Part of the Visual protocol.

Args:
    width: Width of desired render.
    height: Height of desired render or `None` for any height.
    style: The base style to render on top of.
    options: Additional render options.

Returns:
    An list of Strips.

text_alignr^   r   r   r   r   r   r   r   r+   )	r  r   r   r   r  r  r   r!  r   N)	r   r   r  r  r   r!  r   r   to_strip)	rA   r   r  r>   optionsr  r  r   strip_liness	            r5   render_stripsContent.render_strips  s     I==$$%%<0ov6[&1X=j!,''#33))'' & 
 '6NE@EFudmmE23F Gs   !B0c                ,    [        U R                  5      $ rr   )rj   r   r@   s    r5   __len__Content.__len__  s    4::r7   c                     U R                   S:g  $ )Nrb   rs   r@   s    r5   __bool__Content.__bool__  s    zzRr7   c                ,    [        U R                  5      $ rr   )hashr[   r@   s    r5   __hash__Content.__hash__  s    DJJr7   c              #  l   #     U R                   v   SU R                  / 4v   g ! [         a     g f = f7f)Nrl   )r[   r\   AttributeErrorr@   s    r5   rB   Content.__rich_repr__  s6     	**4;;** 		s   4$ 4
1414c                    U R                   $ )zA sequence of spans used to markup regions of the content.

!!! warning
    Never attempt to mutate the spans, as this would certainly break the output--possibly
    in quite subtle ways!

)r\   r@   s    r5   rl   Content.spans   s     {{r7   c                h    U R                   c  [        U R                  5      U l         U R                   $ )zThe cell length of the content.)r]   r   r   r@   s    r5   rm   Content.cell_length  s-     $ ( 4D   r7   c                    U R                   $ )z Get the text as a single string.rs   r@   s    r5   r   Content.plain  s     zzr7   c                h    U R                   (       a   [        U R                  / U R                  SS9$ U $ )zThe content with no spansFr   )r\   r#   r   r]   r@   s    r5   r   Content.without_spans  s,     ;;4::r4+<+<RWXXr7   c                b    SU R                   ;  a  U $ U SU R                   R                  S5       $ )zThe first line of the content.r   N)r   indexr@   s    r5   
first_lineContent.first_line  s2     tzz!K,djj&&t,--r7   c                L  ^  SU 4S jjn[        U[        5      (       a  U" U5      $ UR                  [        T R                  5      5      u  p4nUS:X  a  US:X  aQ  U[        T R                  5      :  a  T $ T R                  S U n[        UT R                  UT R                  5      SS9nU$ T R                  X4 nT R                   Vs/ s H*  nUR                  U-
  S:  d  M  UR                  U* 5      PM,     n	n[        UT R                  Xi5      SS9nU$ [        S5      es  snf )Nc                   > [         n[        TR                  U    TR                   VVVs/ s H"  u  p#nX0s=:  a  U:  d  M  O  M  U" SSU5      PM$     snnnSS9nU$ s  snnnf )Nr   rd   F)rl   rn   )r$   r#   r   r\   )rK   r   r;   r<   r>   r   rA   s         r5   get_text_at(Content.__getitem__.<locals>.get_text_at'  ss    E

6" .2[[-8)E,u, ', 'E!Q&-8
 %*G Ns   AAArd   r   Fr   z%slices with step!=1 are not supported)rK   r:   rP   z	'Content')r   r:   indicesrj   r   r#   _trim_spansr\   r<   rL   r   )
rA   slicerL  r;   stopstepr3   sliced_contentrw   rl   s
   `         r5   __getitem__Content.__getitem__&  s*   	 eS!!u%% %c$**o >EqyA:s4::.#::et,D%,((t{{;,1&N &%  ::e1D %)KK$/D88e+a/ ,UF+$/  
 &-d..t;QV&N &%
   GHHs   D!"D!c                   [        U[        5      (       a"  [        U R                  U-   U R                  SS9$ [        U[        5      (       a  [        U R                  5      n[        U R                  UR                  -   U R                  UR                   VVVs/ s H  u  p4n[        X2-   XB-   U5      PM     snnn-   U R                  b  S 5      nU$ U R                  UR                  -   5      nU$ [        $ s  snnnf )NFr   )r   r   r#   r[   r\   rj   r   r$   r]   rm   r   )rA   r   rK   r;   r<   r>   r   s          r5   __add__Content.__add__S  s    eS!!4::-t{{PUVVeW%%_F

U[[(KK 271=-E U^S\5A1= ((4 G N **U->->>G Ns   C8c                T    [        U[        5      (       d  [        $ [        U5      U -   $ rr   )r   r   r   r#   r   s     r5   __radd__Content.__radd__j  s$    %%%!!u~$$r7   c           
         [        U5      n[        nU Vs/ s HX  nUR                  U:  d  M  UR                  U:  a  UO0U" UR                  [	        X5R                  5      UR
                  5      PMZ     nnU$ s  snf )z=Remove or modify any spans that are over the end of the text.)rj   r$   r;   r<   minr>   )r   r3   rl   
max_offsetr   rw   s         r5   rO  Content._trim_spanso  s     Y
 
 zzJ&N88j( 4::s:xx'@$**MN  	 
 
s   A9AA9c                    [        U[        5      (       aL  [        U R                   U 3U R                  U R
                  c  SSS9$ U R
                  [        U5      -   SS9$ [        R                  X/5      $ )zAppend text or content to this content.

Note this is a little inefficient, if you have many strings to append, consider [`join`][textual.content.Content.join].

Args:
    content: A content instance, or a string.

Returns:
    New content.
NFr   )	r   r   r#   r   r\   r]   r   r   r   r   s     r5   r   Content.append  s     gs##::,wi( ((0  %*	 	 **Xg->>$)	 	 !!4/22r7   c                J    U R                  [        R                  X5      5      $ )zAppend text give as a string, with an optional style.

Args:
    text: Text to append.
    style: Optional style for new text.

Returns:
    New content.
)r   r#   r   )rA   r3   r>   s      r5   append_textContent.append_text  s     {{7>>$677r7   c                  ^ ^^	^
 / n/ nSUU 4S jjnUR                   nUR                   nSm
[        m	T R                  nU" 5        Hu  nU(       d  M  U" UR                  5        U" U	U
4S jUR                   5       5        T
[        UR                  5      -  m
Uc  MX  UR                  c  SOXxR                  -   nMw     [        SR                  U5      X75      $ )a@  Join an iterable of content or strings.

This works much like the join method on `str` objects.
Self is the separator (which maybe empty) placed between each string or Content.

Args:
    lines: An iterable of other Content instances or or strings.

Returns:
    A single Content instance, containing all of the lines.

c               3    >#    TR                   (       aE  [        T5       H5  u  p[        U[        5      (       a  UO	[        USS9v   U (       a  M1  Tv   M7     gT H&  n[        U[        5      (       a  UO	[        USS9v   M(     g7f)z6Iterate the lines, optionally inserting the separator.Fr   N)r   r   r   r#   )r(  r   r  rA   s     r5   iter_content"Content.join.<locals>.iter_content  s|     zz"+E"2JD &dG44 $TuE
  4"
 #3 "D &dG44 $TuE "s   A
B6Br   c              3  \   >#    U  H!  u  pnU(       d  M  T" TU-   TU-   U5      v   M#     g 7frr   rN   )r   r;   r<   r>   r   rK   s       r5   r   Content.join.<locals>.<genexpr>  s6      )7%E ;funfslE::)7s   ,,Nrb   )rP   zIterable[Content])rG   r$   r]   r[   r\   rj   r#   r   )rA   r  r3   rl   rg  extend_textextend_spanstotal_cell_lengthr   r   rK   s   ``       @@r5   r   Content.join  s     	 	& kk||(,(9(9#~G& )0 
 c'--((F , ++3 *-A-AA " &" rwwt}e??r7   )r  r   c               j    U R                  XU5      nU Vs/ s H  oUR                  PM     nnU$ s  snf )a  Wrap text so that it fits within the given dimensions.

Note that Textual will automatically wrap Content in widgets.
This method is only required if you need some additional processing to lines.

Args:
    width: Maximum width of the line (in cells).
    align: Alignment of lines.
    overflow: Overflow of lines (what happens when the text doesn't fit).

Returns:
    A list of Content objects, one per line.
)r  r   )rA   r   r  r   r  r   content_liness          r5   r   Content.wrap  s7      %%eH=278%$%8 9s   0c                   U (       d  U /$ U R                   n/ nSn[        US5      n X$XA-    nU(       d   U$ [        U5      nXa:  a  UR                  XXA-    5         U$ Xa:X  a%  UR                  XXA-    5        U[	        U5      -  nMc  Xa-
  nUS-  =n(       a"  U[        XX* S 5      -  nUS[	        U5      U-
   nXa:  a  U[        US   5      -  nUSS nXa:  a  M  UR                  XU[	        U5      -    5        U[	        U5      -  nM  )a  Fold this line into a list of lines which have a cell length no less than 2 and no greater than `width`.

Folded lines may be 1 less than the width if it contains double width characters (which may
not be subdivided).

Note that this method will not do any word wrapping. For that, see [wrap()][textual.content.Content.wrap].

Args:
    width: Desired maximum width (in cells)

Returns:
    List of content instances.
r   r   Nr&   )r   r   r   r   rj   )	rA   r   r3   r  r   snipsnip_cell_lengthextra_cells
start_snips	            r5   r   Content.fold  sG    6Mzz!E18#34D, +  (~'TX-=>?" !  (TX-=>?CI%*2K(A--z- HT+,-?$@@ 4c$i*45"* HT"X$66 CRy #* LLCI)=>?D	!H/ r7   c                    US:  a  [        U 5      U-   n[        5       nU R                   H  u  p4nXAs=:  a  U:  d  M  O  M  X%-  nM     U$ )zGet the style of a character at give offset.

Args:
    offset (int): Offset into text (negative indexing supported)

Returns:
    Style: A Style instance.
r   )rj   r   r\   )rA   rK   r>   r;   r<   
span_styles         r5   get_style_at_offsetContent.get_style_at_offset#  sP     A:Y'F&*kk"E
$u$$# '2 r7   )r  r  c                  U R                   nXA:X  a  U $ U R                  nU R                  nU(       a'  XA:  a"  X-
  nU R                   SU-   3n[        XVUSS9$ XA:  ag  U(       a$  U(       a  [	        U R                  US-
  5      S-   nO[	        U R                  U5      nU R                  XPR                  5      n[        XVUSS9$ U $ )zTruncate the content at a given cell width.

Args:
    max_width: The maximum width in cells.
    ellipsis: Insert an ellipsis when cropped.
    pad: Pad the content if less than `max_width`.

Returns:
    New Content.
r   Fr   rd   u   …)rm   r   r\   r#   r   rO  )rA   	max_widthr  r  lengthr3   rl   spacess           r5   r  Content.truncate6  s    $ !!Kzz6%'Fjj\#,0D4	uMMI$TZZQ?%G$TZZ;$$T;;7E4	uMMKr7   c           
     0   [        U5      S:X  d   S5       eU(       aq  X!-   U R                   3n[        nU R                   VVVs/ s H  u  pVnU" XQ-   Xa-   U5      PM     nnnn[	        UUU R
                  c  SOU R
                  U-   SS9n	U	$ U $ s  snnnf )zPad the left with a given character.

Args:
    count (int): Number of characters to pad.
    character (str, optional): Character to pad with. Defaults to " ".
rd   &Character must be a string of length 1NFr   rj   r   r$   r\   r#   r]   )
rA   count	characterr3   r   r;   r<   r>   rl   r   s
             r5   pad_leftContent.pad_left\  s     9~"L$LL"'(5DE *.)4%E emS[%8)4   ))1t7H7H57P$)	G Ns   Bc           	     &   U(       a  U R                   n[        U5      n[        U X!-   3U R                   Vs/ s H&  nUR                  U:X  a  UR                  U5      OUPM(     snU R                  c  SSS9$ U R                  U-   SS9$ U $ s  snf )zAdd repeating characters (typically spaces) to the content with the style(s) of the last character.

Args:
    count: Number of spaces.
    character: Character to add with.

Returns:
    A Content instance.
NFr   )r   rj   r#   r\   r<   rG   r]   )rA   r  r  r   	plain_lenrw   s         r5   extend_rightContent.extend_rightu  s     JJEE
I')+,- !% + ,088y+@T[['dJ + ))1$)  8<7H7H57P$)  s   -B
c                    [        U5      S:X  d   S5       eU(       aE  [        U R                   X!-   3U R                  U R                  c  SSS9$ U R                  U-   SS9$ U $ )zPad the right with a given character.

Args:
    count (int): Number of characters to pad.
    character (str, optional): Character to pad with. Defaults to " ".
rd   r  NFr   )rj   r#   r   r\   r]   )rA   r  r  s      r5   	pad_rightContent.pad_right  s|     9~"L$LL"::,y012))1$)	  8<7H7H57P$)	  r7   c           
     t   [        U5      S:X  d   S5       eU(       d  U(       a  X1-   U R                   X2-   3n[        nU(       a0  U R                   VVVs/ s H  u  pgnU" Xa-   Xq-   U5      PM     n	nnnOU R                  n	[	        UU	U R
                  c  SOU R
                  U-   U-   SS9n
U
$ U $ s  snnnf )a  Pad both the left and right edges with a given number of characters.

Args:
    left (int): Number of characters to pad on the left.
    right (int): Number of characters to pad on the right.
    character (str, optional): Character to pad with. Defaults to " ".
rd   r  NFr   r  )rA   r^   r_   r  r3   r   r;   r<   r>   rl   r   s              r5   r  Content.pad  s     9~"L$LL"5&'

|I4E3FGDE .2[[-8)E %,
E:-8  
 ))1t7H7H47ORW7W$)	G Ns   B3c                    U R                  5       R                  XS9nXR                  -
  S-  nX-
  nUR                  XE5      nU$ )zAlign a line to the center.

Args:
    width: Desired width of output.
    ellipsis: Insert ellipsis if content is truncated.

Returns:
    New line Content.
r  r   )r  r  rm   r  )rA   r   r  r   r^   r_   s         r5   centerContent.center  sJ     ++-(((B+++1++d*r7   c                z    U R                  5       R                  XS9nUR                  XR                  -
  5      nU$ )zAlign a line to the right.

Args:
    width: Desired width of output.
    ellipsis: Insert ellipsis if content is truncated.

Returns:
    New line Content.
r  )r  r  r  rm   )rA   r   r  r   s       r5   r_   Content.right  s;     ++-(((B""5+>+>#>?r7   c           
        [        U R                  5      U-
  n[        nU R                   Vs/ s HX  nUR                  U:  d  M  UR
                  U:  a  UO0U" UR                  [        X$R
                  5      UR                  5      PMZ     nnU R                  SU*  nU R                  c  SOU R                  U-
  n[        XeUSS9$ s  snf )zRemove a number of characters from the end of the text.

Args:
    amount: Number of characters to crop.

Returns:
    New Content

NFr   )
rj   r   r$   r\   r;   r<   r]  r>   r]   r#   )rA   amountr^  r   rw   rl   r3   r~  s           r5   
right_cropContent.right_crop  s     _v-
 
 $zzJ&N88j( 4::s:xx'@$**MN $ 	 
 zz(F7#**28I8IF8RtFFF
s   CACc           	         U(       d  U $ [        U 5      nUS:  a  XB-   nUc  UnUS:  a  XC-   nX$:  d  X2::  a  U $ [        U R                  U R                  [	        X$U:  a  UOUU5      /-   U R
                  SS9$ )aR  Apply a style to the text, or a portion of the text.

Args:
    style (Union[str, Style]): Style instance or style definition to apply.
    start (int): Start offset (negative indexing is supported). Defaults to 0.
    end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.
r   Fr   )rj   r#   r   r\   r$   r]   rA   r>   r;   r<   r~  s        r5   r  Content.stylize  s     KT19NE;C7,C?clKJJKK4#v3NOO %	
 	
r7   c                    U(       d  U $ [        U 5      nUS:  a  XB-   nUc  UnUS:  a  XC-   nX$:  d  X2::  a  U $ [        U R                  [        X$U:  a  UOUU5      /U R                  QU R
                  SS9$ )a  Apply a style to the text, or a portion of the text.

Styles applies with this method will be applied *before* other styles already present.

Args:
    style (Union[str, Style]): Style instance or style definition to apply.
    start (int): Start offset (negative indexing is supported). Defaults to 0.
    end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.
r   Fr   )rj   r#   r   r$   r\   r]   r  s        r5   r   Content.stylize_before  s     KT19NE;C7,C?clKJJ%C<S%@O4;;O %	
 	
r7   r   c           	   #  j  ^^^^^^^#    U R                   (       d  U R                  U4v   U(       a  X!4v   gTc  SS jnUnO0 mSUU4S jjnUn[        [        U R                   S5      5      nU VVs0 s HC  u  pxU[	        UR
                  [        5      (       a  U" UR
                  5      OUR
                  _ME     snnmUTS'   U R                  n	S/S U 5       QS U 5       Q[        U	5      S	S4Pn
U
R                  [        SS5      S
9  / mTR                  nTR                  n0 mTR                  m[        R                  mSUUUUU4S jjn[!        XSS 5       H:  u  u  pnu  n  nU(       a	  U" U5        OU" U5        UU:  d  M-  XU U" 5       4v   M<     U(       a  X!4v   ggs  snnf 7f)a  Render Content in to an iterable of strings and styles.

This is typically called by Textual when displaying Content, but may be used if you want to do more advanced
processing of the output.

Args:
    base_style: The style used as a base. This will typically be the style of the widget underneath the content.
    end: Text to end the output, such as a new line.
    parse_style: Method to parse a style. Use `App.parse_style` to apply CSS variables in styles.

Returns:
    An iterable of string and styles, which make up the content.

Nc                    [        U [        5      (       a  U $  [        R                  " U 5      nU$ ! [         a    [        R                  " 5       n U$ f = f)zThe default get_style method.)r   r   r   	Exceptionnull)r>   visual_styles     r5   
_get_style"Content.render.<locals>._get_styleO  sQ    eU++ L0#(;;u#5L $# ! 0#(::<L##0s   1 AAc                N   > TR                  U 5      =nb  U$ T" U 5      =TU '   nU$ rr   )r   )r>   cached_style_style_parse_style_cacheparse_styles      r5   r  r  ^  s9    $6$:$:5$AALN''5@5GG"5)Fr7   rd   r   )r   Fr   c              3  D   #    U  H  u  pUR                   S U4v   M     g7fr}   )r;   r   rG  rw   s      r5   r   !Content.render.<locals>.<genexpr>r  s     M<L[Utzz5%(<L    c              3  D   #    U  H  u  pUR                   S U4v   M     g7fr   )r<   r  s      r5   r   r  s  s     J9I+%txxu%9Ir  Tr   c                    > [        [        T5      5      n T" U 5      =nb  U$ U  Vs/ s H  nT	U   PM
     nnT" U5      =nTU '   U$ s  snf )z#Construct current style from stack.)r   sorted)
r  r  	_style_idstylescurrent_stylecombinestackstyle_cachestyle_cache_get	style_maps
        r5   get_current_style)Content.render.<locals>.get_current_style  s_    fUm,I /	 ::G##<EFIyi	*IFF5<V_DMK	2   Gs   A)r>   zstr | StylerP   r   )rP   r   )r\   r[   r  r  r   r>   r   r   rj   r   r   r   remover   r   r  r  )rA   
base_styler<   r  r  r   enumerated_spansrG  rw   r3   rl   stack_append	stack_popr  rK   leavingstyle_idnext_offset_r  r  r  r  r  r  s      `               @@@@@@r5   renderContent.render1  s    * {{::z**o% $ #I "$  #I	$++q 9:
  0	
  0 )3DJJ)D)D	$**%$**U  0	
	 "	!zz 
M<LM
 K9IJ
 Ya 	
 	

z!Q'
(||LL	46%//--	! 	! ADEQRQS9@U<'Vh)<+q!(#X&V#+.0A0CCC AV /! S
s   A+F34A
F->CF3%F3c                    [         nU R                  X5       VVs/ s H   u  pEU" XE(       a  UR                  OS5      PM"     nnnU$ s  snnf )zRender the Content in to a list of segments.

Args:
    base_style: Base style for render (style under the content). Defaults to Style.null().
    end: Character to end the segments with. Defaults to "".

Returns:
    A list of segments.
N)r   r  
rich_style)rA   r  r<   _Segmentr3   r>   segmentss          r5   render_segmentsContent.render_segments  sS       ${{:;
; TE,,4A; 	 
 	
s   'Ac                N    SSK Jn  U" U R                  [        5       S5      5      $ )z-Allow Content to be rendered with rich.print.r   )Segmentsr   )rich.segmentr  r  r   )rA   r  s     r5   __rich__Content.__rich__  s    ),,UWd;<<r7   c                ^   U R                   c  [        S5      U l         U R                   R                  U5      =nb  U$ [        [	        XSS 5      5      n[        U R                  5      n[        U5      n/ nU R                   H  nUu  pn
X:  a  M  [        XI5      n	SnUnX-   S-  n X=   u  pX:  a  US-
  nOX:  a  US-   nOO	X-   S-  nM&  X:  a  UnO.U=nnUn UU   u  pX:  a  US-
  nOX:  a  US-   nOO	X-   S-  nM'  UR                  X}US-   45        M     X`R                   U'   U$ )zDivide content from a list of offset to cut.

Args:
    offsets: A tuple of indices in to the text.

Returns:
    A list of tuples containing Spans and their line offsets.
N   rd   r   r   )
rh   r   r   r  r  rj   r   r\   r]  r   )rA   r&  cached_resultline_rangestext_length
line_countspan_rangesrw   
span_startspan_endr  lower_boundupper_boundstart_line_no
line_startr  end_line_nos                    r5   _divide_spansContent._divide_spans  s    %!*1D!//33G<<MI  3w45$**o%
35KKD+/(J&(;1HK$K(61<M'2'A$
*"/!"3K*"/!"3K!,!:q @  "+,99k(+6{+C(J,&1Ao!,&1Ao#.#<"BK  [1_EFG  H '27#r7   c           	        U(       d  U /$ [        U5      nU R                  n[        S/UQ[        U5      P5      n[	        [        X3SS 5      5      nU VVs/ s H	  u  pVX%U PM     nnnU Vs/ s H  n[        US5      PM     n	nU R                  (       d  U	$ U	 Vs/ s H  oR                  R                  PM     n
n[        nU R                  U5       Ha  u  u  pnnn[        UU5       HG  nUU   u  nn[        SUU-
  5      n[        UU-
  UU-
  5      nUU:  d  M4  U
U   " U" UUU5      5        MI     Mc     U	$ s  snnf s  snf s  snf )af  Divide the content at the given offsets.

This will cut the content in to pieces, and return those pieces. Note that the number of pieces
return will be one greater than the number of cuts.

Args:
    offsets: Sequence of offsets (in characters) of where to apply the cuts.

Returns:
    List of Content instances which combined would be equal to the whole.
r   rd   N)r  r   r   rj   r  r  r#   r\   r   r$   r  r  r   r]  )rA   r&  r3   divide_offsetsr  r;   r<   	line_textr   r$  _line_appendsr   r  r  r>   
start_lineend_lineline_nor  r  	new_startnew_ends                         r5   r  Content.divide  sW    6M/zz7G7SY783~ab/ABC7BC{T_{	C5>?YTWT4(Y	?{{8AB	++	B /	
)Z5 X6'27';$
H:
#:;	h3X
5JKY&!'*5GU+KL 7 0 + D?
 Cs   D<.EE)include_separatorr  c                 ^^
 T(       d   S5       eU R                   m
TT
;  a  U /$ TX#4nU R                  c  [        S5      U l        U R                  R                  U5      =nb  UR	                  5       $ U(       aY  U R                  [        R                  " [        R                  " T5      T
5       Vs/ s H  ofR                  5       PM     sn5      nOJSUU
4S jjnU R                  [        U" 5       5      5       V	s/ s H  n	U	R                   T:w  d  M  U	PM     nn	U(       d&  T
R                  T5      (       a  UR                  5         XpR                  U'   U$ s  snf s  sn	f )a  Split rich text into lines, preserving styles.

Args:
    separator (str, optional): String to split on. Defaults to "\\n".
    include_separator (bool, optional): Include the separator in the lines. Defaults to False.
    allow_blank (bool, optional): Return a blank line if the text ends with a separator. Defaults to False.

Returns:
    List[Content]: A list of Content, one per line of the original.
zseparator must not be emptyr  c               3     >#    [         R                  " [         R                  " T5      T5       H  n U R                  5        S h  vN   M     g  N	7frr   )refinditerr{   rw   )match	separatorr3   s    r5   flatten_spans$Content.split.<locals>.flatten_spans1  s7     [[9)=tDE$zz|++ E+s   AAA
A)rP   zIterable[int])r   ri   r   r   copyr  r  r  r{   r<   r  endswithpop)rA   r  r  r  r  r  r  r  r  r   r3   s    `        @r5   r   Content.split  s8   " 777yzzD 6M 1?	$ )!D!..229==MJ %%''KK*,++bii	6JD*QR*Q*QRE
, , !KK]_(=>>D::* >   t}}Y77IIK',)$% Ss   4E?E!E!c                    U R                   R                  U5      n[        X R                  X R                  5      5      $ )z"Strip characters from end of text.)r   r  r#   rO  r\   )rA   charsr3   s      r5   r  Content.rstripA  s0    zz  't--dKK@AAr7   c                    [        U 5      nX!:  aZ  X!-
  n[        R                  U R                  5      nUb4  [        UR	                  S5      5      nU R                  [        XS5      5      $ U $ )zvRemove whitespace beyond a certain width at the end of the text.

Args:
    size (int): The desired size of the text.
r   )rj   _re_whitespacesearchr   groupr  r]  )rA   sizer  excesswhitespace_matchwhitespace_counts         r5   r  Content.rstrip_endF  sg     $i 'F-44TZZ@+#&'7'='=a'@#A s+;'DEEr7   c                p   US::  a  U $ U R                   nSU-  nU(       ad  [        U 5      nU Vs/ s H&  nUR                  U:  a  UR                  U5      OUPM(     nn[	        U R
                  U-   X R                  U-   5      $ [	        U R
                  U-   U R                   U R                  5      $ s  snf )zExtend the Text given number of spaces where the spaces have the same style as the last character.

Args:
    spaces (int): Number of spaces to add to the Text.

Returns:
    New content with additional spaces at the end.
r   r   )r\   rj   r<   rG   r#   r[   rm   r]   )rA   r  rl   
new_spaces
end_offsetrw   s         r5   extend_styleContent.extend_styleU  s     Q;K6\
TJ "!D (,xx:'=F#4G!   4::
2E;K;Kf;TUUtzzJ.T=N=NOOs   -B3c                   SU R                   ;  a  U $ U R                  (       d$  [        U R                   R                  U5      5      $ / nUR                  nU R                  SSS9 H  nSUR                   ;  a
  U" U5        M  SnUR                  SSS9nU H  nUR                   R                  S5      (       ad  [        UR                  SS S-   UR                  UR                  5      nXWR                  -  nXQ-  nU(       a  X-
  n	UR                  U	5      nXY-  nOXWR                  -  nU" U5        M     M     [        R                  U5      n
U
$ )	z\Converts tabs to spaces.

Args:
    tab_size (int, optional): Size of tabs. Defaults to 8.

	r   Tr  r   Nr&   r   )r   r\   r#   
expandtabsr   r   r  r[   r]   rm   r  r   r   )rA   r  new_textr   r   cell_positionr   r   tab_remainderr  r   s              r5   r  Content.expand_tabsk  s6    tzz!K{{4::00:;;"$JJttJ<D4::%t !

44
@!Dzz**400& JJsOc14;;@Q@Q  &)9)99(5(@(%-%=F#'#4#4V#<D)3M%)9)994L " =*  $$X.r7   )maximum_highlightsc                  U R                   R                  5       nUR                  n[        nU R                  n[        U[        5      (       a  [        R                  " U5      nOUnSn	UR                  U5       H:  n
U
R                  5       u  pX:  a  U" U" XU5      5        Uc  M.  U	S-   =o:  d  M:    O   [        U R                  X@R                  S9$ )a  Apply a style to text that matches a regular expression.

Args:
    highlight_regex: Regular expression as a string, or compiled.
    style: Style to apply.
    maximum_highlights: Maximum number of matches to highlight, or `None` for no maximum.

Returns:
    new content.
r   rd   r   )r\   r  r   r$   r   r   r   r  compiler  rw   r#   r[   r]   )rA   highlight_regexr>   r  rl   append_spanr   r   re_highlightr  r  r;   r<   s                r5   r  Content.highlight_regex  s    " !KK,,.ll

os++::o6L*L!**51EJE{E%e45".#ai'U> 2 tzz56G6GHHr7   )	r]   rh   rg   rf   re   rk   r\   ri   r[   )rb   NNT)
r3   r   rl   zlist[Span] | Nonerm   
int | Nonern   boolrP   NonerP   r   )rP   r  )rP   r#   )T)r   r%   r   r  rP   r#   )r   zstr | Contentr   objectrP   r#   rr   )r3   z
str | Textr   zConsole | NonerP   r#   )rb   NT)
r3   r   r>   r=   rm   r  rn   r  rP   r#   )r   r:   r>   zStyle | str | NonerP   r#   )r   z'str | Content | tuple[str, str | Style]r<   r   rn   r  rP   r#   )rl   Sequence[Span]rP   r#   )r   r  rP   r  )r   r#   rP   r  )r   r    r   r:   rP   r:   )r   r    rP   r:   )r   r    r   r:   rP   r:   )r   r:   r  r   r   r   r   r  r   r:   r  r:   r  zSelection | Noner   Style | Noner!  r  r   Callable[[str | Style], Style]rP   zlist[_FormattedLine])
r   r:   r  r  r>   r   r-  r   rP   zlist[Strip])rP   r:   rO   )rP   r  )rP  zint | slicerP   r#   )r   Content | strrP   r#   )r   r   rP   r#   )r3   r   rl   
list[Span]rP   r"  )r   r!  rP   r#   )rb   )r3   r   r>   r=   rP   r#   )r  zIterable[Content | str]rP   r#   )r   r:   r  r   r   r   rP   list[Content])r   r:   rP   r#  )rK   r:   rP   r   )r}  r:   r  r  rP   r#   )r   )r  r:   r  r   rP   r#   )r^   r:   r_   r:   r  r   rP   r#   )F)r   r:   r  r  rP   r#   )rd   )r  r:   rP   r#   )r   N)r>   r=   r;   r:   r<   r  rP   r#   )r  r   r<   r   r  z%Callable[[str | Style], Style] | NonerP   zIterable[tuple[str, Style]])r  r   r<   r   rP   list[Segment])r&  ztuple[int, ...]rP   zlist[tuple[Span, int, int]])r&  zSequence[int]rP   r#  )r   )r  r   r  r  r  r  rP   r#  )r  z
str | NonerP   r#   )r   r:   rP   r#   )r  r:   rP   r#   )r+   )r  r:   rP   r#   )r  zre.Pattern[str] | strr>   r=   r  r  rP   r#   )KrR   rS   rT   rU   rV   	__slots___NORMALIZE_TEXT_ALIGNro   rt   propertyrx   r   r   classmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r  r/  r2  r5  r9  rB   rl   rm   r   r   rH  rT  rW  rZ  rO  r   rc  r   r   r   rz  r  r  r  r  r  r  r_   r  r  r   r  r  r  r  r  r  r   r  r  r  r  r  rX   rN   r7   r5   r#   r#      sR    4I&,WP #'"&$( 1 1 ! 1  	 1
 " 1 
 1D    >   AE %0 :> 	   D  B 9=<<(6<	< <|   "&$(   	
 " 
 8  &  $(	;!7;! ;! "	;!
 
;! ;!z<$+&4,48 "!'&*(,#'49KK\\ \ 	\
 \ \ \ $\ &\ !\ 2\ 
\|$$",$5:$ER$	$L     ! !     . .+IZ.%
  30
8;@| 17QW$-BN	(-^. $$
 $ 
$L20": G4 EI
 
),
7A
	
@ 	 
 
  
 	 

 
 
H "JJL=A	`"`" `" ;	`"
 
%`"F #(**,258	&=7r(X 0 #(!00  	0
 0 
0dB
P,&Z *.#I.#I 	#I
 '#I 
#I #Ir7   c                      \ rS rSrSr     S	                 S
S jjr\SS j5       rSS jr      SS jr	Sr
g)r  i  zA line of content with additional formatting information.

This class is used internally within Content, and you are unlikely to need it an an app.
Nc	                d    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        g rr   )r   r   r   xr
  r  r  
link_style)	rA   r   r   r   r+  r
  r  r  r,  s	            r5   ro   _FormattedLine.__init__  s,     #

 $r7   c                .    U R                   R                  $ rr   )r   r   r@   s    r5   r   _FormattedLine.plain  s    ||!!!r7   c                   [         nU R                  nU R                  nS=pVU R                  nU R                  nU R
                  n	U R                  n
US;   d  US:X  a  U R                  (       a  GOUS:X  a#  X@R                  R                  -
  nUS-  nX-
  nGOhUS;   a  X@R                  R                  -
  nGOHUS:X  GaA  UR                  SSS	9n[        S
 U 5       5      n[        U5      S-
  nS/U-  nSnU(       aD  X-   U:  a<  U[        U5      U-
  S-
  ==   S-  ss'   US-  nUS-   [        U5      -  nX-   U:  a  M<  / nUR                  nU R                  n[        U5       H  u  nnUR                  USU
S9 H8  u  nnU" U" UUU-   R                  X5      5      5        U[        U5      S-   -  nM:     U[        U5      :  d  Md  UU   =n(       d  Mr  U" U" SU-  UW-   R                   5      5        M     UU4$ U(       a$  [        SU-  UR"                  R                   5      /O/ nUR                  nUR                  USU
S9 H5  u  nnU" U" UUU-   R                  X5      5      5        U[        U5      -  nM7     U(       a/  UR                  U" SU-  UR"                  R                   5      5        UUR                  U-   U-   4$ )Nr   )r;   r^   ra   r  r   )r<   r_   r   Fr  c              3  j   #    U  H)  n[        UR                  R                  S 5      5      v   M+     g7f)r   N)r   r   r  )r   r   s     r5   r   *_FormattedLine.to_strip.<locals>.<genexpr>  s'     P%$Xdjj&7&7&<==%s   13rd   rb   )r<   r  )r   r  r   r   r+  r
  r   r  rm   r   sumrj   r   r  r  rich_style_with_offsetr  background_style)rA   r>   r  r  r   r  r  r   r+  r
  r   excess_spacewords
words_size
num_spacesr  rG  r  add_segmentr   r3   
text_styler  s                          r5   r,  _FormattedLine.to_strip  s   



  ,,FFFFNN	%%%9*<h <<#;#;;L#q(H$/I&&||777HiMM#M?EP%PPJUaJS:%FE -53v;.23q83!OJ"QY#f+5E !-5
 ')H"//KA(/t(,ry )4 )$D*    5:#5"M"Ma"S
 TQ&A) 3v;&6%=,@C,@sUZ5G4S4S TU  0 U?"  S8^U%;%;%F%FGH 	
 oo 'u") TD*
 2JJ1PQ TNA	 !U OOy%*@*@*K*KL '--89DEEr7   c           
         [         nU VVVs/ s H8  u  pEnUc  M  U" UUR                  c  UOSUR                  ;   a  XQ-   OUU5      PM:     nnnnU$ s  snnnf )Nz@click)r   _metameta)rA   r,  r  r  r3   r>   controls          r5   _apply_link_style _FormattedLine._apply_link_style  st      )1
 )1$WH {{* 08EJJ0F%,E )1 	 
 
s
   
A1A)r  r   r   r  r,  r   r+  r
  )r   r   r^   FN)r   r   r   r#   r   r:   r+  r:   r
  r:   r  r   r  r  r,  r  rP   r  r  )r>   r   rP   ztuple[list[Segment], int])r,  r   r  r$  rP   r$  )rR   rS   rT   rU   rV   ro   r'  r   r,  rA  rX   rN   r7   r5   r  r    s     !#'%1% % 	%
 % % % % !% 
%( " "EFN#/<	r7   r  rb   r   )r3   r   r4   zdict[int, None]rP   r   )KrV   
__future__r   r  	functoolsr   r   operatorr   typingr   r   r	   r
   r   	rich.reprrich
rich._wrapr   
rich.cellsr   rich.consoler   r  r   
rich.styler   r   rich.terminal_themer   	rich.textr   typing_extensionsr   r   textual._cellsr   textual._contextr   textual._loopr   textual.cacher   textual.colorr   textual.css.typesr   r   textual.selectionr   textual.stripr   textual.styletextual.visualr   r    r!   __all__r   r"   rW   r%   ANSI_DEFAULTTRANSPARENT_STYLEr  r  r/   r0   r6   reprautor$   r#   r  r   )
_codepoints   0r5   <module>r`     s   # 	 5  B B  " $     ) -  . # ' # #  5 '   : :
,y#~.Y . Py$34Y 4 0Q1ab)Q1ab) :G  G$ e  (<#';';# %  4L,
,!0,, -A: -A -A` qIf qI  qIh1v vr r{u "g7#s    F