HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/site-packages/pip/_vendor/rich/__pycache__/style.cpython-37.pyc
B

L��g�i�@s�ddlZddlmZddlmZmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZddlmZddlmZmZmZmZdd	lmZmZdd
lmZmZeedfZGdd
�d
�Z eGdd�d��Z!e!�Z"Gdd�d�Z#dS)�N)�	lru_cache)�dumps�loads)�randint)�Any�Dict�Iterable�List�Optional�Type�Union�cast�)�errors)�Color�ColorParseError�ColorSystem�	blend_rgb)�Result�	rich_repr)�DEFAULT_TERMINAL_THEME�
TerminalTheme�Stylec@s@eZdZdZdgZedd�dd�Zdedee	d�d	d
�Z
dS)�_Bitz.A descriptor to get/set a style attribute bit.�bitN)�bit_no�returncCsd|>|_dS)Nr)r)�selfr�r�:/tmp/pip-unpacked-wheel-hv55ucu3/pip/_vendor/rich/style.py�__init__sz
_Bit.__init__r)�obj�objtypercCs |j|j@r|j|j@dkSdS)Nr)�_set_attributesr�_attributes)rr!r"rrr�__get__sz_Bit.__get__)�__name__�
__module__�__qualname__�__doc__�	__slots__�intr rr
�boolr%rrrrrsrc@s�eZdZUdZeeed<eeed<eed<eed<eeed<eed<ee	ed<ddddd	d
dddddgZ
d
ddddddddddddd�
Zdddddddddd d!d!d"d"d#d#d$d$d%d&d'd'd(�Zd)d)d)d)d)d)d)d)d)d)d)d)d)d)d)d)d)d*�ee
eefee
eefeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeefd*�d+d,�Zedd-�d.d/��Zed�eeeedd0�d1d2��Zeeeeefdd3�d4d5��Zed�eeeefedd6�d7d8��Zed9�Zed:�Zed;�Zed<�Zed=�Zed>�Zed?�Zed@�ZedA�Z edB�Z!edC�Z"edD�Z#edE�Z$e%ed-�dFdG��Z&ed-�dHdI�Z'ed-�dJdK�Z(e)edL�dMdN�Z*ee+dOdP�eedQ�dRdS���Z,eee-e-dT�dUdV��Z.e/d-�dWdX�Z0eedY�dZd[�Z1eedY�d\d]�Z2ed-�d^d_�Z3e%eed-�d`da��Z4e%eed-�dbdc��Z5e%eed-�ddde��Z6e%ed-�dfdg��Z7e%dd-�dhdi��Z8e%eeefd-�djdk��Z9e%dd-�dldm��Z:ee+dndP�eddo�dpdq���Z;e+dOdP�d�ee<edr�dsdt��Z=ee>dddu�dvdw��Z?edddu�dxdy��Z@dd-�dzd{�ZAe+d|dP�dd-�d}d~��ZBd�eedd�d�d��ZCd�e)jDd�d��eee)eed��d�d��ZEd�eed)d��d�d��ZFe+dOdP�edddQ�d�d���ZGedddQ�d�d��ZHd)S)�ra�A terminal style.

    A terminal style consists of a color (`color`), a background color (`bgcolor`), and a number of attributes, such
    as bold, italic etc. The attributes have 3 states: they can either be on
    (``True``), off (``False``), or not set (``None``).

    Args:
        color (Union[Color, str], optional): Color of terminal text. Defaults to None.
        bgcolor (Union[Color, str], optional): Color of terminal background. Defaults to None.
        bold (bool, optional): Enable bold text. Defaults to None.
        dim (bool, optional): Enable dim text. Defaults to None.
        italic (bool, optional): Enable italic text. Defaults to None.
        underline (bool, optional): Enable underlined text. Defaults to None.
        blink (bool, optional): Enabled blinking text. Defaults to None.
        blink2 (bool, optional): Enable fast blinking text. Defaults to None.
        reverse (bool, optional): Enabled reverse text. Defaults to None.
        conceal (bool, optional): Enable concealed text. Defaults to None.
        strike (bool, optional): Enable strikethrough text. Defaults to None.
        underline2 (bool, optional): Enable doubly underlined text. Defaults to None.
        frame (bool, optional): Enable framed text. Defaults to None.
        encircle (bool, optional): Enable encircled text. Defaults to None.
        overline (bool, optional): Enable overlined text. Defaults to None.
        link (str, link): Link URL. Defaults to None.

    �_color�_bgcolorr$r#�_hash�_null�_meta�_link�_link_id�_ansi�_style_definition�1�2�3�4�5�6�7�8�9Z21Z51Z52Z53)
