
    (ph$F                         S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJr  Sr	 " S S\
5      r " S	 S
\R                  5      r\R                  R                   \l          " S S\5      rS rS rg)z&Module providing 'sequence awareness'.    N)wcwidth)TextType)CAPABILITIES_CAUSE_MOVEMENT)SequenceSequenceTextWrapper
iter_parsemeasure_lengthc                   t    \ rS rSrSrS rS r\S 5       r\S 5       r	\S 5       r
S r\   SS	 j5       rS
rg)Termcap   z7Terminal capability of given variable name and pattern.c                 6    Xl         X l        X0l        SU l        g)z
Class initializer.

:arg str name: name describing capability.
:arg str pattern: regular expression string.
:arg str attribute: :class:`~.Terminal` attribute used to build
    this terminal capability.
N)namepattern	attribute_re_compiled)selfr   r   r   s       D/var/www/html/venv/lib/python3.13/site-packages/blessed/sequences.py__init__Termcap.__init__   s     	"     c                      SR                  U S9$ )Nz&<Termcap {self.name}:{self.pattern!r}>r   formatr   s    r   __repr__Termcap.__repr__%   s    7>>D>IIr   c                      SR                  U S9$ )z;Regular expression pattern for capability with named group.z(?P<{self.name}>{self.pattern})r   r   r   s    r   named_patternTermcap.named_pattern)   s     177T7BBr   c                 ~    U R                   c%  [        R                  " U R                  5      U l         U R                   $ )z3Compiled regular expression pattern for capability.)r   recompiler   r   s    r   re_compiledTermcap.re_compiled/   s1     $ "

4<< 8D   r   c                 (    U R                   [        ;   $ )z*Whether capability causes cursor movement.)r   r   r   s    r   	will_moveTermcap.will_move6   s     yy777r   c                     SSSSSS.R                  U R                  5      nUb  U$ SSS.R                  U R                  5      nUb7  [        U R                  R	                  U5      R                  S5      5      nX2-  $ g)a  
Horizontal carriage adjusted by capability, may be negative.

:rtype: int
:arg str text: for capabilities *parm_left_cursor*, *parm_right_cursor*, provide the
    matching sequence text, its interpreted distance is returned.
:returns: 0 except for matching '
      )cursor_left	backspacecursor_righttab	ascii_tab)parm_left_cursorparm_right_cursorr   )getr   intr#   matchgroup)r   textvalueunits       r   horizontal_distanceTermcap.horizontal_distance;   s     
 #dii. 	 L !#!"
 #dii. 	 ((..t4::1=>E<r   c	                   ^ SmU(       a  SmU(       a  SmUc  SOUnUS:X  a  U " U[         R                  " U5      U5      $ [         R                  " U" U4U-  6 5      n	U(       dN  [        US-
  US-   5       H8  n
[        U
5      U	;   d  M  U	R	                  [        U
5      T5      nU " XU5      s  $    U(       a  [         R
                  " SU4S jU	5      nO[         R
                  " SU4S	 jU	5      nU " XU5      $ )
a  
Class factory builder for given capability definition.

:arg str name: Variable name given for this pattern.
:arg str capability: A unicode string representing a terminal
    capability to build for. When ``nparams`` is non-zero, it
    must be a callable unicode string (such as the result from
    ``getattr(term, 'bold')``.
:arg str attribute: The terminfo(5) capability name by which this
    pattern is known.
:arg int nparams: number of positional arguments for callable.
:arg int numeric: Value to substitute into capability to when generating pattern
:arg bool match_grouped: If the numeric pattern should be
    grouped, ``(\d+)`` when ``True``, ``\d+`` default.
:arg bool match_any: When keyword argument ``nparams`` is given,
    *any* numeric found in output is suitable for building as
    pattern ``(\d+)``.  Otherwise, only the first matching value of
    range *(numeric - 1)* through *(numeric + 1)* will be replaced by
    pattern ``(\d+)`` in builder.
:arg bool match_optional: When ``True``, building of numeric patterns
    containing ``(\d+)`` will be built as optional, ``(\d+)?``.
:rtype: blessed.sequences.Termcap
:returns: Terminal capability instance for given capability definition
z\d+z(\d+)z(\d+)?c   r   r*      c                    > T$ N x_numeric_regexs    r   <lambda>Termcap.build.<locals>.<lambda>   s    r   c                    > T$ r@   rA   rB   s    r   rE   rF      s    ~r   )r!   escaperangestrreplacesub)clsr   
capabilityr   nparamsnumericmatch_grouped	match_anymatch_optional_outpnumr   rD   s               @r   buildTermcap.buildY   s    8  %N&N"W a<tRYYz2I>> 		*wj7&:;<Wq['A+6s8u$#mmCHnEGti88 7
 ffX'?GGffV%=uEG4),,r   )r   r   r   r   N)r   r=   FFF)__name__
