
    Mh0                       d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ ddlmZmZmZ d	d
lmZmZ d	dlmZ g dZ G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z  G d de          Z! G d de          Z" G d de          Z# G d de          Z$d9d#Z%i d$d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d&d%d(d'd*d)d,d+d.d-d0d/d2d1d4d3Z& e'e&(                                           e'e          k    sJ  e'e&)                                           e'e          k    sJ  e            d:d7            Z*d8S );a  
Collection of style transformations.

Think of it as a kind of color post processing after the rendering is done.
This could be used for instance to change the contrast/saturation; swap light
and dark colors or even change certain colors for other colors.

When the UI is rendered, these transformations can be applied right after the
style strings are turned into `Attrs` objects that represent the actual
formatting.
    )annotations)ABCMetaabstractmethod)
hls_to_rgb
rgb_to_hls)CallableHashableSequence)memoized)FilterOrBool	to_filter)AnyFloatto_floatto_str   )ANSI_COLOR_NAMESAttrs)parse_color)	StyleTransformation#SwapLightAndDarkStyleTransformationReverseStyleTransformation"SetDefaultColorStyleTransformation#AdjustBrightnessStyleTransformationDummyStyleTransformationConditionalStyleTransformationDynamicStyleTransformationmerge_style_transformationsc                  2    e Zd ZdZed	d            Zd
dZdS )r   z2
    Base class for any style transformation.
    attrsr   returnc                    dS )z
        Take an `Attrs` object and return a new `Attrs` object.

        Remember that the color formats can be either "ansi..." or a 6 digit
        lowercase hexadecimal color (without '#' prefix).
        N selfr   s     j/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/styles/style_transformation.pytransform_attrsz#StyleTransformation.transform_attrs,   s          r	   c                >    | j         j         dt          |            S )zE
        When this changes, the cache should be invalidated.
        -)	__class____name__idr$   s    r%   invalidation_hashz%StyleTransformation.invalidation_hash5   s#     .)66BtHH666r'   Nr   r   r    r   r    r	   )r+   
__module____qualname____doc__r   r&   r.   r"   r'   r%   r   r   '   sR             ^7 7 7 7 7 7r'   r   )	metaclassc                      e Zd ZdZddZdS )r   a  
    Turn dark colors into light colors and the other way around.

    This is meant to make color schemes that work on a dark background usable
    on a light background (and the other way around).

    Notice that this doesn't swap foreground and background like "reverse"
    does. It turns light green into dark green and the other way around.
    Foreground and background colors are considered individually.

    Also notice that when <reverse> is used somewhere and no colors are given
    in particular (like what is the default for the bottom toolbar), then this
    doesn't change anything. This is what makes sense, because when the
    'default' color is chosen, it's what works best for the terminal, and
    reverse works good with that.
    r   r   r    c                    |                     t          |j                            }|                     t          |j                            }|S )zR
        Return the `Attrs` used when opposite luminosity should be used.
        colorbgcolor)_replaceget_opposite_colorr8   r:   r#   s     r%   r&   z3SwapLightAndDarkStyleTransformation.transform_attrsN   sE    
 %7%D%DEE'9%-'H'HIIr'   Nr/   r+   r1   r2   r3   r&   r"   r'   r%   r   r   <   s2         "     r'   r   c                      e Zd ZdZddZdS )r   zJ
    Swap the 'reverse' attribute.

    (This is still experimental.)
    r   r   r    c                :    |                     |j                   S )N)reverse)r;   r@   r#   s     r%   r&   z*ReverseStyleTransformation.transform_attrs`   s    ~~%-&7~888r'   Nr/   r=   r"   r'   r%   r   r   Y   s2         9 9 9 9 9 9r'   r   c                  *    e Zd ZdZddZdd
ZddZdS )r   a-  
    Set default foreground/background color for output that doesn't specify
    anything. This is useful for overriding the terminal default colors.

    :param fg: Color string or callable that returns a color string for the
        foreground.
    :param bg: Like `fg`, but for the background.
    fgstr | Callable[[], str]bgr    Nonec                "    || _         || _        d S N)rB   rD   )r$   rB   rD   s      r%   __init__z+SetDefaultColorStyleTransformation.__init__n   s     r'   r   r   c                    |j         dv r5|                    t          t          | j                                      }|j        dv r5|                    t          t          | j                                      }|S )N defaultr9   r7   )r:   r;   r   r   rD   r8   rB   r#   s     r%   r&   z2SetDefaultColorStyleTransformation.transform_attrst   sg    =O++NN;vdg+G+GNHHE;/))NNVDG__)E)ENFFEr'   r	   c                T    dt          | j                  t          | j                  fS )Nzset-default-color)r   rB   rD   r-   s    r%   r.   z4SetDefaultColorStyleTransformation.invalidation_hash}   s%    47OO47OO
 	
r'   N)rB   rC   rD   rC   r    rE   r/   r0   r+   r1   r2   r3   rH   r&   r.   r"   r'   r%   r   r   d   sZ               
 
 
 
 
 