rr��������	�
���dim�bold�italic�	underline�blink�blink2�reverse�conceal�strike�
underline2�frame�encircle�overline)rJ�drK�brL�irM�urNrOrP�rrQ�crR�srS�uurTrUrV�oN)�color�bgcolorrKrJrLrMrNrOrPrQrRrSrTrUrV�link�metacCsd|_d|_tttftd�dd�}|dkr0dn||�|_|dkrFdn||�|_t|dk	|dk	obd|dk	old|dk	ovd|dk	o�d|dk	o�d|	dk	o�d	|
dk	o�d
|dk	o�d|dk	o�d|
dk	o�d
|dk	o�d|dk	o�df
�|_|j�r�t|r�dp�d|r�dp�d|o�d�pd|�rd�pd|�rd�pd|�r*d�p,d|	�r8d	�p:d|
�rFd
�pHd|�rTd�pVd|�rbd�pdd|
�rpd
�prd|�r~d�p�d|�r�d�p�df
�nd|_	||_
|dk�r�dnt|�|_|�s�|�r�t
dd��t|j���nd|_d|_|j�p|�p|�p|�p||_dS)N)r`rcSst|t�r|St�|�S)N)�
isinstancer�parse)r`rrr�_make_color�sz#Style.__init__.<locals>._make_colorr?rArE�� �@��iiiirri?B�)r4r5rr�strr-r.�sumr#r$r2rr1r�hashr3r/r0)rr`rarKrJrLrMrNrOrPrQrRrSrTrUrVrbrcrfrrrr zs4










�*zStyle.__init__)rcCstS)zCCreate an 'null' style, equivalent to Style(), but more performant.)�
NULL_STYLE)�clsrrr�null�sz
Style.null)r`rarcCsV|�t�}d|_d|_||_||_d|_d|_d|_d|_	d|_
|pF||_d|_|S)aCreate a new style with colors and no attributes.

        Returns:
            color (Optional[Color]): A (foreground) color, or None for no color. Defaults to None.
            bgcolor (Optional[Color]): A (background) color, or None for no color. Defaults to None.
        Nrrl)
�__new__rr4r5r-r.r#r$r2r3r1r0r/)rqr`ra�stylerrr�
from_color�s

zStyle.from_color)rcrcCsj|�t�}d|_d|_d|_d|_d|_d|_d|_t	|�|_
tdd��t|j
���|_
d|_||_|S)z�Create a new style with meta data.

        Returns:
            meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None.
        Nri?B)rsrr4r5r-r.r#r$r2rr1rror3r/r0)rqrcrtrrr�	from_meta�s

zStyle.from_meta)rc�handlersrcKs2|dkrin|}|�dd�|��D��|�|�S)a�Create a blank style with meta information.

        Example:
            style = Style.on(click=self.on_click)

        Args:
            meta (Optional[Dict[str, Any]], optional): An optional dict of meta information.
            **handlers (Any): Keyword arguments are translated in to handlers.

        Returns:
            Style: A Style with meta information attached.
        NcSsi|]\}}|d|���qS)�@r)�.0�key�valuerrr�
