
    ij*                      x   d Z ddlZddlZddlmZ  ej
                  d      Z ej
                  d      ZdZ ej
                  edz   ej                  z         Z
d	d
defdZ ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  d      Z ej
                  ej                  j%                  ddd      dz   ej                  j%                  ddd      z   dz   ej                  j%                  ddd      z   dz   ej                  j%                  ddd      z   dz   ez   dz   dz   ej                  z   dz         Z ej
                  dj)                  d dD                    Zdedej,                  ej.                  eef      fdZdedefdZy)aA  
Terminal escape sequence patterns.

This module provides regex patterns for matching terminal escape sequences. All patterns match
sequences that begin with ESC (``\x1b``). Before calling re.match with these patterns, callers
should first check that the character at the current position is ESC for optimal performance.
    N   )_SGR_PATTERNz9\x1b\]66;([^;\x07\x1b]*)(?:;([^\x07\x1b]*))?(\x07|\x1b\\)a
  \x1b\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\x1b_[^\x1b\x07]*(?:\x07|\x1b\\)|\x1bP[^\x1b\x07]*(?:\x07|\x1b\\)|\x1b\^[^\x1b\x07]*(?:\x07|\x1b\\)|\x1b[()](?s:.)|\x1b[\x20-\x2f]+[\x30-\x7e]|\x1b[\x40-\x5f]|\x1b[\x30-\x3f]|\x1b[\x60-\x7e]zZ\x1b\]66;(?P<ts_meta>[^;\x07\x1b]*)(?:;(?P<ts_text>[^\x07\x1b]*))?(?P<ts_term>\x07|\x1b\\)|matchzre.Match[str]returnc                 ,    | j                  d      xs dS )zBKeep the inner text of an OSC 66 match, drop every other sequence.ts_text )group)r   s    a/home/ubuntu/.cache/pipx/cdb5059130eadca/lib/python3.12/site-packages/wcwidth/escape_sequences.py_strip_replr   9   s    ;;y!'R'    z\x1b\[(\d*)Cz\x1b\[(\d*)Dz\x1b\[(\d*)Gz\x1b\[(\d*)[CDG]z[\x08\r]|\x1b\[(\d*)[CDG](z(?P<sgr_params>z
(?P<hpa_n>z(?P<cforward_n>z(?P<cbackward_n>z(?P<other_seq>(?:z))c              #   (   K   | ]
  }d | d  yw)z(?:)N ).0_patterns     r   	<genexpr>r   e   s      8s8*A s   )z\x1b\[\d+;\d+rz
\x1b\[\d*Kz
\x1b\[\d*Jz\x1b\[\d+;\d+Hz
\x1b\[\d*Hz
\x1b\[\d*Az
\x1b\[\d*Bz
\x1b\[\d*Pz
\x1b\[\d*Mz
\x1b\[\d*Lz
\x1b\[\d*@z
\x1b\[\d+Xz
\x1b\[\d*Sz
\x1b\[\d*Tz
\x1b\[\d*dz\x1b\[\?1049[hl]z\x1b\[\?47[hl]z\x1b8z\x1bDz\x1bMz\x1bctextc              #   .  K   d}t        |       }d}||k  rn| |   }|dk(  rY||kD  r	| || df t        j                  | |      }|r%|j                         df |j	                         }n|df |dz  }|}n|dz  }||k  rn||k  r
| |d df yyw)a  
    Iterate through text, yielding segments with sequence identification.

    This generator yields tuples of ``(segment, is_sequence)`` for each part
    of the input text, where ``is_sequence`` is ``True`` if the segment is
    a recognized terminal escape sequence.

    :param text: String to iterate through.
    :returns: Iterator of (segment, is_sequence) tuples.

    .. versionadded:: 0.3.0

    Example::

        >>> list(iter_sequences('hello'))
        [('hello', False)]
        >>> list(iter_sequences('\x1b[31mred'))
        [('\x1b[31m', True), ('red', False)]
        >>> list(iter_sequences('\x1b[1m\x1b[31m'))
        [('\x1b[1m', True), ('\x1b[31m', True)]
    r   FTr   N)lenZERO_WIDTH_PATTERNr   r   end)r   idxtext_lensegment_startcharr   s         r   iter_sequencesr       s     , C4yHM
.Cy6>]"M#.66 ',,T37E{{}d++iik Tl"qM1HC' ., xMN#U++  s   BBBc                 j    d| v rt         j                  t        |       S t        j                  d|       S )a  
    Return text with all terminal escape sequences removed.

    Unknown or incomplete ESC sequences are preserved.

    :param text: String that may contain terminal escape sequences.
    :returns: The input text with all escape sequences stripped.

    .. versionadded:: 0.3.0

    .. versionchanged:: 0.7.0
       Inner text of OSC 66 (Text sizing protocol) is preserved.

    Example::

        >>> strip_sequences('\x1b[31mred\x1b[0m')
        'red'
        >>> strip_sequences('hello')
        'hello'
        >>> strip_sequences('\x1b[1m\x1b[31mbold red\x1b[0m text')
        'bold red text'
        >>> strip_sequences('\x1b]66;s=2;hello\x07')
        'hello'
        >>> strip_sequences('\x1b]8;id=34;https://example.com\x1b\\[view]\x1b]8;;\x1b\\')
        '[view]'
    z]66;r
   )_STRIP_WITH_TEXT_SIZINGsubr   r   )r   s    r   strip_sequencesr$      s2    6 T&**;==!!"d++r   )__doc__retyping	sgr_stater   compileTEXT_SIZING_PATTERNr   _TEXT_SIZING_NAMEDpatternr"   strr   CURSOR_RIGHT_SEQUENCECURSOR_LEFT_SEQUENCECURSOR_HPA_SEQUENCECURSOR_MOVEMENT_SEQUENCE_HORIZONTAL_CURSOR_MOVEMENTreplace_SEQUENCE_CLASSIFYjoinINDETERMINATE_EFFECT_SEQUENCEIteratorTupleboolr    r$   r   r   r   <module>r:      s;   
  $ !bjj@   RZZ 4Q  %"**%7#%=@R@Z@Z%Z[ ( (3 ( #

?3  "rzz/2  !bjj1 
 &2::&9: 
 )bjj)EF 
  RZZ  &7;	
''//\1EF	
!))11#7H!LM 

 !((006H!LM 
	
 	
 


 !!
 $6#=#=>
 AEE   !+

HH  0  ! 61, 1,c4i1H!I 1,h,# ,# ,r   