
    (phK                     8   S r SSKrSSKJrJr  SSKJrJr  \R                  " 5       S:X  a  SSK	r
OSSK
r
S r\" 5       r\" SR                  5       5      r " S S	\5      r " S
 S\5      r " S S\5      r " S S\5      r " S S\5      rS rS rS rS rS rg)z3Sub-module providing sequence-formatting functions.    N)TextType
StringType)
CGA_COLORSX11_COLORNAMES_TO_RGBWindowsc                  2   [        5       n [         HP  nU R                  U5        U R                  SU-   5        U R                  SU-   5        U R                  SU-   5        MR     [         H(  nU R                  U5        U R                  SU-   5        M*     U $ )zd
Return set of valid colors and their derivatives.

:rtype: set
:returns: Color names with prefixes
on_bright_
on_bright_)setr   addr   )colors	cga_color	vga_colors      E/var/www/html/venv/lib/python3.13/site-packages/blessed/formatters.py_make_colorsr      s     UF  	

9

59$%

9y()

<)+,	   +	

9

59$% + M    z,bold underline reverse blink italic standoutc                   (    \ rS rSrSrSS jrS rSrg)ParameterizingString1   a  
A Unicode string which can be called as a parameterizing termcap.

For example::

    >>> from blessed import Terminal
    >>> term = Terminal()
    >>> color = ParameterizingString(term.color, term.normal, 'color')
    >>> color(9)('color #9')
    u'\x1b[91mcolor #9\x1b(B\x1b[m'
