
    ;OOfa                        d dl mZmZ d dlZd dlZ	 d dlZd dlmZm	Z	 d dl
mZ d dlmZmZmZmZ  ed      dz   e e edd                  z   Zd	Zd
Zd ZdZdZdZedz  ez   Zedz
  ZdZdZedz  ez   Zedz
  ZeZg dZ g dZ!g dZ"g dZ#g dZ$e$e D  cg c]  } e D ]  }e D ]  }| ||f	   c}}} z   e!D cg c]  }|||f	 c}z   Z%e$e"D  cg c]  } e"D ]  }e"D ]  }| ||f	   c}}} z   e#D cg c]  }|||f	 c}z   Z& e'e%      dk(  sJ  e'e&      dk(  sJ dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0d Z1d!Z2d"Z3d#Z4d$Z5d%Z6d&Z7d'Z8e(e*z  e+z  e3z  e4z  e6z  e5z  e7z  e8z  Z9e)e-z  e.z  Z:d(Z;d)Z<d*Z=d+Z>d,Z?d-Z@d.ZAd/ZBd0ZCd1ZDd2ZEd3ZFd4ZGd5ZHd6ZId7ZJd8ZKe<e=e>e?e@eAeBeCeDeEeFeGeHeIeJeKgZLe5e7e4e6e3e8d9ZMd: ZN eNe d      ZO eNd ge!z   d;gz   d      ZP eNe"d      ZQ eNd ge#z   d;gz   d      ZRe D cg c]  } e	|dd       c}ZSe!D cg c]  } e	|dd<       c}ZTe"D cg c]  } e	|dd       c}ZUe#D cg c]  } e	|dd<       c}ZV eWd      D cg c]  }eO e	|dd          c}ZX eWd<      D cg c]  }eP e	|d<d          c}ZY eWd      D cg c]  }eQ e	|dd          c}ZZ eWd<      D cg c]  }eR e	|d<d          c}Z[d= Z\d> Z]d? Z^d@ Z_dA Z`dB ZadC ZbdD ZcdE Zd G dF dGee      Zf G dH dIeg      Zh G dJ dKeg      Zi G dL dMee      Zj G dN dO eej                  eg            ZldP ZmendQk(  r em        yy# e$ r Y %w xY wc c}}} w c c}w c c}}} w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w c c}w )R    )divisionprint_functionN)StoppingContext	int_scale)signals)Bbytes3xrangewith_metaclass?       zupdate palette entryzinput descriptors changed                     )r   _               )r         &   0   :   D   N   X   b   l   v                                       )r         r   ).   \   s   r2         r.      ))r   r   r   )r3   r   r   )r   r3   r   )r3   r3   r   )r   r   r1   )r3   r   r3   )r   r3   r3   )   r:   r:   )   r;   r;   )r   r   r   )r   r   r   )r   r   r   )r5   r5   r   )r   r   r   )r   r   r   )r   r   r   r"   i l      ~ l          l          l           l         @ l          l          l          l          l          l          l           l          @l            l            defaultblackzdark redz