<dictcomp>szStyle.on.<locals>.<dictcomp>)�update�itemsrv)rqrcrwrrr�on�szStyle.onrrr?r@rArBrCrDrErFrGrHrIcCs|jS)z+Get a link id, used in ansi code for links.)r3)rrrr�link_idsz
Style.link_idcCs|jdk�rg}|j}|j}|d@r�|d@r>||jr8dnd�|d@rX||jrRdnd�|d	@rr||jrld
nd�|d@r�||jr�d
nd�|d@�r|d@r�||jr�dnd�|d@r�||jr�dnd�|d@r�||j	r�dnd�|d@r�||j
r�dnd�|d@�r||j�rdnd�|d@�r�|d @�rD||j�r>d!nd"�|d#@�rb||j
�r\d$nd%�|d&@�r�||j�rzd'nd(�|d)@�r�||j�r�d*nd+�|jdk	�r�||jj�|jdk	�r�|d,�||jj�|j�r�|d-�||j�d.�|��p�d/|_|jS)0z-Re-generate style definition from attributes.N�rrKznot boldr?rJznot dimrArLz
not italicrErMz
not underlinei�rgrNz	not blinkrhrOz
not blink2rirPznot reverserjrQznot concealrkrRz
not strikeiirSznot underline2irTz	not frameirUznot encircleirVznot overlinerrb� �none)r5�appendr#rKrJrLrMrNrOrPrQrRrSrTrUrVr-�namer.r2�join)r�
attributesr��bitsrrr�__str__sV







z
Style.__str__cCs|jS)z;A Style is false if it has no attributes, colors, or links.)r0)rrrr�__bool__KszStyle.__bool__)�color_systemrcCs>|jdk�r8g}|j}|j}|j|j@}|r�|d@r@||d�|d@rT||d�|d@rh||d�|d@r|||d�|d@r�x*tdd	�D]}|d|>@r�|||�q�W|d
@r�x*td	d�D]}|d|>@r�|||�q�W|jdk	�r|�|j�|��	��|j
dk	�r,|�|j
�|�j	dd
��d�|�|_|jS)z�Generate ANSI codes for this style.

        Args:
            color_system (ColorSystem): Color system.

        Returns:
            str: String containing codes.
        Nrrr?rArEr@i�rFi�
F)�
foreground�;)r4r��
_style_mapr$r#�ranger-�extendZ	downgradeZget_ansi_codesr.r�)rr�Zsgrr�r�r�rrrr�_make_ansi_codesOs<

zStyle._make_ansi_codesi)�maxsize)rtrcCs2yt|�|��Stjk
r,|����SXdS)z�Normalize a style definition so that styles with the same effect have the same string
        representation.

        Args:
            style (str): A style definition.

        Returns:
            str: Normal form of style definition.
        N)rmrer�StyleSyntaxError�strip�lower)rqrtrrr�	normalizezszStyle.normalize)�valuesrcGs&x|D]}|dk	r|SqWtd��dS)zPick first non-None style.Nz$expected at least one non-None style)�
