
    Xh3                       d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZmZmZ dd	lmZ g d
Z ej*                         D  ci c]%  \  } }| j-                         |j/                  d      ' c}} ZddZ edddddddddd
      ZddZddZ ej:                  d      Z G d de      Zej@                  Z! G d de      Z" e	d      Z#ddZ$ddZ% G d de      Z&yc c}} w )z-
Tool for creating styles from a dictionary.
    )annotationsN)Enum)HashableTypeVar)SimpleCache   )ANSI_COLOR_NAMESANSI_COLOR_NAMES_ALIASESDEFAULT_ATTRSAttrs	BaseStyle)NAMED_COLORS)Styleparse_colorPrioritymerge_styles#c                n   | t         v r| S | t        v r	t        |    S 	 t        | j                            S # t        $ r Y nw xY w| dd dk(  rX| dd }|t         v r|S |t        v r	t        |   S t        |      dk(  r|S t        |      dk(  r |d   dz  |d   dz  z   |d   dz  z   S | dv r| S t        d	|       )
z
    Parse/validate color format.

    Like in Pygments, but also support the ANSI color names.
    (These will map to the colors of the 16 color palette.)
    r   r   r   N         ) defaultzWrong color format )r	   r
   _named_colors_lowercaselowerKeyErrorlen
