U cfi@sddlZddlmZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZmZmZdd lmZmZdd lmZmZeed fZGd d d Z eGdd d Z!e!Z"GdddZ#dS)N) lru_cache)dumpsloads)randint)AnyDictIterableListOptionalTypeUnioncast)errors)ColorColorParseError ColorSystem blend_rgb)Result rich_repr)DEFAULT_TERMINAL_THEME TerminalThemeStylec@s@eZdZdZdgZeddddZdedee dd d Z dS) _Bitz.A descriptor to get/set a style attribute bit.bitN)bit_noreturncCsd|>|_dS)Nr)r)selfrrD/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/style.py__init__sz _Bit.__init__r)objobjtypercCs |j|j@r|j|j@dkSdS)Nr)_set_attributesr _attributes)rr!r"rrr__get__s z _Bit.__get__) __name__ __module__ __qualname____doc__ __slots__intr r r boolr%rrrrrsrc@seZdZUdZeeed<eeed<eed<eed<eeed<eed<ee ed<ddddd d d d dddg Z d ddddddddddddd Z dddddddddd 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/Zedeeeedd0d1d2Zeeeeefdd3d4d5Zedeeeefedd6d7d8Zed9Zed:Zed;Zed<Zed=Zed>Zed?Zed@ZedAZ edBZ!edCZ"edDZ#edEZ$e%ed-dFdGZ&ed-dHdIZ'ed-dJdKZ(e)edLdMdNZ*ee+dOdPeedQdRdSZ,eee-e-dTdUdVZ.e/d-dWdXZ0eedYdZd[Z1eedYd\d]Z2ed-d^d_Z3e%eed-d`daZ4e%eed-dbdcZ5e%eed-dddeZ6e%ed-dfdgZ7e%dd-dhdiZ8e%eeefd-djdkZ9e%dd-dldmZ:ee+dndPeddodpdqZ;e+dOdPdee<edrdsdtZ=ee>dddudvdwZ?edddudxdyZ@dd-dzd{ZAe+d|dPdd-d}d~ZBdeeddddZCde)jDddeee)eedddZEdeed)dddZFe+dOdPedddQddZGedddQddZHd)S)raA 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_definition12345678921515253) rr dimbolditalic underlineblinkblink2reverseconcealstrike underline2frameencircleoverline)rNdrObrPirQurRrSrTrrUcrVsrWuurXrYrZoN)colorbgcolorrOrNrPrQrRrSrTrUrVrWrXrYrZlinkmetacCsd|_d|_tttftddd}|dkr0dn|||_|dkrFdn|||_t|dk |dk obd|dk old|dk ovd|dk od|dk od| dk od | dk od | dk od | dk od | dk od |dk od|dk odf |_|jrt|rdpd|rdpd|odpd|rdpd|rdpd|r*dp,d| r8d p:d| rFd pHd| rTd pVd| rbd pdd| rpd prd|r~dpd|rdpdf nd|_ ||_ |dkrdnt ||_ |s|rt ddt|j nd|_d|_|jp|p|p|p| |_dS)N)rdrcSst|tr|St|SN) isinstancerparse)rdrrr _make_colorsz#Style.__init__.._make_colorrCrErI @rr?B)r4r5r rstrr-r.sumr#r$r2rr1rhashr3r/r0)rrdrerOrNrPrQrRrSrTrUrVrWrXrYrZrfrgrkrrrr zs\            #   &zStyle.__init__rcCstS)zCCreate an 'null' style, equivalent to Style(), but more performant.) NULL_STYLE)clsrrrnullsz Style.null)rdrercCsV|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. Nrrv) __new__rr4r5r-r.r#r$r2r3r1r0r/)r|rdrestylerrr from_colors  zStyle.from_color)rgrcCsj|t}d|_d|_d|_d|_d|_d|_d|_t ||_ t ddt |j |_ d|_| |_|S)zCreate a new style with meta data. Returns: meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None. Nrru)r~rr4r5r-r.r#r$r2rr1rryr3r/r0)r|rgrrrr from_metas  zStyle.from_meta)rghandlersrcKs2|dkr in|}|dd|D||S)aCreate 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).0keyvaluerrr szStyle.on..)updateitemsr)r|rgrrrronszStyle.onrrrCrDrErFrGrHrIrJrKrLrMcCs|jS)z+Get a link id, used in ansi code for links.)r3rrrrlink_idsz Style.link_idcCs|jdkrg}|j}|j}|d@r|d@r>||jr8dnd|d@rX||jrRdnd|d @rr||jrld nd |d @r||jrd nd|d@r|d@r||jrdnd|d@r||jrdnd|d@r||j rdnd|d@r||j rdnd|d@r||j rdnd|d@r|d @rD||j r>d!nd"|d#@rb||j r\d$nd%|d&@r||jrzd'nd(|d)@r||jrd*nd+|jdk r||jj|jdk r|d,||jj|jr|d-||jd.|pd/|_|jS)0z-Re-generate style definition from attributes.NrrOznot boldrCrNznot dimrErPz not italicrIrQz not underlinerlrRz not blinkrmrSz not blink2rnrTz not reverserorUz not concealrprVz not strikerqrWznot underline2rrrXz not framersrYz not encirclertrZz not overlinerrf none)r5appendr#rOrNrPrQrRrSrTrUrVrWrXrYrZr-namer.r2join)r attributesrbitsrrr__str__sV             z Style.__str__cCs|j S)z;A Style is false if it has no attributes, colors, or links.)r0rrrr__bool__KszStyle.__bool__) color_systemrcCs4|jdkr.g}|j}|j}|j|j@}|r|d@r@||d|d@rT||d|d@rh||d|d@r|||d|d@rtdd D]}|d|>@r|||q|d @rtd d D]}|d|>@r|||q|jdk r||j| |j dk r"||j |j d d d ||_|jS)zGenerate ANSI codes for this style. Args: color_system (ColorSystem): Color system. Returns: str: String containing codes. NrrrCrErIrDrrJr F foreground;) r4r _style_mapr$r#ranger-extend downgradeget_ansi_codesr.r)rrsgrrrrrrrr_make_ansi_codesOs@            zStyle._make_ansi_codesrr)maxsizerrcCs8zt||WStjk r2|YSXdS)zNormalize 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)rwrjrStyleSyntaxErrorstriplower)r|rrrr normalizezs zStyle.normalize)valuesrcGs&|D]}|dk r|SqtddS)zPick first non-None style.Nz$expected at least one non-None style) ValueError)r|rrrrr pick_firsts zStyle.pick_firstccsd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd |jdfVd |j dfVd |j dfVd |j dfVd |j dfVd|j dfVd|jdfV|jrd|jfVdS)NrdrerOrNrPrQrRrSrTrUrVrWrXrYrfrg)rdrerOrNrPrQrRrSrTrUrVrWrXrYrfr1rgrrrr __rich_repr__s"zStyle.__rich_repr__)otherrcCst|tstS||kSrhrirNotImplemented__hash__rrrrr__eq__s z Style.__eq__cCst|tstS||kSrhrrrrr__ne__s z Style.__ne__cCs8|jdk r|jSt|j|j|j|j|j|jf|_|jSrh)r/ryr-r.r$r#r2r1rrrrrs  zStyle.__hash__cCs|jS)z.The foreground color or None if it is not set.)r-rrrrrdsz Style.colorcCs|jS)z.The background color or None if it is not set.)r.rrrrresz Style.bgcolorcCs|jS)zLink text, if set.)r2rrrrrfsz Style.linkcCs|jdkp|jjS)z6Check if the style specified a transparent background.N)re is_defaultrrrrtransparent_backgroundszStyle.transparent_backgroundcCs t|jdS)zA Style with background only.)re)rrerrrrbackground_styleszStyle.background_stylecCs&|jdkriSttttft|jS)z=Get meta information (can not be changed after construction).N)r1r rrwrrrrrrrgsz Style.metacCsr|jr tS|t}d|_d|_d|_d|_|j|_|j |_ |j |_ |j rVt ddnd|_ d|_d|_ d|_|S)z+Get a copy of the style with color removed.NrrurvF)r0r{r~rr4r5r-r.r$r#r2rr3r1r/rrrrr without_colors zStyle.without_colorrt)style_definitionrc Cs|dks|s|S|j}d}d}i}d}t|}|D]P}|} | dkrt|d} | sltdzt | dkWn:t k r} ztd| d| dW5d} ~ XYnX| }q>| dkrt|d} | | } | dkrtd | d || <q>| d kr(t|d} | s"td | }q>| |kr@d ||| <q>zt | Wn<t k r} ztd| d| dW5d} ~ XYnX| }q>t 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. rNrrvzcolor expected after 'on'zunable to parse z as background color; notz,expected style attribute after 'not', found FrfzURL expected after 'link'Tz as color; )rdrerf)rr}STYLE_ATTRIBUTESitersplitrnextrrrrjrgetr) r|rrrdrerrfwords original_wordworderror attributerrrrrjsb           z Style.parse)themercCs |pt}g}|j}|j}|j}|jr.||}}|jr`|dkrB|jn||}t t ||j d}|dk r||}|d|j |d|j |dk r|j|dd}|d|j |j r|d|jr|d |jr|d |jr|d |jr|d d |S)zGet a CSS style rule.Ng?zcolor: ztext-decoration-color: Frzbackground-color: zfont-weight: boldzfont-style: italicztext-decoration: underlineztext-decoration: line-throughztext-decoration: overlinez; )rrrdrerTrNforeground_color get_truecolorr from_tripletrbackground_colorhexrOrPrQrVrZr)rrcssrrdrer theme_colorrrrget_html_style3s>   zStyle.get_html_style)stylesrcCst|}t|t|S)zCombine styles and get result. Args: styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrxrr|r iter_stylesrrrcombineXs z Style.combinecGst|}t|t|S)zCombine styles from positional argument in to a single style. Args: *styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrrrrchaines z Style.chaincCs~|jr tS|t}|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |j r^t ddnd|_ |j |_ d|_|j|_|S)zwGet a copy of this style. Returns: Style: A new Style instance with identical attributes. rrurvF)r0r{r~rr4r5r-r.r$r#r2rr3r/r1rrrrcopyrs z Style.copyrocCsh|jr tS|t}|j|_|j|_|j|_|j|_|j|_|j |_ d|_ d|_ |j |_ d|_d|_ |S)zGet a copy of this style with link and meta information removed. Returns: Style: New style object. NrvF)r0r{r~rr4r5r-r.r$r#r2r3r/r1rrrrclear_meta_and_linkss zStyle.clear_meta_and_links)rfrcCsn|t}|j|_|j|_|j|_|j|_|j|_|j|_||_|rPt ddnd|_ d|_ d|_ |j |_ |S)zGet 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. rrurvNF)r~rr4r5r-r.r$r#r2rr3r/r0r1)rrfrrrr update_links zStyle.update_linkrvF)rlegacy_windows)textrrrcCsd|r |dkr|S|jp||}|r6d|d|dn|}|jr`|s`d|jd|jd|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=rz\z]8;;\)r4rr2r3)rrrrattrsrenderedrrrrenders  z Style.render)rrcCs(|p t|}tj||ddS)zWrite 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)rwsysstdoutwriter)rrrrrtests 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|_|j r|j rt |j |j |_ n|j p|j |_ d|_|Srh)r0r~rr4r5r-r.r$r#r2r3r1rrgr/)rr new_stylerrr_adds*    z Style._addcCs||}|jr|S|Srh)rrfr)rrcombined_stylerrr__add__s z Style.__add__)NN)N)N)N)rv)N)Ir&r'r(r)r r__annotations__r+r,bytesr*rrr rwrrr classmethodr}rrrrrOrNrPrQrRrSrTrUrVrWrXrYrZpropertyrrrrrrr StyleTyperrrrrrrdrerfrrrgrrjrrrrrrrr TRUECOLORrrrrrrrrrs^      L".+A$    c@sdeZdZdZdgZdddddZedd d Zee dd d Z e dd ddZ e dddZ dS) StyleStackzA stack of styles._stackrN) default_stylercCs |g|_dSrhr)rrrrrr szStyleStack.__init__rzcCsd|jdS)Nz rrrrr__repr__szStyleStack.__repr__cCs |jdS)z&Get the Style at the top of the stack.rrrrrcurrentszStyleStack.currentrcCs|j|jd|dS)z}Push a new style on to the stack. Args: style (Style): New style to combine with current style. rN)rrrrrrpush szStyleStack.pushcCs|j|jdS)z}Pop last style and discard. Returns: Style: New current style (also available as stack.current) r)rpoprrrrrs zStyleStack.pop) r&r'r(r)r*r rwrrrrrrrrrrrsr)$r functoolsrmarshalrrrandomrtypingrrrr r r r r rvrrdrrrrreprrrterminal_themerrrwrrrr{rrrrrs&  (  `