ValueError)rqr�r{rrr�
pick_first�s
zStyle.pick_firstccs�d|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd	|jdfVd
|j	dfVd|j
dfVd|jdfVd
|jdfVd|j
dfVd|jdfV|jr�d|jfVdS)Nr`rarKrJrLrMrNrOrPrQrRrSrTrUrbrc)r`rarKrJrLrMrNrOrPrQrRrSrTrUrbr1rc)rrrr�
__rich_repr__�s"zStyle.__rich_repr__)�otherrcCst|t�stS|��|��kS)N)rdr�NotImplemented�__hash__)rr�rrr�__eq__�s
zStyle.__eq__cCst|t�stS|��|��kS)N)rdrr�r�)rr�rrr�__ne__�s
zStyle.__ne__cCs8|jdk	r|jSt|j|j|j|j|j|jf�|_|jS)N)r/ror-r.r$r#r2r1)rrrrr��s
zStyle.__hash__cCs|jS)z.The foreground color or None if it is not set.)r-)rrrrr`�szStyle.colorcCs|jS)z.The background color or None if it is not set.)r.)rrrrra�sz
Style.bgcolorcCs|jS)zLink text, if set.)r2)rrrrrb�sz
Style.linkcCs|jdkp|jjS)z6Check if the style specified a transparent background.N)raZ
is_default)rrrr�transparent_background�szStyle.transparent_backgroundcCst|jd�S)zA Style with background only.)ra)rra)rrrr�background_style�szStyle.background_stylecCs&|jdkriSttttft|j��S)z=Get meta information (can not be changed after construction).N)r1r
rrmrr)rrrrrc�sz
Style.metacCsr|jr
tS|�t�}d|_d|_d|_d|_|j|_|j	|_	|j
|_
|j
rVtdd��nd|_d|_d|_
d|_|S)z+Get a copy of the style with color removed.Nri?BrlF)r0rprsrr4r5r-r.r$r#r2rr3r1r/)rrtrrr�
without_color�s
zStyle.without_colori)�style_definitionrc
Cs�|��dks|s|��S|j}d}d}i}d}t|���}�x\|D�]R}|��}	|	dkr�t|d�}	|	spt�d��yt	�
|	�dkWn:tk
r�}
zt�d|	�d|
���d�Wdd}
~
XYnX|	}qB|	dk�rt|d�}	|�|	�}|dkr�t�d	|	����d
||<qB|	dk�r.t|d�}	|	�s(t�d��|	}qB|	|k�rFd
|||	<qByt	�
|	�Wn<tk
�r�}
zt�d|	�d|
���d�Wdd}
~
XYnX|	}qBWt
f|||d�|��}|S)aParse a style definition.

        Args:
            style_definition (str): A string containing a style.

        Raises:
            errors.StyleSyntaxError: If the style definition syntax is invalid.

        Returns:
            `Style`: A Style instance.
        r�Nrrlzcolor expected after 'on'zunable to parse z as background color; �notz,expected style attribute after 'not', found FrbzURL expected after 'link'Tz as color; )r`rarb)r�rr�STYLE_ATTRIBUTES�iter�splitr��nextrr�rrer�getr)
rqr�r�r`rar�rb�wordsZ
original_word�word�error�	attributertrrrre�sX









zStyle.parse)�themercCs
|pt}g}|j}|j}|j}|jr.||}}|jr`|dkrB|jn|�|�}t�	t
||jd��}|dk	r�|�|�}|d|j���|d|j���|dk	r�|j|dd�}|d|j���|j
r�|d�|jr�|d	�|jr�|d
�|jr�|d�|j�r|d�d
�|�S)zGet a CSS style rule.Ng�?zcolor: ztext-decoration-color: F)r�zbackground-color: zfont-weight: boldzfont-style: italicztext-decoration: underlineztext-decoration: line-throughztext-decoration: overlinez; )rr�r`rarPrJ�foreground_colorZ
get_truecolorrZfrom_tripletrZbackground_color�hexrKrLrMrRrVr�)rr��cssr�r`rar�Ztheme_colorrrr�get_html_style3s:

zStyle.get_html_style)�stylesrcCst|�}t|t|��S)z�Combine styles and get result.

        Args:
            styles (Iterable[Style]): Styles to combine.

        Returns:
            Style: A new style instance.
        )r�rnr�)rqr��iter_stylesrrr�combineXs
z
Style.combinecGst|�}t|t|��S)z�Combine styles from positional argument in to a single style.

        Args:
            *styles (Iterable[Style]): Styles to combine.

        Returns:
            Style: A new style instance.
        )r�rnr�)rqr�r�rrr�chaines
zStyle.chaincCs~|jr
tS|�t�}|j|_|j|_|j|_|j|_|j|_|j	|_	|j
|_
|j
r^tdd��nd|_|j
|_
d|_|j|_|S)zwGet a copy of this style.

        Returns:
            Style: A new Style instance with identical attributes.
        ri?BrlF)r0rprsrr4r5r-r.r$r#r2rr3r/r1)rrtrrr�copyrs