ValueError)textcols     O/var/www/html/myenv/lib/python3.12/site-packages/prompt_toolkit/styles/style.pyr   r   !   s     '''--&tzz|44  AayC12h ""J,,+C00 X]J X]q6A:A
*SVaZ77 
	 
*4(3
44s   4 	A A 
colorbgcolorbold	underlinestrikeitalicblinkreversehiddendimc                    g }| j                  d      }t        dt        |      dz         D ]3  }|j                  dj	                  |d|       j                                5 |S )z
    Split a single class name at the `.` operator, and build a list of classes.

    E.g. 'a.b.c' becomes ['a', 'a.b', 'a.b.c']
    .r   N)splitranger   appendjoinr   )	classnameresultpartsis       r!   _expand_classnamer7   _   s`     FOOC E1c%j1n% 3chhuRay)//123 M    c                   d| v rt         }nt        }| j                         D ]I  }|dk(  r
|dk(  r|j                  d      }"|dk(  r|j                  d      }:|dk(  r|j                  d      }R|d	k(  r|j                  d      }j|d
k(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      }|dk(  r|j                  d      },|dk(  r|j                  d      }E|dk(  r|j                  d      }^|dk(  r|j                  d      }w|dk(  r|j                  d      }|dv r|j	                  d      r|j	                  d      r|j                  d      r|j	                  d       r |j                  t        |d!d"       #      }|j	                  d$      r |j                  t        |d!d"       %      }/|j                  t        |      %      }L |S )&zd
    Take a style string, e.g.  'bg:red #88ff00 class:title'
    and return a `Attrs` instance.
    	noinheritr%   T)r%   noboldFr(   )r(   noitalicr&   )r&   nounderliner'   )r'   nostriker)   )r)   noblinkr*   )r*   	noreverser+   )r+   nohiddenr,   )r,   nodim)romansansmonozborder:[]zbg:r   N)r$   zfg:)r#   )r   _EMPTY_ATTRSr/   _replace
startswithendswithr   )	style_strattrsparts      r!   _parse_style_strrO   n   s^    i ! 7<;V^NNN-EXNNN.EXNN$N/EZNN%N0E[ NNTN2E]"NNUN3EXNN$N/EZNN%N0E W_NNN.EYNNN/EYNN4N0E[ NN5N1EXNN$N/EZNN%N0EU]NNtN,EW_NNuN-E ..__Y' __S!dmmC&8 __U#NN;tABx+@NAE__U#NNT!"X)>N?ENNT):N;Eo7<r Lr8   z^[a-z0-9.\s_-]*$c                      e Zd ZdZdZdZy)r   a  
    The priority of the rules, when a style is created from a dictionary.

    In a `Style`, rules that are defined later will always override previous
    defined rules, however in a dictionary, the key order was arbitrary before
    Python 3.6. This means that the style could change at random between rules.

    We have two options:

    - `DICT_KEY_ORDER`: This means, iterate through the dictionary, and take
       the key/value pairs in order as they come. This is a good option if you
       have Python >3.6. Rules at the end will override rules at the beginning.
    - `MOST_PRECISE`: keys that are defined with most precision will get higher
      priority. (More precise means: more elements.)
    	KEY_ORDERMOST_PRECISEN)__name__
__module____qualname____doc__DICT_KEY_ORDERrR    r8   r!   r   r      s      !N!Lr8   r   c                  h    e Zd ZdZddZed	d       Zeef	 	 	 	 	 d
d       Z	e
f	 	 	 	 	 ddZddZy)r   a  
    Create a ``Style`` instance from a list of style rules.

    The `style_rules` is supposed to be a list of ('classnames', 'style') tuples.
    The classnames are a whitespace separated string of class names and the
    style string is just like a Pygments style definition, but with a few
    additions: it supports 'reverse' and 'blink'.

    Later rules always override previous rules.

    Usage::

        Style([
            ('title', '#ff0000 bold underline'),
            ('something-else', 'reverse'),
            ('class1 class2', 'reverse'),
        ])

    The ``from_dict`` classmethod is similar, but takes a dictionary as input.
    c                   g }|D ]o  \  }}t         j                  |      sJ t        |             t        |j	                         j                               }t        |      }|j                  ||f       q || _        || _	        y N)
CLASS_NAMES_REmatchrepr	frozensetr   r/   rO   r1   _style_rulesclass_names_and_attrs)selfstyle_rulesra   class_namesrL   class_names_setrM   s          r!   __init__zStyle.__init__   s     " '2 	C"K!''4Gd;6GG4 ((9(9(;(A(A(CDO$Y/E!((/5)AB	C (%:"r8   c                    | j                   S r[   )r`   rb   s    r!   rc   zStyle.style_rules   s       r8   c                    |t         j                  k(  r%dd} | t        |j                         |            S  | t	        |j                                     S )za
        :param style_dict: Style dictionary.
        :param priority: `Priority` value.
        c                H    t        d | d   j                         D              S )Nc              3  P   K   | ]  }t        |j                  d                yw)r.   N)r   r/   ).0r6   s     r!   	<genexpr>z/Style.from_dict.<locals>.key.<locals>.<genexpr>  s     F3qwws|,Fs   $&r   )sumr/   )items    r!   keyzStyle.from_dict.<locals>.key	  s    Fd1gmmoFFFr8   )rp   )ro   ztuple[str, str]returnint)r   rR   sorteditemslist)cls
style_dictpriorityrp   s       r!   	from_dictzStyle.from_dict   sN     x,,,G vj..0c:;;tJ,,./00r8   c           
        |g}t               }| j                  D ]  \  }}|r	|j                  |        |j                         D ]3  }|j	                  d      rg }|dd j                         j                  d      D ]  }	|j                  t        |	              |D ]  }
t               }|j                  t        |
g             t        dt        |      dz         D ];  }t        j                  ||      D ]   }|j                  t        ||
fz                " = | j                  D ]  \  }}||v s|j                  |        |j                  |
        t        |      }|j                  |       6 t        |      S )z9
        Get `Attrs` for the given style string.
        zclass:r   N,r   )setra   r1   r/   rJ   r   extendr7   addr_   r0   r   	itertoolscombinationsrO   _merge_attrs)rb   rL   r   list_of_attrsrd   namesattrrN   new_class_namespnew_namecomboscountc2inline_attrss                  r!   get_attrs_for_style_strzStyle.get_attrs_for_style_str  s    !	 #  55 	+KE4$$T*	+ OO% 	3D x("$ab)//4 AA#**+<Q+?@A !0 .H UFJJy(45!&q#k*:Q*>!? D"+"8"8e"L DB"JJyxk1A'BCDD
 (,'A'A 7t F?)0067  OOH-.$  05$$\2;	3> M**r8   c                ,    t        | j                        S r[   )idra   rh   s    r!   invalidation_hashzStyle.invalidation_hashB  s    $,,--r8   N)rc   list[tuple[str, str]]rq   Nonerq   r   )rw   zdict[str, str]rx   r   rq   r   rL   strr   r   rq   r   rq   r   )rS   rT   rU   rV   rf   propertyrc   classmethoddefault_priorityry   r   r   r   rX   r8   r!   r   r      sw    *;$ ! ! >N1'13;1	1 1$ 0=/+/+',/+	/+b.r8   r   _Tc                   dd}t         |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j
                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c}  |dg| D cg c]  }|j                   c} 
      S 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 )z
    Take a list of :class:`.Attrs` instances and merge them into one.
    Every `Attr` in the list can override the styling of the previous one. So,
    the last one has highest priority.
    c                 4    | ddd   D ]  }||c S  t         )z/Take first not-None value, starting at the end.N)r   )valuesvs     r!   _orz_merge_attrs.<locals>._orP  s+    " 	A}	 r8   r   Fr"   )r   r   rq   r   )r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r   r   as      r!   r   r   I  sL    "87A78B<];!));<9-8Q!&&89eCMBqq{{BC5=m<AHH<=5=m<AHH<=%;M:q177:;E?>1QYY>?5=m<AHH<=76167 7;8B<<:><6s:   EEE2EE$2E)E.2E3E82E= _MergedStylec                F    | D cg c]  }||	 } }t        |       S c c}w )z)
    Merge multiple `Style` objects.
    )r   )stylesss     r!   r   r   e  s+      1A1=a1F1 2s   c                  Z    e Zd ZdZddZed	d       Zed
d       Zef	 	 	 	 	 ddZ	ddZ
y)r   z
    Merge multiple `Style` objects into one.
    This is supposed to ensure consistency: if any of the given styles changes,
    then this style will be updated.
    c                4    || _         t        d      | _        y )Nr   )maxsize)r   r   _style)rb   r   s     r!   rf   z_MergedStyle.__init__}  s    4?4Jr8   c                d     d fd} j                   j                   j                         |      S )z=The `Style` object that has the other styles merged together.c                 .    t         j                        S r[   )r   rc   rh   s   r!   getz'_MergedStyle._merged_style.<locals>.get  s    ))**r8   rq   r   )r   r   r   )rb   r   s   ` r!   _merged_stylez_MergedStyle._merged_style  s(    	+ {{t557==r8   c                b    g }| j                   D ]  }|j                  |j                          |S r[   )r   r}   rc   )rb   rc   r   s      r!   rc   z_MergedStyle.style_rules  s2     	.Aq}}-	.r8   c                :    | j                   j                  ||      S r[   )r   r   )rb   rL   r   s      r!   r   z$_MergedStyle.get_attrs_for_style_str  s     !!99)WMMr8   c                :    t        d | j                  D              S )Nc              3  <   K   | ]  }|j                           y wr[   )r   )rl   r   s     r!   rm   z1_MergedStyle.invalidation_hash.<locals>.<genexpr>  s     @qQ((*@s   )tupler   rh   s    r!   r   z_MergedStyle.invalidation_hash  s    @DKK@@@r8   N)r   list[BaseStyle]rq   r   r   r   r   r   )rS   rT   rU   rV   rf   r   r   rc   r   r   r   rX   r8   r!   r   r   m  sa    K > >   0=NN',N	N
Ar8   )r   r   rq   r   )r3   r   rq   z	list[str])rL   r   rq   r   )r   zlist[Attrs]rq   r   )r   r   rq   r   )'rV   
__future__r   r   reenumr   typingr   r   prompt_toolkit.cacher   baser	   r
   r   r   r   named_colorsr   __all__rt   r   lstripr   r   rH   r7   rO   compiler\   r   rW   r   r   r   r   r   r   )kr   s   00r!   <module>r      s   #  	  $ ,  ' AS@R@R@TU11779ahhsm3U +5` 
	
EP /0"t ". ** p.I p.f T]8 *A9 *A_
 Vs   *C-