dark greenbrownz	dark bluezdark magentaz	dark cyanz
light grayz	dark grayz	light redzlight greenyellowz
light bluezlight magentaz
light cyanwhite)bolditalics	underlineblinkstandoutstrikethroughc                    dgt        t        |       dz
        D cg c]  }| |   | |dz      z   dz   dz   c}z   |gz   }g }t        t        |      dz
        D ]%  }||dz      ||   z
  }|j                  |g|z         ' |S c c}w )a1  
    Generate a lookup table for finding the closest item in values.
    Lookup returns (index into values)+1

    values -- list of values in ascending order, all < size
    size -- size of lookup table and maximum value

    >>> _value_lookup_table([0, 7, 9], 10)
    [0, 0, 0, 0, 1, 1, 1, 1, 2, 2]
    r   r      )rangelenextend)valuessizeimiddle_valueslookup_tablecounts         U/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/urwid/display_common.py_value_lookup_tablerS      s     Cs6{Q') #1Iq1u59a? ) ),062ML3}%a'( )a!e$}Q'77QC%K() )s   Br   e   c                 R    | dz  } | dk  rt         S | t        k\  rt        S t        | z   S )zReturn ths color number for gray number gnum.

    Color cube black and white are returned for 0 and 25 respectively
    since those values aren't included in the gray scale.

    r   r   )_CUBE_BLACK_GRAY_SIZE_256_CUBE_WHITE_256_GRAY_START_256gnums    rR   _gray_num_256r\      s3     	AIDax~T!!    c                 R    | dz  } | dk  rt         S | t        k\  rt        S t        | z   S )zReturn ths color number for gray number gnum.

    Color cube black and white are returned for 0 and 9 respectively
    since those values aren't included in the gray scale.

    r   r   )rV   _GRAY_SIZE_88_CUBE_WHITE_88_GRAY_START_88rZ   s    rR   _gray_num_88rb      s3     	AIDax}D  r]   c                     d| z  S )Nz#%06x )nums    rR   _color_desc_truerf      s    S>r]   c                    | dk\  r| dk  sJ |        | t         k  rd| z  S | t        k  rS| t         z  } | t        z  | t        z  } }| t        z  | t        z  } }| t        z  }dt        |   t        |   t        |   fz  S dt        | t        z
     z  S )a  
    Return a string description of color number num.
    0..15 -> 'h0'..'h15' basic colors (as high-colors)
    16..231 -> '#000'..'#fff' color cube colors
    232..255 -> 'g3'..'g93' grays

    >>> _color_desc_256(15)
    'h15'
    >>> _color_desc_256(16)
    '#000'
    >>> _color_desc_256(17)
    '#006'
    >>> _color_desc_256(230)
    '#ffd'
    >>> _color_desc_256(233)
    'g7'
    >>> _color_desc_256(234)
    'g11'

    r   r   h%d#%x%x%xg%d)_CUBE_STARTrY   _CUBE_SIZE_256_CUBE_STEPS_256_16_GRAY_STEPS_256_101re   bgrs       rR   _color_desc_256rs      s    * !8c	&3&!
