
    _j9                        S 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
JrJrJr  SSKJr  SS	KJrJr  SS
KJrJrJrJr  SSKJr  SSKJrJrJrJrJr  Sr \!RE                  SSSRG                  S \$" SS5       5       5      S-   SRG                  S \$" SS5       5       5      -   5      r%S!S\!S\&S\&4S jjr'SSSS.S\!S\S   S\&S\&S\&4
S jjr(g )"z8This is a high-level width() supporting terminal output.    )Literal   wcwidth)bisearch)wcswidth)_EMOJI_ZWJ_SET_ISC_VIRAMA_SET_CATEGORY_MC_TABLE_FITZPATRICK_RANGE_REGIONAL_INDICATOR_SET)VS16_NARROW_TO_WIDE)
TextSizingTextSizingParams)ILLEGAL_CTRLVERTICAL_CTRLHORIZONTAL_CTRLZERO_WIDTH_CTRL)ISC_CONSONANT)_SEQUENCE_CLASSIFYTEXT_SIZING_PATTERNCURSOR_MOVEMENT_SEQUENCEINDETERMINATE_EFFECT_SEQUENCEstrip_sequences    c              #   8   #    U  H  n[        U5      v   M     g 7fNchr.0cs     C/home/rurouni/.local/lib/python3.13/site-packages/wcwidth/_width.py	<genexpr>r%            .-qCFF-       c              #   8   #    U  H  n[        U5      v   M     g 7fr   r   r!   s     r$   r%   r%   "   r&   r'         textambiguous_widthreturnc                 N    [        [        U 5      R                  [        5      US9$ )z
Fast path for width() with control_codes='ignore'.

