
    (                         S r  SSKJr  SSKJrJrJr  SSK	J
r
  SSKJrJr  SSKJr  SrS	 rSS
 jr " S S\5      rg! \ a	    SSKJr   NBf = f)z
Tool for creating styles from a dictionary.

This is very similar to the Pygments style dictionary, with some additions:
- Support for reverse and blink.
- Support for ANSI color names. (These will map directly to the 16 terminal
  colors.)
    )Mapping   )StyleDEFAULT_ATTRSANSI_COLOR_NAMES)DEFAULT_STYLE_EXTENSIONS)merge_attrssplit_token_in_parts)range)style_from_dictc                     U SS S:X  aL  U SS n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:X  a  U $ [        S	U -  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   #N          zWrong color format %r)r   len
ValueError)textcols     2lib/third_party/prompt_toolkit/styles/from_dict.py_colorformatr      s     AayC12h""JX]JX]q6!8c!fQh&Q11 	
,t3
44    c           	      p   [        U [        5      (       d   eU(       a*  0 nUR                  [        5        UR                  U 5        Un 0 n[	        U R                  5       5       GH  u  pE[        nSU;  a(  [        S[        U5      S-   5       H  n X4SU*     n  O   UR                  5        GH_  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;   a  M  UR                  S5      (       a  GM  UR                  S5      (       a  UR                  [        USS 5      S9nGMG  UR                  [        U5      S9nGMb     XcU'   GM     [        U5      $ ! [         a     GM  f = f)a  
Create a ``Style`` instance from a dictionary or other mapping.

The dictionary is equivalent to the ``Style.styles`` dictionary from
pygments, with a few additions: it supports 'reverse' and 'blink'.

Usage::

    style_from_dict({
        Token: '#ff0000 bold underline',
        Token.Title: 'blink',
        Token.SomethingElse: 'reverse',
    })

:param include_defaults: Include the defaults (built-in) styling for
    selected text, etc...)
	noinheritr   NboldT)r   noboldFitalic)r   noitalic	underline)r    nounderlineblink)r"   noblinkreverse)r$   	noreverse)romansansmonozborder:zbg:r   )bgcolor)color)
isinstancer   updater   sorteditemsr   r   r   KeyErrorsplit_replace
startswithr   _StyleFromDict)	
style_dictinclude_defaultss2token_to_attrsttypestyledefattrsiparts	            r   r   r   -   s?   $ j'****
		*+
		*
 N "*"2"2"45h&1c%j1n-*1":6E  . NN$D{"D1!E2!d3#e4$6&7 T2"U3"t4$u5 22++ ''|DH/EF\$-?@K %N !&uk 6n .))_   s   H&&
H54H5c                   *    \ rS rSrSrS rS rS rSrg)r3      z
Turn a dictionary that maps `Token` to `Attrs` into a style class.

:param token_to_attrs: Dictionary that maps `Token` to `Attrs`.
c                     Xl         g Nr7   )selfr7   s     r   __init___StyleFromDict.__init__   s    ,r   c                     / n[        U5       H2  nUR                  U R                  R                  U[        5      5        M4     [        U5      $ r@   )r
   appendr7   getr   r	   )rB   tokenlist_of_attrss      r   get_attrs_for_token"_StyleFromDict.get_attrs_for_token   sB    )%0E  !4!4!8!8!NO 1=))r   c                 ,    [        U R                  5      $ r@   )idr7   )rB   s    r   invalidation_hash _StyleFromDict.invalidation_hash   s    $%%&&r   rA   N)	__name__
__module____qualname____firstlineno____doc__rC   rJ   rN   __static_attributes__ r   r   r3   r3      s    
-*'r   r3   N)T)rT   collections.abcr   ImportErrorcollectionsbaser   r   r   defaultsr   utilsr	   r
   	six.movesr   __all__r   r   r3   rV   r   r   <module>r_      sW   $' 9 8 . 4 
5*V*r'U 'w  $#$s   > AA