
    i0                    $   S r SSKJr  SSKrSSKJr  SSKJrJrJ	r	  \(       a  SSKJ
r
   " S S\5      r\R                  " S	5      r\R                  " S
5      rSr " S S\	5      r\" 5       rSS jrSS jrSS jr      SS jrSS jrSS jrg)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                      \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSrSr Sr!S r"S!r#g")#_SGR   z
SGR (Select Graphic Rendition) parameter codes.

References:
- https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
- https://github.com/tehmaze/ansi/tree/master/ansi/colour
r                           	                              %   &   '   (   /   0   1   Z   a   d   k    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)       Q/var/www/html/banglarbhumi/venv/lib/python3.13/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OrN   r
   z\x1b\[([\d;:]*)mz\x1b\[[\d;:]*mz[0mc                      \ rS rSr% SrSrS\S'   SrS\S'   SrS\S'   Sr	S\S'   Sr
S\S	'   SrS\S
'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   Srg)	_SGRStateJ   a  
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.   rT   __annotations__rU   rV   rW   rX   rY   rZ   r[   r\   r]   r_   r`   rM   r)   rN   rO   rQ   rQ   J   s    " D$CFDItE4KGTFDM4"d")-J&-)-J&-rN   rQ   c                   U R                   =(       d    U R                  =(       d    U R                  =(       d    U R                  =(       d    U R                  =(       d    U R
                  =(       do    U R                  =(       d\    U R                  =(       dI    U R                  =(       d6    U R                  =(       d#    U R                  SL=(       d    U R                  SL$ )z
Return True if any attributes are set.

:param state: The SGR state to check.
:returns: True if any attribute differs from default.
N)rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r_   r`   )states    rO   _sgr_state_is_activerd   n   s     JJ L%)) Lu|| Lu L{{L#//L38==LDILLL""L&+&<&<L t+L 05/?/?t/KMrN   c                   [        U 5      (       d  gU R                  S4U R                  S4U R                  S4U R                  S4U R
                  S4U R                  S4U R                  S4U R                  S	4U R                  S
4U R                  S4/
nU VVs/ s H  u  p#U(       d  M  UPM     nnnU R                  b1  UR                  SR                  S U R                   5       5      5        U R                  b1  UR                  SR                  S U R                   5       5      5        SSR                  U5       S3$ s  snnf )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   #    U  H  n[        U5      v   M     g 7fNstr.0ps     rO   	<genexpr>)_sgr_state_to_sequence.<locals>.<genexpr>        @/?!s1vv/?   c              3  8   #    U  H  n[        U5      v   M     g 7frs   rt   rv   s     rO   ry   rz      r{   r|   z[m)rd   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r_   appendjoinr`   )rc   
bool_attrsactivecodeparamss        rO   _sgr_state_to_sequencer   {   s'     && 
SEIIs+ellC-@	#c 2U5F5F4L	u||S1E4G4G3M			&	J (2<z|vVdzF< #chh@u/?/?@@A#chh@u/?/?@@A388F#$A&& =s   E,Ec                   [         R                  U 5      nU(       d  / $ UR                  S5      nU(       d  S/$ / nUR                  S5       Hz  nSU;   aN  UR                  S5       Vs/ s H  oU(       a  [	        U5      OSPM     nnUR                  [        U5      5        MW  UR                  U(       a  [	        U5      OS5        M|     U$ s  snf )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.
r   r   rq   :)_SGR_PATTERNmatchgroupsplitintr   tuple)sequencer   
params_strresultparamrx   partss          rO   _parse_sgr_paramsr      s     x(E	QJs
*,F!!#&%< 27S1AB1AAqSVa'1AEBMM%,'MM#e*15 ' M	 Cs   )Cc                    [        U 5      n[        U[        5      (       a  gUS:X  a/  [        U 5      n[        U[        5      (       a  g[        U5      SU4$ US:X  ao  [        U 5      [        U 5      [        U 5      pen[        U[        5      (       d*  [        U[        5      (       d  [        U[        5      (       a  g[        U5      SXEU4$  g! [         a     gf = f)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.
Nr   r   )next
isinstancer   r   StopIteration)r   basemodenrgbs          rO   _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                	   [        U5      n[        U5      nU GH  n[        U[        5      (       am  [	        U5      S:  a'  US   [
        R                  :X  a  U R                  US9n O5[	        U5      S:  a&  US   [
        R                  :X  a  U R                  US9n M  U[
        R                  :X  a  [        n M  U[
        R                  :X  a  U R                  SS9n M  U[
        R                  :X  a  U R                  SS9n M  U[
        R                  :X  a  U R                  SS9n GM  U[
        R                  :X  a  U R                  SS	9n GM8  U[
        R                  :X  a  U R                  SS
9n GM^  U[
        R                   :X  a  U R                  SS9n GM  U[
        R"                  :X  a  U R                  SS9n GM  U[
        R$                  :X  a  U R                  SS9n GM  U[
        R&                  :X  a  U R                  SS9n GM  U[
        R(                  :X  a  U R                  SS9n GM  U[
        R*                  :X  a  U R                  SSS9n GMC  U[
        R,                  :X  a  U R                  SS9n GMi  U[
        R.                  :X  a  U R                  SSS9n GM  U[
        R0                  :X  a  U R                  SSS9n GM  U[
        R2                  :X  a  U R                  SS9n GM  U[
        R4                  :X  a  U R                  SS9n GM  U[
        R6                  :X  a  U R                  SS9n GM)  [
        R8                  Us=::  a  [
        R:                  ::  d.  O  [
        R<                  Us=::  a  [
        R>                  ::  a  O  OU R                  U4S9n GM  [
        R@                  Us=::  a  [
        RB                  ::  d.  O  [
        RD                  Us=::  a  [
        RF                  ::  a  O  OU R                  U4S9n GM  U[
        RH                  :X  a  U R                  SS9n GM#  U[
        RJ                  :X  a  U R                  SS9n GMI  U[
        R                  :X  a6  [M        U[
        R                  5      =n(       a  U R                  US9n GM  GM  U[
        R                  :X  d  GM  [M        U[
        R                  5      =n(       d  GM  U R                  US9n GM     U $ )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   )r_   )r`   T)rT   )rU   )rV   )rW   )rX   )rY   )rZ   )r[   )r\   )r]   F)rT   rU   )rW   r]   )rX   rY   N)'r   iterr   r   lenr
   rC   _replacerG   r/   _SGR_STATE_DEFAULTr0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rI   rJ   rE   rF   rK   rL   rD   rH   r   )rc   r   params_listr   rx   colors         rO   _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 LrN   c                h   [        S U  5       5      (       a  U (       d  [        U 5      $ / n[        nU  Hz  n[        U5      n[        R                  U5       H  n[        X%R                  5       5      nM     U(       a  XC-   OUn[        U5      (       a	  U[        -   nUR                  U5        M|     U$ )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   #    U  H  n[         R                  U5      v   M     g 7frs   )_SGR_QUICK_CHECKsearch)rw   lines     rO   ry    propagate_sgr.<locals>.<genexpr>=  s     ?&&t,,s   "$)anylistr   r   r   finditerr   r   rd   
_SGR_RESETr   )linesr   rc   r   prefixr   output_lines          rO   propagate_sgrr   #  s    4 ????uE{FE'. "**40E%e[[];E 1 (.fm4&&%
2Kk"  MrN   )rc   rQ   returnrS   )rc   rQ   r   ru   )r   ru   r   zlist[int | tuple[int, ...]])r   zIterator[int | tuple[int, ...]]r   r   r   r^   )rc   rQ   r   ru   r   rQ   )r   zSequence[str]r   z	list[str])r.   
__future__r   reenumr   typingr   r   r   r   r
   compiler   r   r   rQ   r   rd   r   r   r   r   r   r)   rN   rO   <module>r      s    # 
  6 6&7 &Z zz-. ::/0  
.
 .B [ 
M'8<+36:Nb/rN   