
    Cjb                        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  \R                  " S5      rSS	 jr  S           SS
 jjrg)    )annotationsN)Iterable)get_character_cell_size)cell_len)	loop_last)get_tab_widthsz
\S+\s*|\s+c              #     #    Sn[         R                  X5      =nbD  UR                  5       u  p1UR                  S5      nX1U4v   [         R                  X5      =nb  MC  gg7f)a,  Yields each "chunk" from the text as a tuple containing (start_index, end_index, chunk_content).
A "chunk" in this context refers to a word and any whitespace around it.

Args:
    text: The text to split into chunks.

Returns:
    Yields tuples containing the start, end and content for each chunk.
r   N)re_chunkmatchspangroup)textendchunk_matchstartchunks        _/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/_wrap.pychunksr      sa      C"..33;
@ %%'
!!!$% #..33;
@s   AA" A"c                z   [        X!5      nU(       a  UnO[        X5      n/ nUR                  nSn[        n	Sn
Sn/ nUR                  n[        U5       HV  u  nu  nn[        U5      [        [        U5      5      -   nU/U-  nU" U5        UU-  nU(       d  ME  UR                  U5        MX     [        U 5       GHx  u  nnnU	" U5      nUU   nUU   nUU-
  nUU-  nX-
  nUU:  nU(       a  UU-  nM;  UU:  Ga  U(       a  [        n/ /nUR                  nUS   R                  nSn U HP  n!U!S:X  a  XZ   S   n"U
S-  n
OU" U!5      n"U U"-   U:  a  U" U!/5        US   R                  nU"n MC  U" U!5        U U"-  n MR     U V#s/ s H  n#SR                  U#5      PM     n$n#[        U$5       HN  u  nn#U(       a  U" U5        U(       a$  UU[        U#5      -      UU   -
  n%U	" U#5      U%-   nM@  U[        U#5      -  nMP     GMF  U(       a  U" U5        UnGMZ  U(       d  GMd  U(       d  GMn  U" U5        UnGM{     U$ s  sn#f )a3  Given a string of text, and a width (measured in cells), return a list
of codepoint indices which the string should be split at in order for it to fit
within the given width.

Args:
    text: The text to examine.
    width: The available cell width.
    tab_size: The tab stop width.
    fold: If True, words longer than `width` will be folded onto a new line.
    precomputed_tab_sections: The output of `get_tab_widths` can be passed here directly,
        to prevent us from having to recompute the value.

Returns:
    A list of indices to break the line at.
r   	    )minr   appendr   extendr   lenintboolr   r   join)&r   widthtab_sizefoldprecomputed_tab_sectionstab_sectionsbreak_positionsr   cell_offset	_cell_lentab_section_indexcumulative_widthcumulative_widthsrecord_widthslasttab_section	tab_widthsection_codepoint_lengthwidthsr   r   r   chunk_widthtab_width_before_starttab_width_before_endchunk_tab_widthremaining_space
chunk_fits_get_character_cell_sizelinesappend_new_lineappend_to_last_linetotal_width	character
cell_widthlinefolded_wordline_tab_widthss&                                         r   compute_wrap_offsetsrB       s   , 8#H/%d5!#O##FKI#%%,,M*3L*A&&{I#&{#3c$y/6J#J "#&>>fI%4$$%56 +B $D\sE&!25!905.1GG&-$3
;&K U"/F,.0TE&+llO*/)*:*:'"#K%*	$,)5)H)KJ-2-)A))LJ&3e;+YK827)2B2B/*4K/	:':5K &+  >C"CUT2774=UK"C&/&<
d "5M !2%#d)2C D"3E":!; , +4D/O*KK!SY.E '=$ u"-K u)E *H 9 #Ds   H8)r   strreturnzIterable[tuple[int, int, str]])TN)r   rC   r!   r   r"   r   r#   r   r$   zlist[tuple[str, int]] | NonerD   z	list[int])
__future__r   retypingr   
rich.cellsr   textual._cellsr   textual._loopr   textual.expand_tabsr   compiler
   r   rB        r   <module>rO      sy    " 	  . # # .::m$ * =As
ss s 	s
 ;s srN   