[s{
_{~%sn'<3~%sn'<3. .q13Ea3Hq!# # 	#&s_'<===r]   c                    | dkD  r| dk  sJ | t         k  rd| z  S | t        k  rJ| t         z  } | t        z  | t        z  } }| t        z  | t        z  }}dt        |   t        |   t        |   fz  S dt        | t        z
     z  S )a  
    Return a string description of color number num.
    0..15 -> 'h0'..'h15' basic colors (as high-colors)
    16..79 -> '#000'..'#fff' color cube colors
    80..87 -> 'g18'..'g90' grays

    >>> _color_desc_88(15)
    'h15'
    >>> _color_desc_88(16)
    '#000'
    >>> _color_desc_88(17)
    '#008'
    >>> _color_desc_88(78)
    '#ffc'
    >>> _color_desc_88(81)
    'g36'
    >>> _color_desc_88(82)
    'g45'

    r   r"   rh   ri   rj   )rk   ra   _CUBE_SIZE_88_CUBE_STEPS_88_16_GRAY_STEPS_88_101ro   s       rR   _color_desc_88rx     s    * 7sRx
[s{
^{}$c]&:3M!3-#71-a02CA2Fa " " 	"%cN&:;;;r]   c                    t        |       }|t        |   \  }}}|dz  |dz  z   |z   S | j                  d      sy t        |       dk(  r| dd  }t	        |d      S t        |       dk(  r d| d   d| d	   d| d
   }t	        |d      S y )Nr   r   #   r   r   0x0rH   r   )_parse_color_256_COLOR_VALUES_256
startswithrJ   int)desccrr   rq   rp   hs         rR   _parse_color_truer   0  s    A}%a(	AqRAF#a''??3
4yA~H1bz	Ta7DGT!W51bzr]   c                    t        |       dkD  ry	 | j                  d      rt        | dd d      }|dk  s|dkD  ry|S | j                  d      rot        |       dk(  rat        | dd d	      }|dk  ry|d	z  |d	z  }}|d	z  |d	z  }}t        |   }t        |   }t        |   }t        |t
        z  |z   t
        z  z   |z   S | j                  d
      r$t        | dd d	      }|dk  s|dkD  ryt        |   }n6| j                  d      r$t        | dd d      }|dk  s|dkD  ryt        |   }ny|dk(  rt        S |dz  }|t        k(  rt        S t        |z   S # t        $ r Y yw xY w)a  
    Return a color number for the description desc.
    'h0'..'h255' -> 0..255 actual color number
    '#000'..'#fff' -> 16..231 color cube colors
    'g0'..'g100' -> 16, 232..255, 231 grays and color cube black/white
    'g#00'..'g#ff' -> 16, 232...255, 231 gray and color cube black/white

    Returns None if desc is invalid.

    >>> _parse_color_256('h142')
    142
    >>> _parse_color_256('#f00')
    196
    >>> _parse_color_256('g100')
    231
    >>> _parse_color_256('g#80')
    244
    r   Nr   r   
   r   r   rz   r   g#rH   rq   d   )rJ   r   r   _CUBE_256_LOOKUP_16rk   rl   _GRAY_256_LOOKUP_GRAY_256_LOOKUP_101rV   rW   rX   rY   
ValueErrorr   re   rgbrp   rq   rr   grays          rR   r~   r~   A  s   & 4y1},??3d12h#CQw#)J??3CINd12h#CQw2XsbysA8SBYqA#A&A#A&A#A&A!n"4q"8N!JJQNN ??4 tABx$Dax4#:#D)D__S!tABx$Dax4#:'-D19	>!""%% sF   *E E 3E 2AE >*E )4E 
E )
E 4E E 	EEc                     | j                  d      rt        |       dk(  sy t        ddj                  | dd | dd | dd fD cg c]  }t	        t        |d      dz  d       c}      z         }t        |      S c c}w )	Nrz   r{    r   r      r   x)r   rJ   r~   joinformatr   rs   )r   r   c256s      rR   _true_to_256r     s    __S!c$i1nC"''q)T!AYQq	3+ 	s1bz2~s#+ #  D
 4  +s    A:c                    t        |       dk(  r| dd | d   z   | d   z   } t        |       dkD  ry	 | j                  d      rt        | d	d d
      }|dk  s|dkD  ry|S | j                  d      rot        |       dk(  rat        | d	d d      }|dk  ry|dz  |dz  }}|dz  |dz  }}t        |   }t        |   }t        |   }t        |t
        z  |z   t
        z  z   |z   S | j                  d      r$t        | dd d      }|dk  s|dkD  ryt        |   }n6| j                  d      r$t        | d	d d
      }|dk  s|dkD  ryt        |   }ny|dk(  rt        S |d	z  }|t        k(  rt        S t        |z   S # t        $ r Y yw xY w)a  
    Return a color number for the description desc.
    'h0'..'h87' -> 0..87 actual color number
    '#000'..'#fff' -> 16..79 color cube colors
    'g0'..'g100' -> 16, 80..87, 79 grays and color cube black/white
    'g#00'..'g#ff' -> 16, 80...87, 79 gray and color cube black/white

    Returns None if desc is invalid.

    >>> _parse_color_88('h142')
    >>> _parse_color_88('h42')
    42
    >>> _parse_color_88('#f00')
    64
    >>> _parse_color_88('g100')
    79
    >>> _parse_color_88('g#80')
    83
    r{   r   rH   r   r   r   Nr   r   r   W   rz   r   r   r   rq   r   )rJ   r   r   _CUBE_88_LOOKUP_16rk   ru   _GRAY_88_LOOKUP_GRAY_88_LOOKUP_101rV   r_   r`   ra   r   r   s          rR   _parse_color_88r     s   ( 4yA~Aay47"T!W,
4y1},??3d12h#CQw#(J??3CINd12h#CQw2XsbysA8SBYqA"1%A"1%A"1%A!m"3a"7=!HH1LL ??4 tABx$Dax4#:"4(D__S!tABx$Dax4#:&t,D19	= !!$$ sH   *E0 E0 3E0 AE0 *E0 4E0 =
E0 
E0 E0 'E0 0	E<;E<c                       e Zd Zy)AttrSpecErrorN__name__
__module____qualname__rd   r]   rR   r   r         r]   r   c                      e Zd ZddZ ed       Z ed       Z ed       Z ed       Z ed       Z	 ed       Z
 ed       Z ed	       Z ed
       Z ed       Z ed       Z ed       Z ed       Z ed       Zd Z ee      Zd Zd Zd Zd Z eee      Zd Zd Z eee      Zd Zd Zd Ze jB                  Z!y)AttrSpecc                     |dvrt        d|z        dt        |dk(  z  z  t        |dk(  z  z  | _        || _        || _        | j                  |kD  r#t        dt        |      t        |      |fz        y)a	  
        fg -- a string containing a comma-separated foreground color
              and settings

              Color values:
              'default' (use the terminal's default foreground),
              'black', 'dark red', 'dark green', 'brown', 'dark blue',
              'dark magenta', 'dark cyan', 'light gray', 'dark gray',
              'light red', 'light green', 'yellow', 'light blue',
              'light magenta', 'light cyan', 'white'

              High-color example values:
              '#009' (0% red, 0% green, 60% red, like HTML colors)
              '#23facc' (RRGGBB hex color code)
              '#fcc' (100% red, 80% green, 80% blue)
              'g40' (40% gray, decimal), 'g#cc' (80% gray, hex),
              '#000', 'g0', 'g#00' (black),
              '#fff', 'g100', 'g#ff' (white)
              'h8' (color number 8), 'h255' (color number 255)

              Setting:
              'bold', 'italics', 'underline', 'blink', 'standout',
              'strikethrough'

              Some terminals use 'bold' for bright colors.  Most terminals
              ignore the 'blink' setting.  If the color is not given then
              'default' will be assumed.

        bg -- a string containing the background color

              Color values:
              'default' (use the terminal's default background),
              'black', 'dark red', 'dark green', 'brown', 'dark blue',
              'dark magenta', 'dark cyan', 'light gray'

              High-color exaples:
              see fg examples above

              An empty string will be treated the same as 'default'.

        colors -- the maximum colors available for the specification

                   Valid values include: 1, 16, 88, 256, and 2**24.  High-color
                   values are only usable with 88, 256, or 2**24 colors.  With
                   1 color only the foreground settings may be used.

        >>> AttrSpec('dark red', 'light gray', 16)
        AttrSpec('dark red', 'light gray')
        >>> AttrSpec('yellow, underline, bold', 'dark blue')
        AttrSpec('yellow,bold,underline', 'dark blue')
        >>> AttrSpec('#ddb', '#004', 256) # closest colors will be found
        AttrSpec('#dda', '#006')
        >>> AttrSpec('#ddb', '#004', 88)
        AttrSpec('#ccc', '#000', colors=88)
        )r   r   r"   r      zinvalid number of colors (%d).r   r"   r   zPforeground/background (%s/%s) require more colors than have been specified (%d).N)r   _HIGH_88_COLOR_HIGH_TRUE_COLOR_value
foreground
backgroundcolorsrepr)selffgbgr   s       rR   __init__zAttrSpec.__init__  s    p 00 @6 IJJ.FbL99<LPVZ_P_<``;; "=b48V,!- . .  r]   c                 .    | j                   t        z  dk7  S Nr   )r   _FG_BASIC_COLORss    rR   <lambda>zAttrSpec.<lambda>       !((_*D*I r]   c                 .    | j                   t        z  dk7  S r   )r   _FG_HIGH_COLORr   s    rR   r   zAttrSpec.<lambda>!      N)Ba)G r]   c                 .    | j                   t        z  dk7  S r   )r   _FG_TRUE_COLORr   s    rR   r   zAttrSpec.<lambda>"  r   r]   c                 (    | j                   t        z  S N)r   _FG_COLOR_MASKr   s    rR   r   zAttrSpec.<lambda>#  s    188n+D r]   c                 .    | j                   t        z  dk7  S r   )r   _BG_BASIC_COLORr   s    rR   r   zAttrSpec.<lambda>$  r   r]   c                 .    | j                   t        z  dk7  S r   )r   _BG_HIGH_COLORr   s    rR   r   zAttrSpec.<lambda>%  r   r]   c                 .    | j                   t        z  dk7  S r   )r   _BG_TRUE_COLORr   s    rR   r   zAttrSpec.<lambda>&  r   r]   c                 6    | j                   t        z  t        z	  S r   )r   _BG_COLOR_MASK	_BG_SHIFTr   s    rR   r   zAttrSpec.<lambda>'  s    AHH~,E, r]   c                 .    | j                   t        z  dk7  S r   )r   _ITALICSr   s    rR   r   zAttrSpec.<lambda>)  s    H!4!9 r]   c                 .    | j                   t        z  dk7  S r   )r   _BOLDr   s    rR   r   zAttrSpec.<lambda>*  s    ahh.!3 r]   c                 .    | j                   t        z  dk7  S r   )r   
_UNDERLINEr   s    rR   r   zAttrSpec.<lambda>+  s    188j#8A#= r]   c                 .    | j                   t        z  dk7  S r   )r   _BLINKr   s    rR   r   zAttrSpec.<lambda>,  s    qxx&0A5 r]   c                 .    | j                   t        z  dk7  S r   )r   	_STANDOUTr   s    rR   r   zAttrSpec.<lambda>-  s    !((Y"6!"; r]   c                 .    | j                   t        z  dk7  S r   )r   _STRIKETHROUGHr   s    rR   r   zAttrSpec.<lambda>.  s    qxx.'@A'E r]   c                     | j                   t        z  ry| j                   t        t        z  z  ry| j                   t        t
        z  z  ry| j                   t        t        z  z  ryy)zh
        Return the maximum colors required for this object.

        Returns 256, 88, 16 or 1.
        r"   r   r   r   r   )r   r   r   r   r   r   r   r   s    rR   _colorszAttrSpec._colors0  sR     ;;';;.>9:;;.>9:;;/O;<r]   c                     | j                   d| j                  }| j                  dk(  r|dz   }| j                  j                  d|dS )z\
        Return an executable python representation of the AttrSpec
        object.
        z, r"   z, colors=88())r   r   r   	__class__r   )r   argss     rR   __repr__zAttrSpec.__repr__A  sA    
  ??DOO<;;"-'D>>22D99r]   c                 D   | j                   s| j                  s| j                  sy| j                   rt        | j                     S | j
                  dk(  rt        | j                        S | j
                  dk(  rt        | j                        S t        | j                        S )z2Return only the color component of the foreground.r<   r"   r   )	foreground_basicforeground_highforeground_true_BASIC_COLORSforeground_numberr   rx   rf   rs   r   s    rR   _foreground_colorzAttrSpec._foreground_colorL  s    %%)=)=AUAU   !7!788;;"!$"8"899;;%#D$:$:;;t5566r]   c                     | j                         d| j                  z  z   d| j                  z  z   d| j                  z  z   d| j                  z  z   d| j
                  z  z   d| j                  z  z   S )Nz,boldz,italicsz	,standoutz,blinkz
,underlinez,strikethrough)r   rA   rB   rE   rD   rC   rF   r   s    rR   _foregroundzAttrSpec._foregroundX  s    &&(dii ",t||";<$--'(*2TZZ*?@ 4>>)* -=t?Q?Q,QR 	Sr]   c           	         d }d}|j                  d      D ]9  }|j                         }|t        v r=|t        |   z  r$t        dt	        |      dt	        |      d      |t        |   z  }Y|dv rd}n|t
        v rt
        j                  |      }|t        z  }nq| j                  t        z  rt        |      }|t        z  }nI| j                  t        z  rt        |      }|t        z  }n!t        t!        |      xs |      }|t        z  }|$t        dt	        |      dt	        |      d      |t        d	t	        |      d      |}< |d}| j                  t"         z  |z  |z  | _        y )
Nr   ,zSetting z( specified more thanonce in foreground (r   r   r<   z!Unrecognised color specification z in foreground (z*More than one color given for foreground ()splitstrip_ATTRIBUTESr   r   r   indexr   r   r   r   r   r   r   r   r~   r   _FG_MASK)r   r   colorflagspartscolors         rR   _set_foregroundzAttrSpec._set_foreground^  s   $$S)  	D::<D{";t,,'6:4jZ()* + + T**&&&,,T2(~-(.'//*40'),t*<*DE'~#-1$Zj9I%K L L #*.z*:%= > >EA 	B =E{{hY.%7%?r]   c                 L   | j                   s| j                  s| j                  sy| j                   rt        | j                     S | j
                  t        z  rt        | j                        S | j                  dk(  rt        | j                        S t        | j                        S )zReturn the background color.r<   r   )background_basicbackground_highbackground_truer   background_numberr   r   rx   r   rf   rs   r   s    rR   _backgroundzAttrSpec._background  s    %%)=)=AUAU   !7!788;;'!$"8"899;;%#D$:$:;;t5566r]   c                    d}|dv rd}n|t         v rt         j                  |      }|t        z  }nq| j                  t        z  rt        |      }|t        z  }nI| j                  t        z  rt        |      }|t        z  }n!t        t        |      xs |      }|t        z  }|t        dt        |      d      | j                  t         z  |t        z  z  |z  | _        y )Nr   r   z0Unrecognised color specification in background (r   )r   r   r   r   r   r   r   r   r   r   r~   r   r   r   _BG_MASKr   )r   r   r   r   s       rR   _set_backgroundzAttrSpec._set_background  s    (E=(!''
3E_$E[[>)#J/E^#E[[++%j1E^#E$\*%=%KLE^#E=)-j)9!< = ={{hY.5I3EFNr]   c           
      ,   | j                   s| j                  s| j                  sd}n| j                  dk(  r*| j                  dk  sJ d       t
        | j                     }na| j                  dk(  r?d| j                  z  }t        |dd |dd |dd	 fD cg c]  }t        |d
       c}      }nt        | j                     }| j                  s| j                  s| j                  s|dz   S | j                  dk(  r,| j                  dk  sJ d       |t
        | j                     z   S | j                  dk(  rAd| j                  z  }|t        |dd |dd |dd	 fD cg c]  }t        |d
       c}      z   S |t        | j                     z   S c c}w c c}w )a.  
        Return (fg_red, fg_green, fg_blue, bg_red, bg_green, bg_blue) color
        components.  Each component is in the range 0-255.  Values are taken
        from the XTerm defaults and may not exactly match the user's terminal.

        If the foreground or background is 'default' then all their compenents
        will be returned as None.

        >>> AttrSpec('yellow', '#ccf', colors=88).get_rgb_values()
        (255, 255, 0, 205, 205, 255)
        >>> AttrSpec('default', 'g92').get_rgb_values()
        (None, None, None, 238, 238, 238)
        NNNr"   zInvalid AttrSpec _valuer   z%06xr   rH   r   r   r   )r   r   r   r   r   _COLOR_VALUES_88tupler   r   r   r   r   r   )r   valsr   r   s       rR   get_rgb_valueszAttrSpec.get_rgb_values  s    %%)=)=AUAU%D[[B))B.I0II.#D$:$:;D[[E!//0Aq1vq1vq1v.FG#a*GHD$T%;%;<D%%)=)=AUAU,,,[[B))B.I0II.*4+A+ABBB[[E!//0A%a!fa!fa!f5M NQ NOOO+D,B,BCCC H !Os   FF
c                 X    t        |t              xr | j                  |j                  k(  S r   )
isinstancer   r   r   others     rR   __eq__zAttrSpec.__eq__  s!    %*Jt{{ell/JJr]   c                     | |k(   S r   rd   r	  s     rR   __ne__zAttrSpec.__ne__  s    5=  r]   N)r   )"r   r   r   r   propertyr   r   r   r   r   r   r   r   rB   rA   rC   rD   rE   rF   r   r   r   r   r   r   r   r   r   r   r  r  r  object__hash__rd   r]   rR   r   r     s   @.D   IJGHOGHO !DE IJGHOGHO  " 9:G34D=>I56E;<HEFM gF	:
7S'@R +7J
7O* +7J"DHK! Hr]   r   c                   *     e Zd Z fdZ	 	 ddZ xZS )RealTerminalc                 F    t         t        |           d| _        d | _        y NF)superr  r   _signal_keys_set_old_signal_keysr   r   s    rR   r   zRealTerminal.__init__  s     l4)+ % $r]   c                     |t         j                  j                         }t        j                  |      syt        j                  |      }|d   }|t
        j                     |t
        j                     |t
        j                     |t
        j                     |t
        j                     f}	|dk(  rd}|dk(  rd}|dk(  rd}|dk(  rd}|dk(  rd}|||d   t
        j                  <   |||d   t
        j                  <   |||d   t
        j                  <   |||d   t
        j                  <   |||d   t
        j                  <   |||||,t        j                  |t
        j                  |       d| _        |	S )a  
        Read and/or set the tty's signal character settings.
        This function returns the current settings as a tuple.

        Use the string 'undefined' to unmap keys from their signals.
        The value None is used when no change is being made.
        Setting signal keys is done using the integer ascii
        code for the key, eg.  3 for CTRL+C.

        If this function is called after start() has been called
        then the original settings will be restored when stop()
        is called.
        Nr   	undefinedr   T)sysstdinfilenoosisattytermios	tcgetattrVINTRVQUITVSTARTVSTOPVSUSP	tcsetattr	TCSADRAINr  )
r   intrquitstartstopsuspr  tattrsattrskeyss
             rR   tty_signal_keyszRealTerminal.tty_signal_keys  sv    >YY%%'Fyy !!&)aw}}%uW]]';'..!5#7'-- " ;q;qK;q;qtU1Xgmm4tU1Xgmm4eAhw~~6tU1Xgmm4tU1Xgmm4t/!1fg&7&7?$(D!r]   )NNNNNN)r   r   r   r   r1  __classcell__r   s   @rR   r  r    s    %
 ;?%),r]   r  c                       e Zd Zy)ScreenErrorNr   rd   r]   rR   r5  r5    r   r]   r5  c                   j     e Zd ZdZeegZ fdZ ed       Z	d Z
d Zd Zd Zd Zd	 Z	 dd
Z xZS )
BaseScreenzD
    Base class for Screen classes (raw_display.Screen, .. etc)
    c                 F    t         t        |           i | _        d| _        y r  )r  r7  r   _palette_startedr  s    rR   r   zBaseScreen.__init__  s    j')r]   c                     | j                   S r   )r:  r   s    rR   r   zBaseScreen.<lambda>  s
    DMM r]   c                 b    | j                   sd| _          | j                  |i | t        |       S )ay  Set up the screen.  If the screen has already been started, does
        nothing.

        May be used as a context manager, in which case :meth:`stop` will
        automatically be called at the end of the block:

            with screen.start():
                ...

        You shouldn't override this method in a subclass; instead, override
        :meth:`_start`.
        T)r:  _startr   )r   r   kwargss      rR   r+  zBaseScreen.start  s0     }} DMDKK((t$$r]   c                      y r   rd   r   s    rR   r=  zBaseScreen._start0      r]   c                 J    | j                   r| j                          d| _         y r  )r:  _stopr   s    rR   r,  zBaseScreen.stop3  s    ==JJLr]   c                      y r   rd   r   s    rR   rB  zBaseScreen._stop8  r@  r]   c                 `     | j                   |i |5   |       cddd       S # 1 sw Y   yxY w)zStart the screen, call a function, then stop the screen.  Extra
        arguments are passed to `start`.

        Deprecated in favor of calling `start` as a context manager.
        N)r+  )r   fnr   r>  s       rR   run_wrapperzBaseScreen.run_wrapper;  s1     TZZ(( 	4	 	 	s   $-c                    |D ]  }t        |      dv r | j                  |   t        |      dk7  rt        dt        |      z        |\  }}|| j                  vrt        d|z        | j                  |   | j                  |<    y)ac  Register a set of palette entries.

        palette -- a list of (name, like_other_name) or
        (name, foreground, background, mono, foreground_high,
        background_high) tuples

            The (name, like_other_name) format will copy the settings
            from the palette entry like_other_name, which must appear
            before this tuple in the list.

            The mono and foreground/background_high values are
            optional ie. the second tuple format may have 3, 4 or 6
            values.  See register_palette_entry() for a description
            of the tuple values.
        )r   r   r   rH   z"Invalid register_palette entry: %sz palette entry '%s' doesn't existN)rJ   register_palette_entryr5  r   r9  )r   paletteitemname	like_names        rR   register_palettezBaseScreen.register_paletteE  s    "  
	;D4yG#+++T24yA~!"FJ#    "OD)-!"DY"NOO"&--	":DMM$
	;r]   c           
         t        ||d      }t        |      t        k(  rdj                  |      }|t        }t        |t        d      }||}||}t        ||d      }t        ||d      }	d }
 |
