o
    j                     @   s$  d Z ddlZddlZddlmZ edZedZedZedZ	ed	Z
ed
ZedZeejdddd e
jddd d ejddd d e	jddd d d d d ej d Zeddd dD Zdedejejeef  fddZdedefddZdS )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_PATTERNz4\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[()].|\x1b[\x20-\x2f]+[\x30-\x7e]|\x1b[\x40-\x5f]|\x1b[\x30-\x3f]|\x1b[\x60-\x7e]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>zU\x1b\]66;(?P<ts_meta>[^;\x07\x1b]*);(?P<ts_text>[^\x07\x1b]*)(?P<ts_term>\x07|\x1b\\)z(?P<other_seq>(?:z))c                 c   s    | ]	}d | dV  qdS )z(?:)N ).0Z_patternr   r   Y/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/wcwidth/escape_sequences.py	<genexpr>W   s    r
   )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textreturnc                 c   s    d}t | }d}||k rJ| | }|dkrB||kr"| || dfV  t| |}|r6| dfV  | }n	|dfV  |d7 }|}n|d7 }||k s||k rY| |d dfV  dS dS )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_PATTERNmatchgroupend)r   idxZtext_lenZsegment_startcharr   r   r   r	   iter_sequencesq   s*   

r   c                 C   s    d| v r
t d| } t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;z\2 )TEXT_SIZING_PATTERNsubr   )r   r   r   r	   strip_sequences   s   r   )__doc__retypingZ	sgr_stater   compiler   r   ZCURSOR_RIGHT_SEQUENCEZCURSOR_LEFT_SEQUENCEZCURSOR_HPA_SEQUENCEZCURSOR_MOVEMENT_SEQUENCEZ_HORIZONTAL_CURSOR_MOVEMENTpatternreplaceZ_SEQUENCE_CLASSIFYjoinZINDETERMINATE_EFFECT_SEQUENCEstrIteratorTupleboolr   r   r   r   r   r	   <module>   s^    	




"4