o
    ÄCâhÏ3  ã                   @  s$  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dd„ e ¡ D ƒZd+dd„Zeddddddddddd
Zd,dd„Zd-dd„Ze d¡ZG dd„ deƒZejZG dd„ deƒZ e	d ƒZ!d.d#d$„Z"d/d(d)„Z#G d*d'„ d'eƒZ$dS )0z-
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_stylesc                 C  s    i | ]\}}|  ¡ | d ¡“qS )ú#)ÚlowerÚlstrip)Ú.0ÚkÚv© r   úm/var/www/html/myvaluetrips/my_value_trip_new/venv/lib/python3.10/site-packages/prompt_toolkit/styles/style.pyÚ
<dictcomp>   s     r   ÚtextÚstrÚreturnc                 C  sÒ   | t v r| S | tv rt|  S zt|  ¡  W S  ty   Y nw | dd… dkr\| dd… }|t v r3|S |tv r;t| S t|ƒdkrC|S t|ƒdkr[|d d |d d  |d d  S n| dv rb| 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_lowercaser   ÚKeyErrorÚlenÚ
ValueError)r   Úcolr   r   r   r   !   s.   ÿ$ÿr   ©
ÚcolorÚbgcolorÚboldÚ	underlineÚstrikeÚitalicÚblinkÚreverseÚhiddenÚdimÚ	classnameú	list[str]c                 C  sF   g }|   d¡}tdt|ƒd ƒD ]}| d |d|… ¡ ¡ ¡ q|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   )r3   ÚresultÚpartsÚir   r   r   Ú_expand_classname_   s
   
r=   Ú	style_strr   c                 C  s  d| v rt }nt}|  ¡ D ]ù}|dkrq|dkr|jdd}q|dkr*|jdd}q|dkr5|jdd}q|d	kr@|jdd}q|d
krK|jdd}q|dkrV|jdd}q|dkra|jdd}q|dkrl|jdd}q|dkrw|jdd}q|dkr‚|jdd}q|dkr|jdd}q|dkr˜|jdd}q|dkr£|jdd}q|dkr®|jdd}q|dkr¹|jdd}q|dkrÄ|jdd}q|dv rÉq| d¡rÏq| d¡rÚ| d¡rÚq| d ¡rì|jt|d!d"… ƒd#}q| d$¡rþ|jt|d!d"… ƒd%}q|jt|ƒd%}q|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/   Únoblinkr0   ©r0   Ú	noreverser1   ©r1   Únohiddenr2   ©r2   Únodim)ÚromanÚsansÚmonozborder:ú[ú]zbg:r   N©r*   zfg:©r)   )r
   Ú_EMPTY_ATTRSr6   Ú_replaceÚ
startswithÚendswithr   )r>   ÚattrsÚpartr   r   r   Ú_parse_style_strn   sd   


r]   z^[a-z0-9.\s_-]*$c                   @  s   e Zd ZdZdZdZdS )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_ORDERr_   r   r   r   r   r   ¹   s    r   c                   @  sR   e Zd ZdZddd„Zeddd	„ƒZeefddd„ƒZ	e
fddd„Zddd„ZdS )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.
    Ústyle_rulesúlist[tuple[str, str]]r   ÚNonec                 C  s^   g }|D ]"\}}t  |¡sJ t|ƒƒ‚t| ¡  ¡ ƒ}t|ƒ}| ||f¡ q|| _|| _	d S ©N)
ÚCLASS_NAMES_REÚmatchÚreprÚ	frozensetr   r6   r]   r8   Ú_style_rulesÚclass_names_and_attrs)Úselfre   rn   Úclass_namesr>   Úclass_names_setr[   r   r   r   Ú__init__é   s   
zStyle.__init__c                 C  s   | j S rh   )rm   ©ro   r   r   r   re   û   s   zStyle.style_rulesÚ
style_dictúdict[str, str]Úpriorityr   c                 C  s8   |t jkrd	dd„}| t| ¡ |dƒS | t| ¡ ƒƒS )
za
        :param style_dict: Style dictionary.
        :param priority: `Priority` value.
        Úitemútuple[str, str]r   Úintc                 S  s   t dd„ | d  ¡ D ƒƒS )Nc                 s  s    | ]
}t | d ¡ƒV  qdS )r5   N)r%   r6   )r   r<   r   r   r   Ú	<genexpr>  s   € z/Style.from_dict.<locals>.key.<locals>.<genexpr>r   )Úsumr6   )rw   r   r   r   Úkey	  s   zStyle.from_dict.<locals>.key)r|   N)rw   rx   r   ry   )r   r_   ÚsortedÚitemsÚlist)Úclsrt   rv   r|   r   r   r   Ú	from_dictÿ   s   

zStyle.from_dictr>   r   r"   r   c              	   C  s  |g}t ƒ }| jD ]\}}|s| |¡ q	| ¡ D ]m}| d¡r}g }|dd…  ¡  d¡D ]	}	| t|	ƒ¡ q-|D ]B}
t ƒ }| t	|
gƒ¡ t
dt|ƒd ƒD ]}t ||¡D ]}| t	||
f ƒ¡ qWqO| jD ]\}}||v ru| |¡ qh| |
¡ q9qt|ƒ}| |¡ qt|ƒS )z9
        Get `Attrs` for the given style string.
        zclass:r   Nú,r   )Úsetrn   r8   r6   rY   r   Úextendr=   Úaddrl   r7   r%   Ú	itertoolsÚcombinationsr]   Ú_merge_attrs)ro   r>   r"   Úlist_of_attrsrp   ÚnamesÚattrr\   Únew_class_namesÚpÚnew_nameÚcombosÚcountÚc2Úinline_attrsr   r   r   Úget_attrs_for_style_str  s6   
