+
    =i0                    (   R t ^ RIHt ^ RIt^ RIHt ^ RIHtHtH	t	 ]'       d   ^ RIH
t
  ! R R]4      t]P                  ! R4      t]P                  ! R	4      tR
t ! R R]	4      t]! 4       tR R ltR R ltR R ltR R ltR R ltR R ltR# )as  
SGR (Select Graphic Rendition) state tracking for terminal escape sequences.

This module provides functions for tracking and propagating terminal styling (bold, italic, colors,
etc.) via public API propagate_sgr(), and its dependent functions, cut() and wrap(). It only has
attributes necessary to perform its functions, eg 'RED' and 'BLUE' attributes are not defined.
)annotationsN)IntEnum)TYPE_CHECKINGIterator
NamedTuple)Sequencec                      ] tR t^tRt^ t^t^t^t^t	^t
^t^t^t^	t^t^t^t^t^t^t^t^t^t^%t^&t^'t^(t^/t^0t^1t^Zt^at ^dt!^kt"Rt#R# )_SGRz
SGR (Select Graphic Rendition) parameter codes.

References:
- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
- https://github.com/tehmaze/ansi/tree/master/ansi/colour
 N)$__name__
__module____qualname____firstlineno____doc__RESETBOLDDIMITALIC	UNDERLINEBLINKRAPID_BLINKINVERSEHIDDENSTRIKETHROUGHDOUBLE_UNDERLINEBOLD_DIM_OFF
ITALIC_OFFUNDERLINE_OFF	BLINK_OFFINVERSE_OFF
HIDDEN_OFFSTRIKETHROUGH_OFFFG_BLACKFG_WHITEFG_EXTENDED
FG_DEFAULTBG_BLACKBG_WHITEBG_EXTENDED
BG_DEFAULTFG_BRIGHT_BLACKFG_BRIGHT_WHITEBG_BRIGHT_BLACKBG_BRIGHT_WHITE__static_attributes__r
       t/Users/tonyclaw/.openclaw/workspace/scripts/youtube-playlists/venv/lib/python3.14/site-packages/wcwidth/sgr_state.pyr	   r	      s     ED
CFIEKGFMLJMIKJHHKJHHKJOOOOr/   r	   z\x1b\[([\d;:]*)mz\x1b\[[\d;:]*mz[0mc                      ] tR t^Jt$ RtRtR]R&   RtR]R&   RtR]R&   Rt	R]R&   Rt
R]R&   RtR]R	&   RtR]R
&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR]R&   RtR# )	_SGRStatea  
Track active SGR terminal attributes by category (immutable).

:param bold: Bold attribute (SGR 1).
:param dim: Dim/faint attribute (SGR 2).
:param italic: Italic attribute (SGR 3).
:param underline: Underline attribute (SGR 4).
:param blink: Slow blink attribute (SGR 5).
:param rapid_blink: Rapid blink attribute (SGR 6).
:param inverse: Inverse/reverse attribute (SGR 7).
:param hidden: Hidden/invisible attribute (SGR 8).
:param strikethrough: Strikethrough attribute (SGR 9).
:param double_underline: Double underline attribute (SGR 21).
:param foreground: Foreground color as tuple of SGR params, or None for default.
:param background: Background color as tuple of SGR params, or None for default.
Fboolbolddimitalic	underlineblinkrapid_blinkinversehiddenstrikethroughdouble_underlineNtuple[int, ...] | None
foreground
backgroundr
   )r   r   r   r   r   r4   __annotations__r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   r@   r.   r
   r/   r0   r2   r2   J   s    " D$CFDItE4KGTFDM4"d")-J&-)-J&-r/   r2   c                    V ^8  d   QhRRRR/# )   stater2   returnr3   r
   )formats   "r0   __annotate__rG   n   s     
M 
M	 
Md 
Mr/   c                   V P                   ;'       g    V P                  ;'       g    V P                  ;'       g    V P                  ;'       g    V P                  ;'       g    V P
                  ;'       gu    V P                  ;'       ga    V P                  ;'       gM    V P                  ;'       g9    V P                  ;'       g%    V P                  RJ;'       g    V P                  RJ# )z
Return True if any attributes are set.