__module____qualname____firstlineno____doc__r   r   propertyr   r#   r&   r:   classmethodrV   __static_attributes__rA   r   r   r   r      sp    A!J C C
 ! ! 8 8< 899>"2- 2-r   r   c                   *    \ rS rSrSrS rS rS rSrg)r      zDocstring overridden.c                 R    X l         [        R                  R                  " X40 UD6  g)zM
Class initializer.

This class supports the :meth:`~.Terminal.wrap` method.
N)termtextwrapTextWrapperr   )r   widthrc   kwargss       r   r   SequenceTextWrapper.__init__   s"     	%%d<V<r   c                    / nU R                   S::  d  [        U R                   [        5      (       d8  [        SR	                  U R                   [        U R                   5      5      5      eU R                  n[        U S5      (       + =(       d    U R                  nUR                  5         U(       GaC  / nSnU(       a  U R                  OU R                  nU R                   [        U5      -
  nU(       a+  [        US   U5      R                  5       S:X  a
  U(       a  US	 U(       ai  [        US   U5      R                  5       n	Xi-   U:  a  X:  a  U R!                  XXh5        O,UR#                  UR%                  5       5        Xi-  nU(       a  Mi  U(       a+  U(       a$  [        US   U5      R                  5       S:X  a  US	 U(       a#  UR#                  USR'                  U5      -   5        U(       a  GMC  U$ )a  
Sequence-aware variant of :meth:`textwrap.TextWrapper._wrap_chunks`.

:raises ValueError: ``self.width`` is not a positive integer
:rtype: list
:returns: text chunks adjusted for width

This simply ensures that word boundaries are not broken mid-sequence, as standard python
textwrap would incorrectly determine the length of a string containing sequences, and may
also break consider sequences part of a "word" that may be broken by hyphen (``-``), where
this implementation corrects both.
r   z0invalid width {0!r}({1!r}) (must be integer > 0)drop_whitespacer)    )rf   
isinstancer4   
ValueErrorr   typerc   hasattrrj   reversesubsequent_indentinitial_indentlenr   striplength_handle_long_wordappendpopjoin)
r   chunkslinesrc   rj   cur_linecur_lenindentrf   	chunk_lens
             r   _wrap_chunks SequenceTextWrapper._wrap_chunks   s    ::?*TZZ"="=B

D$457 7 yy%d,= ( ( @+/+?+? 	HG/4T++$:M:MFJJV,EVBZ.446"<2J$VBZ6==?	&. (..vP

-$ & (2,!=!C!C!E!KRLVchhx&889) f* r   c                    US:  a  SOXC-
  nU R                   (       a  U R                  nUS   nS=p[        Xg5       HR  u  pU	[        U
5      -  n	[	        USU	 U5      R                  5       nX:  a  US:X  a  US:X  a  U	S:X  a  US:X  a  O  OU	nMT     UR                  USU 5        XxS US'   gU(       d   UR                  UR                  5       5        gg)a  
Sequence-aware :meth:`textwrap.TextWrapper._handle_long_word`.

This method ensures that word boundaries are not broken mid-sequence, as
standard python textwrap would incorrectly determine the length of a
string containing sequences and wide characters it would also break
these "words" that would be broken by hyphen (``-``), this
implementation corrects both.

This is done by mutating the passed arguments, removing items from
'reversed_chunks' and appending them to 'cur_line'.

However, some characters (east-asian, emoji, etc.) cannot be split any
less than 2 cells, so in the case of a width of 1, we have no choice
but to allow those characters to flow outside of the given cell.
r*   r)   r   Nr>   )break_long_wordsrc   r   rs   r   ru   rw   rx   )r   reversed_chunksr|   r}   rf   
space_leftrc   chunkidxnxtr7   _
seq_lengths                r   rv   %SequenceTextWrapper._handle_long_word   s    &  !)Q
   99D#B'EMC%d2s4y %eDSk48??A
*!|
saxJRSO  3 OOE$3K("'+OB
 OOO//12 r   )rc   N)	rX   rY   rZ   r[   r\   r   r   rv   r_   rA   r   r   r   r      s    =,\.3r   r   c                   v    \ rS rSrSrS rSS jrSS jrSS jrS r	S r
SS
 jrSS jrSS jrS rSS jrSrg	)r   i  z
A "sequence-aware" version of the base :class:`str` class.

This unicode-derived class understands the effect of escape sequences
of printable length, allowing a properly implemented :meth:`rjust`,
:meth:`ljust`, :meth:`center`, and :meth:`length`.
c                 >    [         R                  " X5      nX#l        U$ )z
Class constructor.

:arg str sequence_text: A string that may contain sequences.
:arg blessed.Terminal term: :class:`~.Terminal` instance.
)r   __new___term)rM   sequence_textrc   news       r   r   Sequence.__new__  s     s2	
r   c                     U[        [        S[        UR                  5       U R	                  5       -
  5      5      [        [        U5      5      -  5      -  nSR                  X45      $ )a9  
Return string containing sequences, left-adjusted.

:arg int width: Total width given to left-adjust ``text``.  If
    unspecified, the width of the attached terminal is used (default).
:arg str fillchar: String for padding right-of ``text``.
:returns: String of ``text``, left-aligned by ``width``.
:rtype: str
        rk   r4   maxfloat	__index__ru   rs   ry   )r   rf   fillchar	rightsides       r   ljustSequence.ljust  sX     seEOO-=>?5XCWW Y Y	xx)**r   c                     U[        [        S[        UR                  5       U R	                  5       -
  5      5      [        [        U5      5      -  5      -  nSR                  X045      $ )a;  
Return string containing sequences, right-adjusted.

:arg int width: Total width given to right-adjust ``text``.  If
    unspecified, the width of the attached terminal is used (default).
:arg str fillchar: String for padding left-of ``text``.
:returns: String of ``text``, right-aligned by ``width``.
:rtype: str
r   rk   r   )r   rf   r   leftsides       r   rjustSequence.rjust&  sX     ceEOO-=>?5XCWWY Yxx())r   c           	         [        S[        UR                  5       5      U R                  5       -
  5      S-  nU[	        [        S[
        R                  " U5      5      [        [        U5      5      -  5      -  nU[	        [        S[
        R                  " U5      5      [        [        U5      5      -  5      -  nSR                  X@U45      $ )a4  
Return string containing sequences, centered.

:arg int width: Total width given to center ``text``.  If
    unspecified, the width of the attached terminal is used (default).
:arg str fillchar: String for padding left and right-of ``text``.
:returns: String of ``text``, centered by ``width``.
:rtype: str
r   r>   rk   )
r   r   r   ru   r4   mathfloorrs   ceilry   )r   rf   r   splitr   r   s         r   centerSequence.center4  s     Cu01DKKMABQFcdjj'(E#h-,@@B Bsdii&'5X+?? A A	xx344r   c                    SnSnUR                  5       n[        U R                  U R                  5       5      nU H/  u  pgU(       d  U[	        [        U5      S5      -  nX4:  a    OX&-  nM1     USR                  S U 5       5      -   $ )aW  
Truncate a string in a sequence-aware manner.

Any printable characters beyond ``width`` are removed, while all
sequences remain in place. Horizontal Sequences are first expanded
by :meth:`padd`.

:arg int width: The printable width to truncate the string to.
:rtype: str
:returns: String truncated to at most ``width`` printable characters.
rk   r   c              3   <   #    U  H  u  pU(       d  M  Uv   M     g 7fr@   rA   ).0r7   caps      r   	<genexpr>$Sequence.truncate.<locals>.<genexpr>`  s     HjCjs   	)r   r   r   paddr   r   ry   )r   rf   outputcurrent_widthtarget_width
parsed_seqr7   r   s           r   truncateSequence.truncateE  s     (

DIIK8
 $IDWT]A!66 /NF $ HjHHHHr   c                 @    [        S U R                  SS9 5       5      $ )uA  
Return the printable length of string containing sequences.

Strings containing ``term.left`` or ``\b`` will cause "overstrike",
but a length less than 0 is not ever returned. So ``_\b+`` is a
length of 1 (displays as ``+``), but ``\b`` alone is simply a
length of 0.

Some characters may consume more than one cell, mainly those CJK
Unified Ideographs (Chinese, Japanese, Korean) defined by Unicode
as half or full-width characters.

For example:

    >>> from blessed import Terminal
    >>> from blessed.sequences import Sequence
    >>> term = Terminal()
    >>> msg = term.clear + term.red(u'コンニチハ')
    >>> Sequence(msg, term).length()
    10

.. note:: Although accounted for, strings containing sequences such
    as ``term.clear`` will not give accurate returns, it is not
    considered lengthy (a length of 0).
c              3   L   #    U  H  n[        [        U5      S 5      v   M     g7f)r   N)r   r   )r   w_chars     r   r   "Sequence.length.<locals>.<genexpr>}  s      O9Nv3wv**9Ns   "$Trt   )sumr   r   s    r   ru   Sequence.lengthb  s     6 O9NOOOr   Nc                 @    U R                  5       R                  U5      $ )z
Return string of sequences, leading and trailing whitespace removed.

:arg str chars: Remove characters in chars instead of whitespace.
:rtype: str
:returns: string of sequences with leading and trailing whitespace removed.
)
strip_seqsrt   r   charss     r   rt   Sequence.strip  s      &&u--r   c                 @    U R                  5       R                  U5      $ )z
Return string of all sequences and leading whitespace removed.

:arg str chars: Remove characters in chars instead of whitespace.
:rtype: str
:returns: string of sequences with leading removed.
)r   lstripr   s     r   r   Sequence.lstrip        ''..r   c                 @    U R                  5       R                  U5      $ )z
Return string of all sequences and trailing whitespace removed.

:arg str chars: Remove characters in chars instead of whitespace.
:rtype: str
:returns: string of sequences with trailing removed.
)r   rstripr   s     r   r   Sequence.rstrip  r   r   c                      U R                  SS9$ )zv
Return ``text`` stripped of only its terminal sequences.

:rtype: str
:returns: Text with terminal sequences removed
Tr   )r   r   s    r   r   Sequence.strip_seqs  s     yyty$$r   c                     Sn[        U R                  U 5       HM  u  p4U(       d  X#-  nM  UR                  U5      nUS:  a
  USU-  -  nM3  US:  a  USU nM@  U(       a  MI  X#-  nMO     U$ )z
Return non-destructive horizontal movement as destructive spacing.

:arg bool strip: Strip terminal sequences
:rtype: str
:returns: Text adjusted for horizontal movement
rk   r    N)r   r   r:   )r   rt   outpr7   r   r8   s         r   r   Sequence.padd  sw     #DJJ5ID++D1Eqye#FU|U 6 r   rA   )r   r@   )F)rX   rY   rZ   r[   r\   r   r   r   r   r   ru   rt   r   r   r   r   r_   rA   r   r   r   r     s@    
+*5"I:P:.//%r   r   c              #      #    U R                   R                  U5       H@  nUR                  nUR                  U5      nUS:X  a  US4v   M.  X@R                  U   4v   MB     g7f)z
Generator yields (text, capability) for characters of ``text``.

value for ``capability`` may be ``None``, where ``text`` is
:class:`str` of length 1.  Otherwise, ``text`` is a full
matching sequence of given capability.
MISMATCHN)_caps_compiled_anyfinditer	lastgroupr6   caps)rc   r7   r5   r   r8   s        r   r   r     s\      ((11$7D!:$-4(( 8s   A!A#c                 x     [        [        X5      5      u  pU(       a  [        U 5      $  g! [         a     gf = f)z[
.. deprecated:: 1.12.0.

:rtype: int
:returns: Length of the first sequence in the string
r   )nextr   rs   StopIteration)r7   rc   rN   s      r   r	   r	     sD    
4 67t9    s   ', 
99)r\   r!   r   rd   r   blessed._compatr   blessed._capabilitiesr   __all__objectr   re   r   r   r   r	   rA   r   r   <module>r      sw    , 	    % =
M
x-f x-vh3(.. h3b '22::  xx xv)"r   