r'   r   c                  >    e Zd ZdZ	 ddd	ZddZddZddZddZdS )r   a  
    Adjust the brightness to improve the rendering on either dark or light
    backgrounds.

    For dark backgrounds, it's best to increase `min_brightness`. For light
    backgrounds it's best to decrease `max_brightness`. Usually, only one
    setting is adjusted.

    This will only change the brightness for text that has a foreground color
    defined, but no background color. It works best for 256 or true color
    output.

    .. note:: Notice that there is no universal way to detect whether the
              application is running in a light or dark terminal. As a
              developer of an command line application, you'll have to make
              this configurable for the user.

    :param min_brightness: Float between 0.0 and 1.0 or a callable that returns
        a float.
    :param max_brightness: Float between 0.0 and 1.0 or a callable that returns
        a float.
                  ?min_brightnessr   max_brightnessr    rE   c                "    || _         || _        d S rG   )rR   rS   )r$   rR   rS   s      r%   rH   z,AdjustBrightnessStyleTransformation.__init__   s     -,r'   r   r   c                l   t          | j                  }t          | j                  }d|cxk    rdk    sn J d|cxk    rdk    sn J |dk    r|dk    r|S |j         p
|j        dk    }|j        o
|j        dk    }|r|r|                     |j        pd          \  }}}t          |||          \  }	}
}|                     |
||          }
t          |	|
|          \  }}}t          |dz            d	t          |dz            d	t          |dz            d	}|
                    |
          }|S )Nr   r   rP   rQ   rL   ansidefaultrK      02xr7   )r   rR   rS   r:   r8   _color_to_rgbr   _interpolate_brightnessr   intr;   )r$   r   rR   rS   no_backgroundhas_fgcolorrgbhue