|      s |
|      r|}nt        ||d      }t        j                  | t        ||||||	       |||||	f| j                  |<   y)	aj  Register a single palette entry.

        name -- new entry/attribute name

        foreground -- a string containing a comma-separated foreground
        color and settings

            Color values:
            'default' (use the terminal's default foreground),
            'black', 'dark red', 'dark green', 'brown', 'dark blue',
            'dark magenta', 'dark cyan', 'light gray', 'dark gray',
            'light red', 'light green', 'yellow', 'light blue',
            'light magenta', 'light cyan', 'white'

            Settings:
            'bold', 'underline', 'blink', 'standout', 'strikethrough'

            Some terminals use 'bold' for bright colors.  Most terminals
            ignore the 'blink' setting.  If the color is not given then
            'default' will be assumed.

        background -- a string containing the background color

            Background color values:
            'default' (use the terminal's default background),
            'black', 'dark red', 'dark green', 'brown', 'dark blue',
            'dark magenta', 'dark cyan', 'light gray'

        mono -- a comma-separated string containing monochrome terminal
        settings (see "Settings" above.)

            None = no terminal settings (same as 'default')

        foreground_high -- a string containing a comma-separated
        foreground color and settings, standard foreground
        colors (see "Color values" above) or high-colors may
        be used

            High-color example values:
            '#009' (0% red, 0% green, 60% red, like HTML colors)
            '#fcc' (100% red, 80% green, 80% blue)
            'g40' (40% gray, decimal), 'g#cc' (80% gray, hex),
            '#000', 'g0', 'g#00' (black),
            '#fff', 'g100', 'g#ff' (white)
            'h8' (color number 8), 'h255' (color number 255)

            None = use foreground parameter value

        background_high -- a string containing the background color,
        standard background colors (see "Background colors" above)
        or high-colors (see "High-color example values" above)
        may be used

            None = use background parameter value
        r   r   Nr   r   r   c                     | j                  d      syd| v r| j                  dd      d   } t        | dd  d      }|dkD  S )Nr   Fr   r   r   r      )r   r   r   )r   re   s     rR   large_hz2BaseScreen.register_palette_entry.<locals>.large_h  sH    ??3'd{zz#a(+d12h#C8Or]   r"   )	r   typer  r   DEFAULTr   emit_signalUPDATE_PALETTE_ENTRYr9  )r   rK  r   r   monor   r   basichigh_256	high_truerQ  high_88s               rR   rH  z!BaseScreen.register_palette_entryb  s    r Z4: 88D>D<Dgq)"(O"(OO_cB_ouE	
	 ?#w'?GDGD"6 %w)	M$dGXyIdr]   r  )r   r   r   __doc__rU  INPUT_DESCRIPTORS_CHANGEDr   r   r  startedr+  r=  r,  rB  rF  rM  rH  r2  r3  s   @rR   r7  r7    sQ     $%>?G
 12G%$