€
ÿ
€òzStyle.get_attrs_for_style_strr   c                 C  s
   t | jƒS rh   )Úidrn   rs   r   r   r   Úinvalidation_hashB  ó   
zStyle.invalidation_hashN)re   rf   r   rg   ©r   rf   )rt   ru   rv   r   r   r   ©r>   r   r"   r   r   r   ©r   r   )r`   ra   rb   rc   rr   Úpropertyre   ÚclassmethodÚdefault_priorityr   r
   r“   r•   r   r   r   r   r   Ó   s    
ÿÿ1r   Ú_Tr‰   úlist[Attrs]c                 C  s  ddd„}t |dgdd„ | D ƒ¢R Ž |dgd	d„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž |d
gdd„ | D ƒ¢R Ž d
S )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.
    Úvaluesr   r   c                  W  s(   | ddd… D ]
}|dur|  S qt ‚)z/Take first not-None value, starting at the end.Néÿÿÿÿ)r&   )rŸ   r   r   r   r   Ú_orP  s
   ÿz_merge_attrs.<locals>._orr!   c                 S  ó   g | ]}|j ‘qS r   rV   ©r   Úar   r   r   Ú
<listcomp>X  ó    z _merge_attrs.<locals>.<listcomp>c                 S  r¢   r   rU   r£   r   r   r   r¥   Y  r¦   Fc                 S  r¢   r   r@   r£   r   r   r   r¥   Z  r¦   c                 S  r¢   r   rD   r£   r   r   r   r¥   [  r¦   c                 S  r¢   r   rF   r£   r   r   r   r¥   \  r¦   c                 S  r¢   r   rB   r£   r   r   r   r¥   ]  r¦   c                 S  r¢   r   rH   r£   r   r   r   r¥   ^  r¦   c                 S  r¢   r   rJ   r£   r   r   r   r¥   _  r¦   c                 S  r¢   r   rL   r£   r   r   r   r¥   `  r¦   c                 S  r¢   r   rN   r£   r   r   r   r¥   a  r¦   r(   N)rŸ   r   r   r   )r   )r‰   r¡   r   r   r   rˆ   I  s   
örˆ   Ústylesúlist[BaseStyle]Ú_MergedStylec                 C  s   dd„ | D ƒ} t | ƒS )z)
    Merge multiple `Style` objects.
    c                 S  s   g | ]}|d ur|‘qS rh   r   ©r   Úsr   r   r   r¥   i  s    z merge_styles.<locals>.<listcomp>)r©   )r§   r   r   r   r   e  s   r   c                   @  sN   e Zd ZdZddd„Zedd	d
„ƒZeddd„ƒZefddd„Z	ddd„Z
dS )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.
    r§   r¨   r   rg   c                 C  s   || _ tdd| _d S )Nr   )Úmaxsize)r§   r   Ú_style)ro   r§   r   r   r   rr   }  s   z_MergedStyle.__init__r   c                   s    d‡ fdd„}ˆ j  ˆ  ¡ |¡S )z=The `Style` object that has the other styles merged together.r   r   c                     s
   t ˆ jƒS rh   )r   re   r   rs   r   r   Úget…  r–   z'_MergedStyle._merged_style.<locals>.getN©r   r   )r­   r®   r•   )ro   r®   r   rs   r   Ú_merged_style  s   z_MergedStyle._merged_stylerf   c                 C  s    g }| j D ]}| |j¡ q|S rh   )r§   r„   re   )ro   re   r«   r   r   r   re   Š  s   
z_MergedStyle.style_rulesr>   r   r"   r   c                 C  s   | j  ||¡S rh   )r°   r“   )ro   r>   r"   r   r   r   r“   ‘  s   z$_MergedStyle.get_attrs_for_style_strr   c                 C  s   t dd„ | jD ƒƒS )Nc                 s  s    | ]}|  ¡ V  qd S rh   )r•   rª   r   r   r   rz   —  s   € z1_MergedStyle.invalidation_hash.<locals>.<genexpr>)Útupler§   rs   r   r   r   r•   –  s   z_MergedStyle.invalidation_hashN)r§   r¨   r   rg   r¯   r—   r˜   r™   )r`   ra   rb   rc   rr   rš   r°   re   r
   r“   r•   r   r   r   r   r©   m  s    
ÿ)r   r   r   r   )r3   r   r   r4   )r>   r   r   r   )r‰   rž   r   r   )r§   r¨   r   r©   )%rc   Ú
__future__r   r†   ÚreÚenumr   Útypingr   r   Úprompt_toolkit.cacher   Úbaser   r	   r
   r   r   Únamed_colorsr   Ú__all__r~   r#   r   rW   r=   r]   Úcompileri   r   rd   rœ   r   r   rˆ   r   r©   r   r   r   r   Ú<module>   sD    
0ö


Hs