z
Style.copyrjcCsh|jr
tS|�t�}|j|_|j|_|j|_|j|_|j|_|j	|_	d|_
d|_|j|_d|_d|_
|S)z�Get a copy of this style with link and meta information removed.

        Returns:
            Style: New style object.
        NrlF)r0rprsrr4r5r-r.r$r#r2r3r/r1)rrtrrr�clear_meta_and_links�s
zStyle.clear_meta_and_links)rbrcCsn|�t�}|j|_|j|_|j|_|j|_|j|_|j|_||_|rPt	dd��nd|_
d|_d|_|j
|_
|S)z�Get a copy with a different value for link.

        Args:
            link (str, optional): New value for link. Defaults to None.

        Returns:
            Style: A new Style instance.
        ri?BrlNF)rsrr4r5r-r.r$r#r2rr3r/r0r1)rrbrtrrr�update_link�s	
zStyle.update_linkrlF)r��legacy_windows)�textr�r�rcCsd|r|dkr|S|jp|�|�}|r6d|�d|�d�n|}|jr`|s`d|j�d|j�d|�d�}|S)	aDRender the ANSI codes for the style.

        Args:
            text (str, optional): A string to style. Defaults to "".
            color_system (Optional[ColorSystem], optional): Color system to render to. Defaults to ColorSystem.TRUECOLOR.

        Returns:
            str: A string containing ANSI style codes.
        Nz[�mzz]8;id=r�z\z]8;;\)r4r�r2r3)rr�r�r��attrs�renderedrrr�render�s
zStyle.render)r�rcCs(|p
t|�}tj�|�|��d��dS)z�Write text with style directly to terminal.

        This method is for testing purposes only.

        Args:
            text (Optional[str], optional): Text to style or None for style name.

        �
N)rm�sys�stdout�writer�)rr�rrr�test�s	z
Style.testcCs�|dks|jr|S|jr|S|�t�}d|_d|_|jp<|j|_|jpJ|j|_|j|j@|j|j@B|_|j|jB|_|j	p�|j	|_	|j
p�|j
|_
|j|_|jr�|jr�t|j
|j
��|_n|jp�|j|_d|_|S)N)r0rsrr4r5r-r.r$r#r2r3r1rrcr/)rrtZ	new_stylerrr�_add�s(
z
Style._addcCs|�|�}|jr|��S|S)N)r�rbr�)rrtZcombined_stylerrr�__add__�s
z
Style.__add__)NN)N)N)N)rl)N)Ir&r'r(r)r
r�__annotations__r+r,�bytesr*r�r�rrmrrr �classmethodrrrurvrrrKrJrLrMrNrOrPrQrRrSrTrUrV�propertyr�r�r�rr�rr��	StyleTyper�rr�r�r�r�r`rarbr�r�rcr�rerr�rr�r�r�r�r�Z	TRUECOLORr�r�r�r�rrrrrs
�9".+A$c@sdeZdZdZdgZddd�dd�Zed�d	d
�Zee	d�dd��Z
e	dd
�dd�Ze	d�dd�ZdS)�
StyleStackzA stack of styles.�_stackrN)�
default_stylercCs|g|_dS)N)r�)rr�rrrr szStyleStack.__init__)rcCsd|j�d�S)Nz<stylestack �>)r�)rrrr�__repr__szStyleStack.__repr__cCs
|jdS)z&Get the Style at the top of the stack.���)r�)rrrr�currentszStyleStack.current)rtrcCs|j�|jd|�dS)z}Push a new style on to the stack.

        Args:
            style (Style): New style to combine with current style.
        r�N)r�r�)rrtrrr�push
szStyleStack.pushcCs|j��|jdS)z}Pop last style and discard.

        Returns:
            Style: New current style (also available as stack.current)
        r�)r��pop)rrrrr�s
zStyleStack.pop)
r&r'r(r)r*r rmr�r�rr�r�r�rrrrr��sr�)$r��	functoolsr�marshalrr�randomr�typingrrrr	r
rrr
rlrr`rrrr�reprrrZterminal_themerrrmr�rrrpr�rrrr�<module>s$(a