;< :>\Jr]   r7  c                  ,    dd l } | j                          y r   )doctesttestmod)r_  s    rR   _testra    s    OOr]   __main__)o
__future__r   r   r  r  r   ImportError
urwid.utilr   r   urwidr   urwid.compatr   r	   r
   r   listUNPRINTABLE_TRANS_TABLErU  r\  _BASIC_STARTrk   rl   rW   rY   rX   ru   r_   ra   r`   rV   _CUBE_STEPS_256_GRAY_STEPS_256_CUBE_STEPS_88_GRAY_STEPS_88_BASIC_COLOR_VALUESr   r  rJ   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rS  BLACKDARK_RED
DARK_GREENBROWN	DARK_BLUEDARK_MAGENTA	DARK_CYAN
LIGHT_GRAY	DARK_GRAY	LIGHT_REDLIGHT_GREENYELLOW
LIGHT_BLUELIGHT_MAGENTA
LIGHT_CYANWHITEr   r   rS   _CUBE_256_LOOKUPr   _CUBE_88_LOOKUPr   rm   rn   rv   rw   rI   r   r   r   r   r\   rb   rf   rs   rx   r   r~   r   r   	Exceptionr   r  r   r  r5  MetaSignalsr7  ra  r   )rr   rq   rp   grns   00000rR   <module>r     sz  * 0 	 
	 2  : : C&2+tF2cN/C(DD  . 7   A%3!1$!#k1" 7 *AG 
 )'  1 A	 AY Y Y  ,,bb"b\,-  (&  1 1	 AY Y Y  ++bb"b\+, 
 $ $$
" ""$$$$$$$$	$$ $	$
$$$$_,~=#$&+,.679GHO+n<

		
			

 
	
	!( #( '< &s_'<v'EsK %nc:%qcN&:dV&CSI :IIAi5$/I 9HIAyE3/I 8FG1Yq%.G 8FG1i5#.G  2Y	 (	!R(?@   3Z	 )1c5)AB   2Y	 &i2u&=>   3Z	 'yC'?@  ""!">B<@"BJ
!EN	I 	yv yx26 2j	) 	mJ 3 3V< mJ` Z	G S  		X,+F JIGGsY   L3 L?
<MM
8MM7MM!'M&M+&M0M5(M:3L<;L<