o
    žD®fó2  ã                   @  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	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   úT/home/ubuntu/webapp/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Ú	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   )r2   Ú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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   Únohidden)ÚromanÚsansÚmonozborder:ú[ú]zbg:r   N©r*   zfg:©r)   )r
   Ú_EMPTY_ATTRSr5   Ú_replaceÚ
startswithÚendswithr   )r=   ÚattrsÚpartr   r   r   Ú_parse_style_strm   s\   


rZ   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   r5   rZ   r7   Ú_style_rulesÚclass_names_and_attrs)Úselfrb   rk   Úclass_namesr=   Úclass_names_setrX   r   r   r   Ú__init__ä   s   
zStyle.__init__c                 C  s   | j S re   )rj   ©rl   r   r   r   rb   ö   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 )r4   N)r%   r5   )r   r;   r   r   r   Ú	<genexpr>  s   € z/Style.from_dict.<locals>.key.<locals>.<genexpr>r   )Úsumr5   )rt   r   r   r   Úkey  s   zStyle.from_dict.<locals>.key)ry   N)rt   ru   r   rv   )r   r\   ÚsortedÚitemsÚlist)Úclsrq   rs   ry   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   )Úsetrk   r7   r5   rV   r   Úextendr<   Úaddri   r6   r%   Ú	itertoolsÚcombinationsrZ   Ú_merge_attrs)rl   r=   r"   Úlist_of_attrsrm   ÚnamesÚattrrY   Ú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 re   )Úidrk   rp   r   r   r   Úinvalidation_hash=  ó   
zStyle.invalidation_hashN)rb   rc   r   rd   ©r   rc   )rq   rr   rs   r   r   r   ©r=   r   r"   r   r   r   ©r   r   )r]   r^   r_   r`   ro   Úpropertyrb   Ú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	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   Ú_orK  s
   ÿz_merge_attrs.<locals>._orr!   c                 S  ó   g | ]}|j ‘qS r   rS   ©r   Úar   r   r   Ú
<listcomp>S  ó    z _merge_attrs.<locals>.<listcomp>c                 S  rŸ   r   rR   r    r   r   r   r¢   T  r£   Fc                 S  rŸ   r   r?   r    r   r   r   r¢   U  r£   c                 S  rŸ   r   rC   r    r   r   r   r¢   V  r£   c                 S  rŸ   r   rE   r    r   r   r   r¢   W  r£   c                 S  rŸ   r   rA   r    r   r   r   r¢   X  r£   c                 S  rŸ   r   rG   r    r   r   r   r¢   Y  r£   c                 S  rŸ   r   rI   r    r   r   r   r¢   Z  r£   c                 S  rŸ   r   rK   r    r   r   r   r¢   [  r£   r(   N)rœ   rš   r   rš   )r   )r†   rž   r   r   r   r…   D  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 re   r   ©r   Úsr   r   r   r¢   c  s    z merge_styles.<locals>.<listcomp>)r¦   )r¤   r   r   r   r   _  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   rd   c                 C  s   || _ tdd| _d S )Nr   )Úmaxsize)r¤   r   Ú_style)rl   r¤   r   r   r   ro   w  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 re   )r   rb   r   rp   r   r   Úget  r“   z'_MergedStyle._merged_style.<locals>.getN©r   r   )rª   r«   r’   )rl   r«   r   rp   r   Ú_merged_style{  s   z_MergedStyle._merged_stylerc   c                 C  s    g }| j D ]}| |j¡ q|S re   )r¤   r   rb   )rl   rb   r¨   r   r   r   rb   „  s   
z_MergedStyle.style_rulesr=   r   r"   r   c                 C  s   | j  ||¡S re   )r­   r   )rl   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 re   )r’   r§   r   r   r   rw   ‘  s   € z1_MergedStyle.invalidation_hash.<locals>.<genexpr>)Útupler¤   rp   r   r   r   r’     s   z_MergedStyle.invalidation_hashN)r¤   r¥   r   rd   r¬   r”   r•   r–   )r]   r^   r_   r`   ro   r—   r­   rb   r
   r   r’   r   r   r   r   r¦   g  s    
ÿ)r   r   r   r   )r2   r   r   r3   )r=   r   r   r   )r†   r›   r   r   )r¤   r¥   r   r¦   )%r`   Ú
__future__r   rƒ   ÚreÚenumr   Útypingr   r   Úprompt_toolkit.cacher   Úbaser   r	   r
   r   r   Únamed_colorsr   Ú__all__r{   r#   r   rT   r<   rZ   Úcompilerf   r   ra   r™   r   rš   r…   r   r¦   r   r   r   r   Ú<module>   sB    
0÷


Ds

