
    ^h3                       S r SSKJr  SSKrSSKrSSKJr  SSKJrJ	r	  SSK
Jr  SSKJrJrJrJrJr  SS	KJr  / S
Qr\R*                  " 5        V Vs0 s H%  u  pU R-                  5       UR/                  S5      _M'     snn rSS jr\" SSSSSSSSSSS9
rSS jrSS jr\R:                  " S5      r " S S\5      r\R@                  r! " S S\5      r"\	" S5      r#SS jr$SS jr% " S S\5      r&gs  snn f )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                   U [         ;   a  U $ U [        ;   a	  [        U    $  [        U R                  5          $ ! [         a     Of = fU SS S:X  a_  U SS nU[         ;   a  U$ U[        ;   a	  [        U   $ [        U5      S:X  a  U$ [        U5      S:X  a  US   S-  US   S-  -   US   S-  -   $ OU S;   a  U $ [        S	U < 35      e)
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     U/home/james-whalen/.local/lib/python3.13/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   8 
AA
colorbgcolorbold	underlinestrikeitalicblinkreversehiddendimc                    / nU R                  S5      n[        S[        U5      S-   5       H4  nUR                  SR	                  USU 5      R                  5       5        M6     U$ )zy
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%chhuRay)//12 & M    c                   SU ;   a  [         nO[        nU R                  5        GHS  nUS:X  a  M  US:X  a  UR                  SS9nM#  US:X  a  UR                  SS9nM:  US:X  a  UR                  SS9nMQ  US	:X  a  UR                  SS9nMh  US
:X  a  UR                  SS9nM  US:X  a  UR                  SS9nM  US:X  a  UR                  SS9nM  US:X  a  UR                  SS9nM  US:X  a  UR                  SS9nM  US:X  a  UR                  SS9nM  US:X  a  UR                  SS9nGM
  US:X  a  UR                  SS9nGM"  US:X  a  UR                  SS9nGM:  US:X  a  UR                  SS9nGMR  US:X  a  UR                  SS9nGMj  US:X  a  UR                  SS9nGM  US;   a  GM  UR	                  S5      (       a  GM  UR	                  S5      (       a  UR                  S5      (       a  GM  UR	                  S 5      (       a  UR                  [        US!S" 5      S#9nGM  UR	                  S$5      (       a  UR                  [        US!S" 5      S%9nGM;  UR                  [        U5      S%9nGMV     U$ )&zX
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   sh    i !;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&8 __U##NN;tABx+@NAE__U##NNT!"X)>N?ENNT):N;Eo "r Lr8   z^[a-z0-9.\s_-]*$c                       \ rS rSrSrSrSrSrg)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_PRECISE N)__name__
__module____qualname____firstlineno____doc__DICT_KEY_ORDERrS   __static_attributes__rT   r8   r!   r   r      s      !N!Lr8   r   c                  ~    \ rS rSrSrS
S jr\SS j5       r\\	4     SS jj5       r
\4     SS jjrSS jrSrg	)r      aT  
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                   / nU Hs  u  p4[         R                  U5      (       d   [        U5      5       e[        UR	                  5       R                  5       5      n[        U5      nUR                  XV45        Mu     Xl        X l	        g N)
CLASS_NAMES_REmatchrepr	frozensetr   r/   rO   r1   _style_rulesclass_names_and_attrs)selfstyle_rulesre   class_namesrL   class_names_setrM   s          r!   __init__Style.__init__   s     " '2"K!''44Gd;6GG4 ((9(9(;(A(A(CDO$Y/E!((/)AB '2 (%:"r8   c                    U R                   $ r_   )rd   rf   s    r!   rg   Style.style_rules   s       r8   c                    U[         R                  :X  a#  SS jnU " [        UR                  5       US95      $ U " [	        UR                  5       5      5      $ )zI
:param style_dict: Style dictionary.
:param priority: `Priority` value.
c                H    [        S U S   R                  5        5       5      $ )Nc              3  V   #    U  H  n[        UR                  S 5      5      v   M!     g7f)r.   N)r   r/   ).0r6   s     r!   	<genexpr>/Style.from_dict.<locals>.key.<locals>.<genexpr>  s      Fo3qwws|,,os   ')r   )sumr/   )items    r!   keyStyle.from_dict.<locals>.key	  s    Fd1gmmoFFFr8   )rw   )rv   ztuple[str, str]returnint)r   rS   sorteditemslist)cls
style_dictpriorityrw   s       r!   	from_dictStyle.from_dict   sN     x,,,G vj..0c:;;tJ,,./00r8   c           
     B   U/n[        5       nU R                   H  u  pVU(       a  M  UR                  U5        M!     UR                  5        GHD  nUR	                  S5      (       Ga  / nUSS R                  5       R                  S5       H  n	UR                  [        U	5      5        M     U H  n
[        5       nUR                  [        U
/5      5        [        S[        U5      S-   5       H=  n[        R                  " XL5       H   nUR                  [        X4-   5      5        M"     M?     U R                   H  u  pVX[;   d  M  UR                  U5        M     UR                  U
5        M     GM(  [        U5      nUR                  U5        GMG     [        U5      $ )z)
Get `Attrs` for the given style string.
zclass:r   N,r   )setre   r1   r/   rJ   r   extendr7   addrc   r0   r   	itertoolscombinationsrO   _merge_attrs)rf   rL   r   list_of_attrsrh   namesattrrN   new_class_namespnew_namecomboscountc2inline_attrss                  r!   get_attrs_for_style_strStyle.get_attrs_for_style_str  sc    !	 #  55KE5$$T* 6 OO%D x(("$ab)//4A#**+<Q+?@ 5 !0H UFJJy(45!&q#k*:Q*>!?"+"8"8"LB"JJyk1A'BC #M "@
 (,'A'A ?)006 (B  OOH- !0$  05$$\2; &> M**r8   c                ,    [        U R                  5      $ r_   )idre   rm   s    r!   invalidation_hashStyle.invalidation_hashB  s    $,,--r8   )rd   re   N)rg   list[tuple[str, str]]ry   Nonery   r   )r   zdict[str, str]r   r   ry   r   rL   strr   r   ry   r   ry   r   )rU   rV   rW   rX   rY   rj   propertyrg   classmethoddefault_priorityr   r   r   r   r[   rT   r8   r!   r   r      sw    *;$ ! ! >N1'13;1	1 1$ 0=/+/+',/+	/+b.r8   r   _Tc                (   SS jn[        U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R
                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 U" S/U  Vs/ s H  o"R                  PM     snQ76 S9
$ s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf s  snf )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                 :    U SSS2    H
  nUc  M  Us  $    [         e)z/Take first not-None value, starting at the end.N)r   )valuesvs     r!   _or_merge_attrs.<locals>._orP  s&    "A}  r8   r   Fr"   )r   r   ry   r   )r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   )r   r   as      r!   r   r   I  s`    "87A78B<];]))];<9-8-Q&&-89eCMBMq{{MBC5=m<mHHm<=5=m<mHHm<=%;M:Mq77M:;E?>1YY>?5=m<mHHm<=76167 7;8B<<:><6s:   E"E'E,9E1E6=E;F F#F
F _MergedStylec                N    U  Vs/ s H	  oc  M  UPM     n n[        U 5      $ s  snf )z!
Merge multiple `Style` objects.
)r   )stylesss     r!   r   r   e  s(      1AaF1 2s   ""c                  n    \ rS rSrSrS
S jr\SS j5       r\SS j5       r\	4     SS jjr
SS jrSrg	)r   im  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                ,    Xl         [        SS9U l        g )Nr   )maxsize)r   r   _style)rf   r   s     r!   rj   _MergedStyle.__init__}  s    4?4Jr8   c                h   ^  SU 4S jjnT R                   R                  T R                  5       U5      $ )z=The `Style` object that has the other styles merged together.c                 .   > [        T R                  5      $ r_   )r   rg   rm   s   r!   get'_MergedStyle._merged_style.<locals>.get  s    ))**r8   ry   r   )r   r   r   )rf   r   s   ` r!   _merged_style_MergedStyle._merged_style  s(    	+ {{t557==r8   c                f    / nU R                    H  nUR                  UR                  5        M      U$ r_   )r   r   rg   )rf   rg   r   s      r!   rg   _MergedStyle.style_rules  s-    Aq}}- r8   c                8    U R                   R                  X5      $ r_   )r   r   )rf   rL   r   s      r!   r   $_MergedStyle.get_attrs_for_style_str  s     !!99)MMr8   c                :    [        S U R                   5       5      $ )Nc              3  @   #    U  H  oR                  5       v   M     g 7fr_   )r   )rr   r   s     r!   rs   1_MergedStyle.invalidation_hash.<locals>.<genexpr>  s     @Kq((**Ks   )tupler   rm   s    r!   r   _MergedStyle.invalidation_hash  s    @DKK@@@r8   )r   r   N)r   list[BaseStyle]ry   r   r   r   r   r   )rU   rV   rW   rX   rY   rj   r   r   rg   r   r   r   r[   rT   r8   r!   r   r   m  sa    K > >   0=NN',N	N
Ar8   )r   r   ry   r   )r3   r   ry   z	list[str])rL   r   ry   r   )r   zlist[Attrs]ry   r   )r   r   ry   r   )'rY   
__future__r   r   reenumr   typingr   r   prompt_toolkit.cacher   baser	   r
   r   r   r   named_colorsr   __all__r|   r   lstripr   r   rH   r7   rO   compiler`   r   rZ   r   r   r   r   r   r   )kr   s   00r!   <module>r      s   #  	  $ ,  ' AM@R@R@TU@T1779ahhsm3@TU +5` 
	
EP /0"t ". ** p.I p.f T]8 *A9 *A_
 Vs   ,C1