:param state: The SGR state to check.
:returns: True if any attribute differs from default.
N)r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   r@   )rD   s   &r0   _sgr_state_is_activerI   n   s     JJ L L%)) L Lu|| L Lu L L{{L L#//L L38==L LDILLL L""L L&+&<&<L L t+L L 05/?/?t/KMr/   c                    V ^8  d   QhRRRR/# )rC   rD   r2   rE   strr
   )rF   s   "r0   rG   rG   {   s     ' ') ' 'r/   c                   \        V 4      '       g   R# V P                  R3V P                  R3V P                  R3V P                  R3V P
                  R3V P                  R3V P                  R3V P                  R	3V P                  R
3V P                  R3.
pV UUu. uF  w  r#V'       g   K  VNK  	  pppV P                  e2   VP                  RP                  R V P                   4       4      4       V P                  e2   VP                  RP                  R V P                   4       4      4       RRP                  V4       R2# u uppi )z
Generate minimal SGR sequence to restore this state from reset.

:param state: The SGR state to convert.
:returns: SGR escape sequence string, or empty string if no attributes set.
 12345678921;c              3  8   "   T F  p\        V4      x  K  	  R # 5iNrK   .0ps   & r0   	<genexpr>)_sgr_state_to_sequence.<locals>.<genexpr>        @/?!s1vv/?   c              3  8   "   T F  p\        V4      x  K  	  R # 5irZ   r[   r\   s   & r0   r_   r`      ra   rb   z[m)rI   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   appendjoinr@   )rD   
bool_attrsactivecodeparamss   &    r0   _sgr_state_to_sequencerk   {   s)     && 
SEIIs+ellC-@	#c 2U5F5F4L	u||S1E4G4G3M			&	J (2<z|vVddzF< #chh@u/?/?@@A#chh@u/?/?@@A388F#$A&& =s   E
.E
c                    V ^8  d   QhRRRR/# )rC   sequencerK   rE   zlist[int | tuple[int, ...]]r
   )rF   s   "r0   rG   rG      s       (C r/   c                   \         P                  V 4      pV'       g   . # VP                  ^4      pV'       g   ^ .# . pVP                  R4       F|  pRV9   dO   VP                  R4       Uu. uF  qU'       d   \	        V4      M^ NK  	  ppVP                  \        V4      4       KX  TP                  V'       d   \	        V4      M^ 4       K~  	  V# u upi )a  
Parse SGR sequence and return list of parameter values.

Handles compound sequences like ``\x1b[1;31;4m`` -> [1, 31, 4].
Empty params (e.g., ``\x1b[m``) are treated as [0] (reset).
Colon-separated extended colors like ``\x1b[38:2::255:0:0m`` are returned
as tuples: [(38, 2, 255, 0, 0)].

:param sequence: SGR escape sequence string.
:returns: List of integer parameters or tuples for colon-separated colors.
rX   :)_SGR_PATTERNmatchgroupsplitintre   tuple)rm   rq   
params_strresultparamr^   partss   &      r0   _parse_sgr_paramsrz      s     x(E	QJs
*,F!!#&%< 27S1AB1AAqSVa'1AEBMM%,'MM#e*15 ' M	 Cs   ,Cc               $    V ^8  d   QhRRRRRR/# )rC   rj   zIterator[int | tuple[int, ...]]basert   rE   r>   r
   )rF   s   "r0   rG   rG      s$      +36r/   c                    \        V 4      p\        V\        4      '       d   R# V^8X  d2   \        V 4      p\        V\        4      '       d   R# \        V4      ^V3# V^8X  dt   \        V 4      \        V 4      \        V 4      rep\        V\        4      '       g-   \        V\        4      '       g   \        V\        4      '       d   R# \        V4      ^WEV3#  R#   \         d     R# i ; i)a%  
Parse extended color (256-color or RGB) from parameter iterator.

:param params: Iterator of remaining SGR parameters (semicolon-separated format).
:param base: Base code (38 for foreground, 48 for background).
:returns: Color tuple like (38, 5, N) or (38, 2, R, G, B), or None if malformed.
N)next
isinstanceru   rt   StopIteration)rj   r|   modenrgbs   &&     r0   _parse_extended_colorr      s    F|dE""19VA!U##Iq!$$196lDL$v,!A!U##z!U';';z!U?S?SIq!**	    s)   !C (C C A)C C C)(C)c               $    V ^8  d   QhRRRRRR/# )rC   rD   r2   rm   rK   rE   r
   )rF   s   "r0   rG   rG      s&     N NY N# N) Nr/   c                
   \        V4      p\        V4      pV EFV  p\        V\        4      '       d   \	        V4      ^8  d0   V^ ,          \
        P                  8X  d   V P                  VR7      p M>\	        V4      ^8  d/   V^ ,          \
        P                  8X  d   V P                  VR7      p K  V\
        P                  8X  d	   \        p K  V\
        P                  8X  d   V P                  RR7      p K  V\
        P                  8X  d   V P                  RR7      p EK	  V\
        P                  8X  d   V P                  RR7      p EK3  V\
        P                  8X  d   V P                  RR7      p EK]  V\
        P                  8X  d   V P                  RR7      p EK  V\
        P                   8X  d   V P                  RR	7      p EK  V\
        P"                  8X  d   V P                  RR