brightness
saturation	new_colors                r%   r&   z3AdjustBrightnessStyleTransformation.transform_attrs   s   !$"566!$"566N''''a''''''N''''a'''''' S  ^s%:%:L "M)GU]i-GkBek]&B 
	4= 
	4(():;;GAq!*4Q1*=*='CZ55NN J !j*==GAq!q3w<<QQSS\\QQs1s7||QQQINNN33Er'   r8   strtuple[float, float, float]c                   	 ddl m} ||         \  }}}|dz  |dz  |dz  fS # t          $ r Y nw xY wt          |dd         d          dz  t          |dd         d          dz  t          |dd         d          dz  fS )z;
        Parse `style.Attrs` color into RGB tuple.
        r   )ANSI_COLORS_TO_RGB     o@            )prompt_toolkit.output.vt100rh   KeyErrorr[   )r$   r8   rh   r^   r_   r`   s         r%   rY   z1AdjustBrightnessStyleTransformation._color_to_rgb   s    
	FFFFFF(/GAq!u9a%iU22 	 	 	D	
 ac
B%'ac
B%'ac
B%'
 	
s   " 
//valuefloatc                    |||z
  |z  z   S )zS
        Map the brightness to the (min_brightness..max_brightness) range.
        r"   )r$   rp   rR   rS   s       r%   rZ   z;AdjustBrightnessStyleTransformation._interpolate_brightness   s     .!@E IIIr'   r	   c                T    dt          | j                  t          | j                  fS )Nzadjust-brightness)r   rR   rS   r-   s    r%   r.   z5AdjustBrightnessStyleTransformation.invalidation_hash   s+    T())T())
 	
r'   N)rP   rQ   )rR   r   rS   r   r    rE   r/   )r8   re   r    rf   )rp   rq   rR   rq   rS   rq   r    rq   r0   )	r+   r1   r2   r3   rH   r&   rY   rZ   r.   r"   r'   r%   r   r      s         0 JM- - - - -   :
 
 
 
.J J J J
 
 
 
 
 
r'   r   c                  "    e Zd ZdZd	dZd
dZdS )r   z*
    Don't transform anything at all.
    r   r   r    c                    |S rG   r"   r#   s     r%   r&   z(DummyStyleTransformation.transform_attrs   s    r'   r	   c                    dS )Nzdummy-style-transformationr"   r-   s    r%   r.   z*DummyStyleTransformation.invalidation_hash   s    ++r'   Nr/   r0   )r+   r1   r2   r3   r&   r.   r"   r'   r%   r   r      sF            , , , , , ,r'   r   c                  *    e Zd ZdZddZdd	ZddZdS )r   z
    StyleTransformation class that can dynamically returns any
    `StyleTransformation`.

    :param get_style_transformation: Callable that returns a
        :class:`.StyleTransformation` instance.
    get_style_transformation(Callable[[], StyleTransformation | None]r    rE   c                    || _         d S rG   )rx   )r$   rx   s     r%   rH   z#DynamicStyleTransformation.__init__   s     )A%%%r'   r   r   c                p    |                                  pt                      }|                    |          S rG   )rx   r   r&   )r$   r   style_transformations      r%   r&   z*DynamicStyleTransformation.transform_attrs  s8    ))++I/G/I/I 	 $33E:::r'   r	   c                n    |                                  pt                      }|                                S rG   )rx   r   r.   )r$   r|   s     r%   r.   z,DynamicStyleTransformation.invalidation_hash  s6    ))++I/G/I/I 	 $55777r'   N)rx   ry   r    rE   r/   r0   rN   r"   r'   r%   r   r      s^         A A A A
; ; ; ;8 8 8 8 8 8r'   r   c                  *    e Zd ZdZddZddZddZdS )r   zB
    Apply the style transformation depending on a condition.
    r|   r   filterr   r    rE   c                <    || _         t          |          | _        d S rG   )r|   r   r   )r$   r|   r   s      r%   rH   z'ConditionalStyleTransformation.__init__  s     %9!''r'   r   r   c                b    |                                  r| j                            |          S |S rG   )r   r|   r&   r#   s     r%   r&   z.ConditionalStyleTransformation.transform_attrs  s/    ;;== 	D,<<UCCCr'   r	   c                \    |                                  | j                                        fS rG   )r   r|   r.   r-   s    r%   r.   z0ConditionalStyleTransformation.invalidation_hash  s$    t8JJLLMMr'   N)r|   r   r   r   r    rE   r/   r0   rN   r"   r'   r%   r   r     s`         ( ( ( (   
N N N N N Nr'   r   c                  &    e Zd ZddZddZdd
ZdS )_MergedStyleTransformationstyle_transformationsSequence[StyleTransformation]r    rE   c                    || _         d S rG   r   )r$   r   s     r%   rH   z#_MergedStyleTransformation.__init__$  s    %:"""r'   r   r   c                D    | j         D ]}|                    |          }|S rG   )r   r&   )r$   r   transformations      r%   r&   z*_MergedStyleTransformation.transform_attrs'  s.    "8 	: 	:N"22599EEr'   r	   c                >    t          d | j        D                       S )Nc              3  >   K   | ]}|                                 V  d S rG   )r.   ).0ts     r%   	<genexpr>z?_MergedStyleTransformation.invalidation_hash.<locals>.<genexpr>-  s.      OOqQ((**OOOOOOr'   )tupler   r-   s    r%   r.   z,_MergedStyleTransformation.invalidation_hash,  s"    OOD4NOOOOOOr'   N)r   r   r    rE   r/   r0   )r+   r1   r2   rH   r&   r.   r"   r'   r%   r   r   #  sV        ; ; ; ;   
P P P P P Pr'   r   r   r   r    c                     t          |           S )z2
    Merge multiple transformations together.
    )r   r   s    r%   r   r   0  s     &&;<<<r'   rV   	ansiblack	ansiwhiteansiredansibrightred	ansigreenansibrightgreen
ansiyellowansibrightyellowansiblueansibrightblueansimagentaansibrightmagentaansicyanansibrightcyanansigrayansibrightblack	colorname
str | Nonec                   | dS | dv r| S 	 t           |          S # t          $ r t          | dd         d          dz  }t          | dd         d          dz  }t          | dd         d          dz  }t          |||          \  }}}d|z
  }t	          |||          \  }}}t          |d	z            }t          |d	z            }t          |d	z            }|d
|d
|d
cY S w xY w)z
    Take a color name in either 'ansi...' format or 6 digit RGB, return the
    color of opposite luminosity (same hue/saturation).

    This is used for turning color schemes that work on a light background
    usable on a dark background.
    NrJ   rj   rk   ri   rl   rm   r   rW   rX   )OPPOSITE_ANSI_COLOR_NAMESro   r[   r   r   )r   r^   r_   r`   hlss          r%   r<   r<   S  s*    t O##((33 ( ( (	"1"r""U*	!A###e+	!A###e+Q1%%1aEQ1%%1aCLLCLLCLL''''''''''!(s    CC'&C'N)r   r   r    r   )r   r   r    r   )+r3   
__future__r   abcr   r   colorsysr   r   typingr   r	   r
   prompt_toolkit.cacher   prompt_toolkit.filtersr   r   prompt_toolkit.utilsr   r   r   baser   r   styler   __all__r   r   r   r   r   r   r   r   r   r   r   setkeysvaluesr<   r"   r'   r%   <module>r      s  
 
 # " " " " " ' ' ' ' ' ' ' ' + + + + + + + + / / / / / / / / / / ) ) ) ) ) ) : : : : : : : : ; ; ; ; ; ; ; ; ; ; ) ) ) ) ) ) ) )      
 
 
7 7 7 7 7G 7 7 7 7*    *=   :9 9 9 9 9!4 9 9 9
 
 
 
 
)< 
 
 
B_
 _
 _
 _
 _
*= _
 _
 _
D
, 
, 
, 
, 
,2 
, 
, 
,8 8 8 8 8!4 8 8 86N N N N N%8 N N N(
P 
P 
P 
P 
P!4 
P 
P 
P= = = ==  "	
 $   &   !  Y {  j   j!" z# & s$))++,,4D0E0EEEEE
s$++--..##6F2G2GGGGG 
"( "( "( "( "( "(r'   