
    AHj                       d dl mZ d dlZd dlmZ d dlmZ  ej                  d      ZdddZ	dddZ
ddZed	k(  r e e
d
              e e
d              e e
d              e e
d              e e
d              e e
d              e e
d              e e
d              e e
d              e e
d              e e
d             yy)    )annotationsN)cell_len)Textz(.*?\t|.+?$)c                    g }|j                   }d}t        j                  |       }|D ]A  }d}|j                  d      r"|dd }|t	        |      z  }||z  }||z
  }||z  } |||f       C |S )a!  Splits a string line into tuples (str, int).

    Each tuple represents a section of the line which precedes a tab character.
    The string is the string text that appears before the tab character (excluding the tab).
    The integer is the width that the tab character is expanded to.

    Args:
        line: The text to expand tabs in.
        tab_size: Number of cells in a tab.

    Returns:
        A list of tuples representing the line split on tab characters,
            and the widths of the tabs after tab expansion is applied.
    r   	N)append_TABS_SPLITTER_REfindallendswithr   )	linetab_sizepartsadd_partcell_positionmatchesmatchexpansion_widthtab_remainders	            K/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/expand_tabs.pyget_tab_widthsr      s      $&E||HM''-G +>>$#2JEXe_,M *H4M&6O_,M%)*+ L    c           	     z    t        | |      }dj                  |D cg c]  \  }}||dz  z    c}}      S c c}}w )zExpands tabs, taking into account double cell characters.

    Args:
        line: The text to expand tabs in.
        tab_size: Number of cells in a tab.
    Returns:
        New string with tabs replaced with spaces.
      )r   join)r   r   
tab_widthspartr   s        r   expand_tabs_inliner   1   sA      h/J77CMN*?$#%	%N Ns   7
c                   d| j                   vr| S | j                  dd      }t        |      }g }|j                  }|D ]f  }|j                   j	                  d      rA|j
                  d   dd dz   |j
                  d<   t        |      }|j                  |dz
          ||       h t        dd	      j                  |      S )
a9  Expand tabs to the widths defined in the `tab_widths` list.

    This will return a new Text instance with tab characters expanded into a
    number of spaces. Each time a tab is encountered, it's expanded into the
    next integer encountered in the `tab_widths` list. Consequently, the length
    of `tab_widths` should match the number of tab characters in `line`.

    Args:
        line: The `Text` instance to expand tabs in.
        tab_widths: The widths to expand tabs to.

    Returns:
        A new text instance with tab characters converted to spaces.
    r   T)include_separatorr   Nr      r   )end)
plainsplititerr	   r   _textnextextend_styler   r   )r   r   r   tab_widths_iter	new_partsappend_partr   spacess           r   expand_text_tabs_from_widthsr.   @   s     4::JJttJ4E:&OI""K ::t$!ZZ^CR036DJJrN/*Ffqj)D   ++r   __main__z	barz	bar	z1	barz12	barz123	barz1234	baru   💩	baru   💩💩	baru   💩💩💩	baru	   F💩	baru
   F💩O	bar)   )r   strr   intreturnzlist[tuple[str, int]])r   r1   r   r2   r3   r1   )r   r   r   z	list[int]r3   r   )
__future__r   re
rich.cellsr   	rich.textr   compiler
   r   r   r.   __name__print r   r   <module>r<      s    " 	  BJJ/ #L,B z	
W
%&	
Y
'(	
X
&'	
Y
'(	
Z
()	
[
)*	
[
)*	
_
-.	
0
12	
\
*+	
]
+, r   