7      p EK  V\
        P$                  8X  d   V P                  RR7      p EK  V\
        P&                  8X  d   V P                  RR7      p EK/  V\
        P(                  8X  d   V P                  RR7      p EKY  V\
        P*                  8X  d   V P                  RRR7      p EK  V\
        P,                  8X  d   V P                  RR7      p EK  V\
        P.                  8X  d   V P                  RRR7      p EK  V\
        P0                  8X  d   V P                  RRR7      p EK  V\
        P2                  8X  d   V P                  RR
7      p EK.  V\
        P4                  8X  d   V P                  RR7      p EKX  V\
        P6                  8X  d   V P                  RR7      p EK  \
        P8                  Tu;8:  d   \
        P:                  8:  g1   M \
        P<                  Tu;8:  d   \
        P>                  8:  d   M MV P                  V3R7      p EK  \
        P@                  Tu;8:  d   \
        PB                  8:  g1   M \
        PD                  Tu;8:  d   \
        PF                  8:  d   M MV P                  V3R7      p EKd  V\
        PH                  8X  d   V P                  RR7      p EK  V\
        PJ                  8X  d   V P                  RR7      p EK  V\
        P                  8X  d;   \M        V\
        P                  4      ;p'       d   V P                  VR7      p EK  EK  V\
        P                  8X  g   EK  \M        V\
        P                  4      ;p'       g   EKD  V P                  VR7      p EKY  	  V # )z
Parse SGR sequence and return new state with updates applied.

:param state: Current SGR state.
:param sequence: SGR escape sequence string.
:returns: New SGRState with updates applied.
)r?   )r@   T)r4   )r5   )r6   )r7   )r8   )r9   )r:   )r;   )r<   )r=   F)r4   r5   )r7   r=   )r8   r9   N)'rz   iterr   ru   lenr	   r$   _replacer(   r   _SGR_STATE_DEFAULTr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r*   r+   r&   r'   r,   r-   r%   r)   r   )rD   rm   params_listrj   r^   colors   &&    r0   _sgr_state_updater      s    $H-K+Fa1v{qtt'7'77!4Q11)9)9!9!4

?&E$))^NNN-E$((]NNtN,E$++NN$N/E$.. NNTN2E$**_NNN.E$"""NNtN4E$,,NN4N0E$++NN$N/E$$$$NNN6E$'''NNDN9E$###NN5N9E$//!NN%N0E$$$$NNUUNKE$.. NNENBE$"""NN5N1E$//!NN%N0E$(((NNN7Emmq1DMM1%%Bd.B.BBNNqdN3Emmq1DMM1%%Bd.B.BBNNqdN3E$//!NNdN3E$//!NNdN3E$"""-fd6F6FGGuG%8 H$"""-fd6F6FGGuGG%8C D Lr/   c                    V ^8  d   QhRRRR/# )rC   lineszSequence[str]rE   z	list[str]r
   )rF   s   "r0   rG   rG   #  s     / / /9 /r/   c                   \         ;QJ d    R V  4       F  '       g   K   RM	  RM! R V  4       4      '       d	   V '       g   \        V 4      # . p\        pV  F  p\        V4      p\        P                  V4       F  p\        W%P                  4       4      pK  	  V'       d	   WC,           MTp\        V4      '       d   V\        ,           pVP                  V4       K  	  V# )a  
Propagate SGR codes across wrapped lines.

When text with SGR styling is wrapped across multiple lines, each line
needs to be self-contained for proper display. This function:

- Ends each line with ``\x1b[0m`` if styles are active (prevents bleeding)
- Starts each subsequent line with the active style restored

:param lines: List of text lines, possibly containing SGR sequences.
:returns: List of lines with SGR codes propagated.

Example::

    >>> propagate_sgr(['\x1b[31mhello', 'world\x1b[0m'])
    ['\x1b[31mhello\x1b[0m', '\x1b[31mworld\x1b[0m']

This is useful in cases of making special editors and viewers, and is used for the
default modes (propagate_sgr=True) of :func:`wcwidth.width` and :func:`wcwidth.clip`.

When wrapping and clipping text containing SGR sequences, maybe a previous line enabled the BLUE
color--if we are viewing *only* the line following, we would want the carry over the BLUE color,
and all lines with sequences should end with terminating reset (``\x1b[0m``).
c              3  L   "   T F  p\         P                  V4      x  K  	  R # 5irZ   )_SGR_QUICK_CHECKsearch)r]   lines   & r0   r_    propagate_sgr.<locals>.<genexpr>=  s     ?&&t,,s   "$TF)anylistr   rk   rp   finditerr   rr   rI   
_SGR_RESETre   )r   rw   rD   r   prefixrq   output_lines   &      r0   propagate_sgrr   #  s    4 3??333????uE{FE'. "**40E%e[[];E 1 (.fm4&&%
2Kk"  Mr/   )r   
__future__r   reenumr   typingr   r   r   r   r	   compilerp   r   r   r2   r   rI   rk   rz   r   r   r   r
   r/   r0   <module>r      s    # 
  6 6&7 &Z zz-. ::/0  
.
 .B [ 
M'8<:Nb/r/   