Strips escape sequences and control characters, then measures remaining text.
)r.   )r   r   	translate_CONTROL_CHAR_TABLE)r-   r.   s     r$   _width_ignored_codesr3   &   s(     ''(;<'     parse   )control_codestabsizer.   r7   )r5   strictignorer8   c          	        ^ U R                  5       (       a   U R                  5       (       a  [        U 5      $ US:X  ac  [        U 5      [        :  aP  SU ;  aJ  SU ;  aD  SU ;  a>  SU ;  d6  [        R
                  " U 5      (       d  [        R
                  " U 5      (       d  SnUS:X  a  [        U T5      $ US:H  nSnSnSn[        U 5      nTS	:X  a  [        OU4S
 jn	Sn
SnSnSnXx:  Ga  X   nUS:X  Ga  [        R                  " X5      nU(       d  US	-  nGOUR                  5       nU(       a-  [        R                  " U5      (       a  [        SU SU< 35      eUR                  S5      =nb4  U(       a  [        U5      OS	nU(       a  [        SU SU< S35      eUS	-
  nOUR                  S5      =nb  UU(       a  [        U5      OS	-  nOUR                  S5      =nbF  U(       a  [        U5      OS	nU(       a  UU:  a  [        SU SU SU S35      e[        SUU-
  5      nOrUR                  S5      =nb^  UR                  S5      nUR                  S5      nUb  Uc   e[!        ["        R$                  " UUS9UU5      nUUR'                  T5      -  nUR)                  5       nSn
Sn[        Xe5      nGM  U[*        ;   a.  U(       a  [        S[-        U5      S SU 35      eUS	-  nSn
SnGM  U[.        ;   a.  U(       a  [        S [-        U5      S SU 35      eUS	-  nSn
SnGMK  U[0        ;   a]  US:X  a  US:  a
  XRXR-  -
  -  nO0US:X  a  US:  a  US	-  nOUS:X  a  U(       a  [        S!U S"35      eSn[        Xe5      nUS	-  nSn
SnGM  U[2        ;   a  US	-  nSn
SnGM  [-        U5      nUS#:X  a(  U(       a  US	-  nOUS	-   U:  a  SnUS$-  nOSnUS	-  nGM  US%:X  aC  U
S:  a=  [5        [-        X
   5      [6        S&   5      (       a  US	-  n[        Xe5      nSn
US	-  nGMJ  US':  a  U[8        ;   a_  SnUS	-
  nUS:  a>  [-        U U   5      [8        ;   a(  US	-  nUS	-  nUS:  a  [-        U U   5      [8        ;   a  M(  US$-  S	:X  a
  UnUS	-  nGM  O0[:        S   Us=::  a  [:        S	   ::  a  O  OU[<        ;   a  US	-  nGM  U(       a%  [5        U[>        5      (       a  Un
UnSnS(nUS	-  nGM  U	" U5      nUS:  a%  U(       a  US	-  nSnUU-  n[        Xe5      nUn
UnSnO;U
S:  a,  [5        U[@        5      (       a  US	-  n[        Xe5      nSn
SnSnO	U[B        ;   nUS	-  nXx:  a  GM  U(       a  US	-  n[        Xe5      nU$ ))u  
Return printable width of text containing many kinds of control codes and sequences.

Unlike :func:`wcswidth`, this function handles most control characters and many popular terminal
output sequences.  Never returns -1.

:param text: String to measure.
:param control_codes: How to handle control characters and sequences:

    - ``'parse'`` (default): Track horizontal cursor movement like BS ``\b``, CR ``\r``, TAB
      ``\t``, cursor left and right movement sequences.  Vertical movement (LF, VT, FF) and
      indeterminate terminal sequences are zero-width. OSC 66 Kitty Text Sizing protocol, OSC 8
      Hyperlink, and many other kinds of output sequences are parsed for displayed measurements.
    - ``'strict'``: Like parse, but raises :exc:`ValueError` on control characters with
      indeterminate results of the screen or cursor, like clear or vertical movement. Generally,
      these should be handled with a virtual terminal emulator (like 'pyte').
    - ``'ignore'``: All C0 and C1 control characters and escape sequences are measured as
      width 0. This is the fastest measurement for text already filtered or known not to contain
      any kinds of control codes or sequences. TAB ``\t`` is zero-width; to ensure
      tab expansion, pre-process text using :func:`str.expandtabs`.

:param tabsize: Tab stop width for ``'parse'`` and ``'strict'`` modes. Default is 8.
    Must be positive. Has no effect when ``control_codes='ignore'``.
:param ambiguous_width: Width to use for East Asian Ambiguous (A)
    characters. Default is ``1`` (narrow). Set to ``2`` for CJK contexts.
:returns: Maximum cursor position reached, "extent", accounting for cursor movement sequences
    present in ``text`` according to given parameters.  This represents the rightmost column the
    cursor reaches.  Always a non-negative integer.

:raises ValueError: If ``control_codes='strict'`` and control characters with indeterminate
    effects, such as vertical movement or clear sequences are encountered, or on unexpected
    C0 or C1 control code. Also raised when ``control_codes`` is not one of the valid values.

.. versionadded:: 0.3.0

.. versionchanged:: 0.7.0
   Expanded strict-mode to raise :exc:`ValueError` when cursor-left movement
   (CSI D) would move beyond the beginning of the string. Previously, cursor-left
   was silently clamped to column 0 in all modes.

   Support horizontal cursor sequences (``cub``, ``cuf``, ``hpa``). Cursor-left (``cub``) or
   backspace (``\b``) now overwrites text.  ``column_address`` (``hpa``) and carriage return
   (``\r``) are now parsed, and some values conditionally raise ``ValueError`` when
   ``control_codes='parse'``.

Examples::

    >>> width('hello')
    5
    >>> width('コンニチハ')
    10
    >>> width('\x1b[31mred\x1b[0m')
    3
    >>> width('\x1b[31mred\x1b[0m', control_codes='ignore')  # same result (ignored)
    3
    >>> width('123\b4')     # backspace overwrites previous cell (outputs '124')
    3
    >>> width('abc\t')      # tab caused cursor to move to column 8
    8
    >>> width('1\x1b[10C')  # '1' + cursor right 10, cursor ends on column 11
    11
    >>> width('1\x1b[10C', control_codes='ignore')   # faster but wrong in this case
    1
r5   	r:   r9   r   r   c                    > [        U ST5      $ )Nautor   )r#   r.   s    r$   <lambda>width.<locals>.<lambda>   s    gaQ`>ar4   Fz*Indeterminate cursor sequence at position z, hpa_nz.Indeterminate horizontal position at position z (absolute column unknown)
cforward_ncbackward_nz!Cursor left movement at position z would move z cells left from column z, exceeding string startts_metats_textts_term)r7   zIllegal control character z#xz at position zVertical movement character z-Horizontal movement character \r at position z: indeterminate starting columni      i  z9.0.0i  T)"isasciiisprintablelen_WIDTH_FAST_PATH_MIN_LENr   searchr   r3   r   r   matchgroupr   
ValueErrorintmaxr   r   from_paramsdisplay_widthendr   ordr   r   r   r   r   r   r   r	   r   r   r
   )r-   r7   r8   r.   r9   current_col
max_extentidxtext_len_wcwidthlast_measured_idxlast_measured_ucslast_was_viramaconjunct_pendingcharmseqrF   
target_colrG   rH   
n_backwardrI   rJ   rK   	text_sizeucs	ri_beforejws      `                          r$   widthrn   2   s_   Z ||~~$**,,4y CI0H$HtD 0T5E T!,33D99+22488 (  #D/::h&F KJ
C4yH
 *Q.w4aH O
.y 6>"((3Aqggi;AA#FF$'QRUQVVXY\X_%`aa WWW--E:/4U!J(LSEQS"g%?A  #-q.K$%GGL$99jFj3z?aGK%&WW]%;;kH5@[!1aJ*{":(?uL)l*B;- P56 
 #&az)A"BK!"!33g@ggi0Gggi0G".73FFF *(44WMZ!*I  9#:#:?#KKKeeg " "Z5J < #=c$i^=Y\X]!^__1HC " "=  #?D	"~][^Z_!`aa1HC " " ?"t|!+*?@@?1$K$H N8 8   Z5J1HC " " ?"1HC " " $i &=qq8#"'q"'q &=.!3D346I'6RSSq  9
 "1HC <--	!G1fT!W1H!HNIFA 1fT!W1H!H q=A%(+%1HC & %Q'3G2DQ2GG'>9q x];; # ##O#1HC TNq5q #( 1KZ5J # ##O!#6H(I(I1KZ5J "#O$!_4OqQ .T q1
r4   N)r   ))__doc__typingr   r_   r   r   	_wcswidthr   
_constantsr	   r
   r   r   r   
table_vs16r   text_sizingr   r   r7   r   r   r   r   table_graphemer   escape_sequencesr   r   r   r   r   rP   str	maketransjoinranger2   rU   r3   rn    r4   r$   <module>r|      s    >    2 2
 , 5 X X )0 0   mmBGG.E$-..
GG.E$-../ 	s 	S 	 	 ;Ba
a 67a 	a
 a 	ar4   