c                 J    [         R                  " X5      nX$l        X4l        U$ )z
Class constructor accepting 3 positional arguments.

:arg str cap: parameterized string suitable for curses.tparm()
:arg str normal: terminating sequence for this capability (optional).
:arg str name: name of this terminal capability (optional).
)r   __new___normal_name)clscapnormalnamenews        r   r   ParameterizingString.__new__>   s#     s(	
r   c           	          [         R                  " U R                  S5      /UQ76 R                  S5      n[	        X R
                  5      $ ! [         aF  nU(       a9  [        US   [        5      (       a!  [        SU R                  < SU< SU< 35      ee SnAf[         R                   a$  nS[        U5      ;  a  e [        5       s SnA$ SnAff = f)a  
Returning :class:`FormattingString` instance for given parameters.

Return evaluated terminal capability (self), receiving arguments
``*args``, followed by the terminating sequence (self.normal) into
a :class:`FormattingString` capable of being called.

:raises TypeError: Mismatch between capability and arguments
:raises curses.error: :func:`curses.tparm` raised an exception
:rtype: :class:`FormattingString` or :class:`NullCallableString`
:returns: Callable string for given parameters
latin1r   zUnknown terminal capability, z, or, TypeError for arguments z: Nztparm() returned NULL)cursestparmencodedecodeFormattingStringr   	TypeError
isinstancer   r   errorr   NullCallableString)selfargsattrerrs       r   __call__ParameterizingString.__call__L   s    	( <<H 5==DDXND#D,,77 		 
47J77.2jj$EF F
 || 	( 'hsm;%''	(s+   A	A 
CABC.CCC N z<not specified>__name__
__module____qualname____firstlineno____doc__r   r0   __static_attributes__r2   r   r   r   r   1   s    
#(r   r   c                   (    \ rS rSrSrSS jrS rSrg)ParameterizingProxyStringr   a  
A Unicode string which can be called to proxy missing termcap entries.

This class supports the function :func:`get_proxy_string`, and mirrors
the behavior of :class:`ParameterizingString`, except that instead of
a capability name, receives a format string, and callable to filter the
given positional ``*args`` of :meth:`ParameterizingProxyString.__call__`
into a terminal sequence.

For example::

    >>> from blessed import Terminal
    >>> term = Terminal('screen')
    >>> hpa = ParameterizingString(term.hpa, term.normal, 'hpa')
    >>> hpa(9)
    u''
    >>> fmt = u'\x1b[{0}G'
    >>> fmt_arg = lambda *arg: (arg[0] + 1,)
    >>> hpa = ParameterizingProxyString((fmt, fmt_arg), term.normal, 'hpa')
    >>> hpa(9)
    u'\x1b[10G'
c                     [        U[        5      (       d   U5       e[        US   5      (       d
   US   5       e[        R                  " XS   5      nUS   Ul        X$l        X4l        U$ )az  
Class constructor accepting 4 positional arguments.

:arg tuple fmt_pair: Two element tuple containing:
    - format string suitable for displaying terminal sequences
    - callable suitable for receiving  __call__ arguments for formatting string
:arg str normal: terminating sequence for this capability (optional).
:arg str name: name of this terminal capability (optional).
   r   )r)   tuplecallabler   r   	_fmt_argsr   r   )r   fmt_pairr   r   r   s        r   r   !ParameterizingProxyString.__new__   sh     (E**4H4*$$1hqk1$sQK0 	
r   c                 b    [        U R                  " U R                  " U6 6 U R                  5      $ )ac  
Returning :class:`FormattingString` instance for given parameters.

Arguments are determined by the capability.  For example, ``hpa``
(move_x) receives only a single integer, whereas ``cup`` (move)
receives two integers.  See documentation in terminfo(5) for the
given capability.

:rtype: FormattingString
:returns: Callable string for given parameters
)r'   formatrC   r   r,   r-   s     r   r0   "ParameterizingProxyString.__call__   s,      T^^T-B C $. 	.r   r2   Nr3   r5   r2   r   r   r=   r=   r   s    .&.r   r=   c                   (    \ rS rSrSrSS jrS rSrg)r'      a.  
A Unicode string which doubles as a callable.

This is used for terminal attributes, so that it may be used both
directly, or as a callable.  When used directly, it simply emits
the given terminal sequence.  When used as a callable, it wraps the
given (string) argument with the 2nd argument used by the class
constructor::

    >>> from blessed import Terminal
    >>> term = Terminal()
    >>> style = FormattingString(term.bright_blue, term.normal)
    >>> print(repr(style))
    u'\x1b[94m'
    >>> style('Big Blue')
    u'\x1b[94mBig Blue\x1b(B\x1b[m'
c                 >    [         R                  " X5      nX#l        U$ )z
Class constructor accepting 2 positional arguments.

:arg str sequence: terminal attribute sequence.
:arg str normal: terminating sequence for this attribute (optional).
)r   r   r   )r   sequencer   r   s       r   r   FormattingString.__new__   s     s-
r   c                    [        U5       HV  u  p#[        U[        5      (       a  M  [        SU< SU< S[        R                  < S[        U5      R                  < 35      e   SnU (       af  U R                  (       aU  U R                  nU R                  U -   nU Vs/ s H-  nUR                  UR                  U R                  5      5      PM/     nnU SR                  U5      -   U-   $ s  snf )z
Return ``text`` joined by ``sequence`` and ``normal``.

:raises TypeError: Not a string type
:rtype: str
:returns: Arguments wrapped in sequence and normal
z)TypeError for FormattingString argument, z, at position z: expected type z, got r4   )		enumerater)   r   r(   r6   typer   joinsplit)r,   r-   idxucs_partpostfix_refreshs         r   r0   FormattingString.__call__   s     't_MCh
33$,c:3F3FXH_H_a  - DLLllG||d*H$(*$( MM(..">?$(  * chhtn$w..*s   4C,r2   N)r4   r5   r2   r   r   r'   r'      s    $
/r   r'   c                   *    \ rS rSrSrS rS rS rSrg)FormattingOtherString   a  
A Unicode string which doubles as a callable for another sequence when called.

This is used for the :meth:`~.Terminal.move_up`, ``down``, ``left``, and ``right()``
family of functions::

    >>> from blessed import Terminal
    >>> term = Terminal()
    >>> move_right = FormattingOtherString(term.cuf1, term.cuf)
    >>> print(repr(move_right))
    u'\x1b[C'
    >>> print(repr(move_right(666)))
    u'\x1b[666C'
    >>> print(repr(move_right()))
    u'\x1b[C'
c                 >    [         R                  " X5      nX#l        U$ )z
Class constructor accepting 2 positional arguments.

:arg str direct: capability name for direct formatting, eg ``('x' + term.right)``.
:arg str target: capability name for callable, eg ``('x' + term.right(99))``.
r   r   	_callable)r   directtargetr   s       r   r   FormattingOtherString.__new__   s     s+
r   c                 P    [         R                  " [         U 5      U R                  4$ Nr]   )r,   s    r   __getnewargs__$FormattingOtherString.__getnewargs__  s    $/??r   c                 2    U(       a  U R                   " U6 $ U $ )zReturn ``text`` by ``target``.)r^   rH   s     r   r0   FormattingOtherString.__call__  s    (,t~~t$6$6r   r2   N)	r6   r7   r8   r9   r:   r   rd   r0   r;   r2   r   r   rZ   rZ      s    "
@7r   rZ   c                   $    \ rS rSrSrS rS rSrg)r+   i  z
A dummy callable Unicode alternative to :class:`FormattingString`.

This is used for colors on terminals that do not support colors, it is just a basic form of
unicode that may also act as a callable.
c                 0    [         R                  " U S5      $ )zClass constructor.r4   )r   r   )r   s    r   r   NullCallableString.__new__  s    S))r   c                 v    U(       a  [        US   [        5      (       a
  [        5       $ SR                  U5      $ )a  
Allow empty string to be callable, returning given string, if any.

When called with an int as the first arg, return an empty Unicode. An int is a good hint
that I am a :class:`ParameterizingString`, as there are only about half a dozen string-
returning capabilities listed in terminfo(5) which accept non-int arguments, they are seldom
used.

When called with a non-int as the first arg (no no args at all), return the first arg,
acting in place of :class:`FormattingString` without any attributes.
r   r4   )r)   intr+   rR   rH   s     r   r0   NullCallableString.__call__  s0     z$q'3// &''xx~r   r2   Nr5   r2   r   r   r+   r+     s    *r   r+   c           	        ^  [        [        U 4S jS 5       5      T 5      n[        SS 4T R                  U5      [        SS 4T R                  U5      S.[        SS	 4T R                  U5      [        S
S 4T R                  U5      [        SS 4T R                  U5      [        SS 4T R                  U5      SSS.S.nUR	                  U0 5      R	                  US5      $ )a  
Proxy and return callable string for proxied attributes.

:arg Terminal term: :class:`~.Terminal` instance.
:arg str attr: terminal capability name that may be proxied.
:rtype: None or :class:`ParameterizingProxyString`.
:returns: :class:`ParameterizingProxyString` for some attributes
    of some terminal types that support it, where the terminfo(5)
    database would otherwise come up empty, such as ``move_x``
    attribute for ``term.kind`` of ``screen``.  Otherwise, None.
c              3   l   >#    U  H)  nTR                   R                  U5      (       d  M%  Uv   M+     g 7frc   )kind
startswith).0_kindterms     r   	<genexpr>#get_proxy_string.<locals>.<genexpr>B  s,      :-@E!YY11%8  %-@s   $4	4)screenansiz[{0}Gc                      U S   S-   4$ Nr   r@   r2   args    r   <lambda>"get_proxy_string.<locals>.<lambda>H      SVaZMr   z[{0}dc                      U S   S-   4$ rz   r2   r{   s    r   r}   r~   J  r   r   )hpavpaz[?25lc                      gNr2   r2   r{   s    r   r}   r~   P      Br   z[?25hc                      gr   r2   r{   s    r   r}   r~   R  r   r   c                      U S   S-   4$ rz   r2   r{   s    r   r}   r~   T  r   r   c                      U S   S-   4$ rz   r2   r{   s    r   r}   r~   V  r   r   z[sz[u)civiscnormr   r   scrcN)nextiterr=   r   get)rt   r.   	term_kind_proxy_tables   `   r   get_proxy_stringr   5  s     T :-@ : :;?AI
 -9:DKKO,9:DKKO	
 //dD./dD,9:DKKO,9:DKKO
L. Ir*..tT::r   c                     / n/ SQnU R                  S5       H6  nU(       a  US   U;   a  US==   SU-   -  ss'   M%  UR                  U5        M8     U$ )a.  
Split compound formating string into segments.

>>> split_compound('bold_underline_bright_blue_on_red')
['bold', 'underline', 'bright_blue', 'on_red']

:arg str compound: a string that may contain compounds, separated by
    underline (``_``).
:rtype: list
:returns: List of formating string segments
)onbright	on_bright_)rS   append)compoundmerged_segsmergeable_prefixessegments       r   split_compoundr   ^  sY     K6>>#&;r?.@@OsW},Ow'	 '
 r   c                     U R                   (       d  g[        R                  " U R                  R	                  X5      5      nUc  S$ UR                  S5      $ )aK  
Resolve a raw terminal capability using :func:`tigetstr`.

:arg Terminal term: :class:`~.Terminal` instance.
:arg str attr: terminal capability name.
:returns: string of the given terminal capability named by ``attr``,
   which may be empty (u'') if not found or not supported by the
   given :attr:`~.Terminal.kind`.
:rtype: str
r4   r"   )does_stylingr#   tigetstr_sugarr   r&   )rt   r.   vals      r   resolve_capabilityr   u  sE     
//$++//$5
6C +373::h#77r   c                    U R                   S:X  a
  [        5       $ SU;   a  U R                  OU R                  nUR	                  SS5      S   nU[
        ;   aa  SU;   a  SOSnUR	                  SS5      S   nSUR                  5       < 3nU" [        [        U5      U-   5      n[        X`R                  5      $ U[        ;   d	   S	U45       e[        U   nU R                   S
::  a*  U" U R                  " U6 5      n[        X`R                  5      $ SU;   a  SOSnU R                   S:X  d   eSU-   S-   n[        UR                  " U6 U R                  5      $ )aE  
Resolve a simple color name to a callable capability.

This function supports :func:`resolve_attribute`.

:arg Terminal term: :class:`~.Terminal` instance.
:arg str color: any string found in set :const:`COLORS`.
:returns: a string class instance which emits the terminal sequence
    for the given color, and may be used as a callable to wrap the
    given string with such sequence.
:returns: :class:`NullCallableString` when
    :attr:`~.Terminal.number_of_colors` is 0,
    otherwise :class:`FormattingString`.
:rtype: :class:`NullCallableString` or :class:`FormattingString`
r   r	   r   r@   r   r
      COLOR_zcolor not known   4838i   z[z;2;{0};{1};{2}m)number_of_colorsr+   _background_color_foreground_colorrsplitr   uppergetattrr#   r'   r   r   rgb_downconvertrG   )	rt   colorvga_color_cap
base_coloroffsetr.   fmt_attrrgbfgbg_seqs	            r   resolve_colorr     s_   " !!## 05~T++++  c1%b)JZ  5(a\\#q)"-
'--/1 !6!?@++66.. ':1' '.


+C # !5!5s!;<++66 DH  G+++("%66HHOOS14;;??r   c                   ^  U[         ;   a  [        T U5      $ U[        ;   a"  [        T U5      n[	        UT R
                  5      $ [        U5      n[        S U 5       5      (       a1  U 4S jU 5       n[	        SR                  U5      T R
                  5      $ [        T U5      nU(       d*  [        T T R                  R                  X5      5      nUb  U$ [        UT R
                  U5      $ )a|  
Resolve a terminal attribute name into a capability class.

:arg Terminal term: :class:`~.Terminal` instance.
:arg str attr: Sugary, ordinary, or compound formatted terminal
    capability, such as "red_on_white", "normal", "red", or
    "bold_on_black".
:returns: a string class instance which emits the terminal sequence
    for the given terminal capability, or may be used as a callable to
    wrap the given string with such sequence.
:returns: :class:`NullCallableString` when
    :attr:`~.Terminal.number_of_colors` is 0,
    otherwise :class:`FormattingString`.
:rtype: :class:`NullCallableString` or :class:`FormattingString`
c              3   R   #    U  H  o[         ;   =(       d	    U[        ;   v   M     g 7frc   )COLORSCOMPOUNDABLES)rr   fmts     r   ru   $resolve_attribute.<locals>.<genexpr>  s     
Ijs6M1SM11js   %'c              3   <   >#    U  H  n[        TU5      v   M     g 7frc   )resolve_attribute)rr   r   rt   s     r   ru   r     s     Ijs'c22js   r4   )r   r   r   r   r'   r   r   allrR   r   r   r   r   )rt   r.   rM   
formatters
resolutiontparm_capseqproxys   `      r   r   r     s      v~T4(( }%dD1$++66
  %J

Ij
IIIIjI
 4dkkBB &dD1L !!%!<>Ldkk4@@r   )r:   platformblessed._compatr   r   blessed.colorspacer   r   systemjinxedr#   r   r   r   rS   r   r   r=   r'   rZ   r+   r   r   r   r   r   r2   r   r   <module>r      s    9  1 @ ??	!2 
 BHHJK>(8 >(B8. 8.v9/x 9/x$7H $7N" "J&;R.8&2@j.Ar   