o 7]heg@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)loadsdumps)randint)AnycastDictIterableListOptionalTypeUnion)errors)ColorColorParseError ColorSystem blend_rgb) rich_reprResult)DEFAULT_TERMINAL_THEME TerminalThemeStylec@sFeZdZdZdgZdeddfddZdd d ed dee fd d Z dS) _Bitz.A descriptor to get/set a style attribute bit.bitbit_noreturnNcCsd|>|_dS)Nr)r)selfrr8/usr/lib/python3/dist-packages/pip/_vendor/rich/style.py__init__z _Bit.__init__objrobjtypecCs |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&rrrrrs "rc&@seZdZUdZeeed<eeed<eed<eed<eed<eed<ee ed<gd Z d d d d dddddddddd Z iddddddddddddddddd d d!d!d"d"d#d"d$d$d%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.d/ee eefd0ee eefdeedeedeedeed eed!eed"eed$eed&eed(eed)eed*eed+eed1eed2eeeeff"d3d4Zedd6d7Ze -dd/eed0eed5dfd8d9Zed2eeeefd5dfd:d;Zedd2eeeefdZed?Zed@ZedAZedBZedCZedDZedEZedFZedGZ edHZ!edIZ"edJZ#edKZ$e%d5efdLdMZ&d5efdNdOZ'd5efdPdQZ(dRe)d5efdSdTZ*ee+dUdVdWed5efdXdYZ,edZee-d5e-fd[d\Z.d5e/fd]d^Z0d_ed5efd`daZ1d5efdbdcZ2e%d5eefdddeZ3e%d5eefdfdgZ4e%d5eefdhdiZ5e%d5efdjdkZ6e%ddldmZ7e%d5eeeffdndoZ8e%ddpdqZ9ee+drdVdsed5dfdtduZ:e+dUdVddvee;d5efdwdxZedd|d}Z?dd~dZ@dd1eed5dfddZA de)jBdddedRee)ded5efddZCddeed5d-fddZDdWedd5dfddZEd-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) r.r/r%r$_link_link_id_ansi_style_definitionr0r1r212345678921515253) rr dimdboldbitalici underlineublinkblink2reverserconcealcstrikes underline2frameencircleoverline)uur`rarboN)colorbgcolorrQrOrSrUrWrXrYr[r]r_r`rarblinkmetarerfrgrhcCsd|_d|_dtttfdtfdd}|durdn|||_|dur$dn|||_t|du|duo2d|duo7d|duo._make_colorrDrFrJ @rr?B)r5r6r rstrr.r/sumr$r%r3rr4rr2hashr0r1)rrerfrQrOrSrUrWrXrYr[r]r_r`rarbrgrhrlrrrr {sj            #              zStyle.__init__rcCstS)zCCreate an 'null' style, equivalent to Style(), but more performant.) NULL_STYLE)clsrrrnullsz Style.nullcCsf|t}d|_d|_||_||_d|_d|_d|_d|_ d|_ t ||ddddf|_ |p.| |_ |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. Nrrw)__new__rr5r6r.r/r$r%r3r4r2rzr0r1)r|rerfstylerrr from_colors*  zStyle.from_colorcCsh|t}d|_d|_d|_d|_d|_d|_d|_d|_ t ||_ t ddddd|j f|_ | |_|S)zCreate a new style with meta data. Returns: meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None. Nrrw)r~rr5r6r.r/r$r%r3r4rr2rzr0r1)r|rhrrrr from_metas*   zStyle.from_metahandlerscKs2|durin|}|dd|D||S)aCreate a blank style with meta information. Example: style = Style.on(click=self.on_click) Args: meta (Optiona[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|rhrrrrons zStyle.onrrrDrErFrGrHrIrJrKrLrMrNcC|jS)z+Get a link id, used in ansi code for links.)r4rrrrlink_id2z Style.link_idcCs|jdurg}|j}|j}|d@rE|d@r||jrdnd|d@r+||jr(dnd|d @r8||jr5d nd |d @rE||jrBd nd|d@r|d@rV||jrSdnd|d@rc||jr`dnd|d@rp||j rmdnd|d@r}||j rzdnd|d@r||j rdnd|d@r|d @r||j rd!nd"|d#@r||j rd$nd%|d&@r||jrd'nd(|d)@r||jrd*nd+|jdur||jj|jdur|d,||jj|jr|d-||jd.|pd/|_|jS)0z-Re-generate style definition from attributes.NrrQznot boldrDrOznot dimrFrSz not italicrJrUz not underlinermrWz not blinkrnrXz not blink2rorYz not reverserpr[z not concealrqr]z not strikerrr_znot underline2rsr`z not framertraz not encirclerurbz not overlinerrg none)r6appendr$rQrOrSrUrWrXrYr[r]r_r`rarbr.namer/r3join)r attributesrbitsrrr__str__7sV      z Style.__str__cCs|j S)z;A Style is false if it has no attributes, colors, or links.)r1rrrr__bool__eszStyle.__bool__ color_systemcCs0|jdurg}|j}|j}|j|j@}|rm|d@r||d|d@r)||d|d@r3||d|d@r=||d|d@rUtdd D]}|d|>@rT|||qF|d @rmtd d D]}|d|>@rl|||q^|jdur}||j| |j dur||j |j d d d ||_|jS)zGenerate ANSI codes for this style. Args: color_system (ColorSystem): Color system. Returns: str: String containing codes. NrrrDrFrJrErrKr F foreground;) r5r _style_mapr%r$ranger.extend downgradeget_ansi_codesr/r)rrsgrrrrrrrr_make_ansi_codesisD              zStyle._make_ansi_codesrs)maxsizercCs2zt||WStjy|YSw)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. )rxrkrStyleSyntaxErrorstriplower)r|rrrr normalizes  zStyle.normalizevaluescGs"|D] }|dur |Sqtd)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|jrud|jfVdSdS)NrerfrQrOrSrUrWrXrYr[r]r_r`rargrh)rerfrQrOrSrUrWrXrYr[r]r_r`rargr2rhrrrr __rich_repr__s&zStyle.__rich_repr__othercCsVt|tstS|j|jko*|j|jko*|j|jko*|j|jko*|j|jko*|j|jkSri) rjrNotImplementedr.r/r$r%r3r2)rrrrr__eq__s       z Style.__eq__cCrri)r0rrrr__hash__szStyle.__hash__cCr)z.The foreground color or None if it is not set.)r.rrrrrerz Style.colorcCr)z.The background color or None if it is not set.)r/rrrrrfrz Style.bgcolorcCr)zLink text, if set.)r3rrrrrgrz Style.linkcCs|jdup|jjS)z6Check if the style specified a transparent background.N)rf is_defaultrrrrtransparent_backgroundszStyle.transparent_backgroundcCs t|jdS)zA Style with background only.)rf)rrfrrrrbackground_styles zStyle.background_stylecCs&|jduriSttttft|jS)z=Get meta information (can not be changed after construction).N)r2rrrxrrrrrrrhs&z Style.metacCst|jrtS|t}d|_d|_d|_d|_|j|_|j |_ |j |_ |j r+t ddnd|_ |j |_ d|_d|_|S)z+Get a copy of the style with color removed.NrrvrwFr1r{r~rr5r6r.r/r%r$r3rr4r0r2rrrrr without_colors zStyle.without_colorrustyle_definitionc Cs|dks|s |S|j}d}d}i}d}t|}|D]}|} | dkrZt|d} | s5tdz t | duWnt yV} z td| d| dd} ~ ww| }q| dkryt|d} | | } | durttd | d || <q| d krt|d} | std | }q| |vrd ||| <qzt | Wnt y} z td| d| dd} ~ ww| }qt d|||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. rNrrwzcolor expected after 'on'zunable to parse z as background color; notz,expected style attribute after 'not', found FrgzURL expected after 'link'Tz as color; )rerfrgr)rr}STYLE_ATTRIBUTESitersplitrnextrrrrkrgetr) r|rrrerfrrgwords original_wordworderror attributerrrrrksj        z Style.parsethemecCs|pt}g}|j}|j}|j}|jr||}}|jr0|dur!|jn||}t t ||j d}|durI||}|d|j |d|j |dur\|j|dd}|d|j |j rc|d|jrj|d |jrq|d |jrx|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; )rrrerfrYrOforeground_color get_truecolorr from_tripletrbackground_colorhexrQrSrUr]rbr)rrcssrrerfr theme_colorrrrget_html_styleBs>    zStyle.get_html_stylestylescCt|}t|t|S)zCombine styles and get result. Args: styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rryrr|r iter_stylesrrrcombineg z Style.combinecGr)zCombine styles from positional argument in to a single style. Args: *styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrrrrchaintrz Style.chaincCs~|jrtS|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. rrvrwFrrrrrcopys z Style.copycCsp|t}|j|_|j|_|j|_|j|_|j|_|j|_||_|r(t ddnd|_ |j |_ 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. rrvrwF)r~rr5r6r.r/r%r$r3rr4r0r1r2)rrgrrrr update_links zStyle.update_linkrwF)rlegacy_windowstextrcCs^|r|dur|S||}|rd|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;;\)rr3r4)rrrrattrsrenderedrrrrenders   z Style.rendercCs(|pt|}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)rxsysstdoutwriter)rrrrrtests z Style.testcCst|ts |dus tS|dus|jr|S|jr|S|t}d|_d|_|jp)|j|_|jp0|j|_|j |j @|j |j @B|_ |j |j B|_ |j pL|j |_ |j pS|j |_ |j |_ |jp^|j|_|jrs|jrsti|j|j|_|S|jpx|j|_|Sri)rjrrr1r~r5r6r.r/r%r$r3r4r0r2rrh)rr new_stylerrr__add__s0    z Style.__add__)rr)NNri)rrrr)rw)Fr'r(r)r*r r__annotations__r,r-bytesr+rrr rxrrr classmethodr}rrrrrQrOrSrUrWrXrYr[r]r_r`rarbpropertyrrrrrrr StyleTyperrrrrrerfrgrrrhrrkrrr rrrr TRUECOLORrrrrrrrrs               S   &.*   A$    c@s`eZdZdZdgZdddZdefd d Zede fd d Z d e ddfddZ de fddZ dS) StyleStackzA stack of styles._stack default_stylerrNcCs |g|_dSrir)rrrrrr s zStyleStack.__init__cCsd|jdS)Nz rrrrr__repr__r!zStyleStack.__repr__cCs |jdS)z&Get the Style at the top of the stack.rrrrrcurrents zStyleStack.currentrcCs|j|jd|dS)z}Push a new style on to the stack. Args: style (Style): New style to combine with current style. rN)rrrrrrpushszStyleStack.pushcCs|j|jdS)z}Pop last style and discard. Returns: Style: New current style (also available as stack.current) r)rpoprrrrr s  zStyleStack.pop)rrrN) r'r(r)r*r+r rxrrrrrrrrrrrs r)$r functoolsrmarshalrrrandomrtypingrrrr r r r r rwrrerrrrreprrrterminal_themerrrxrrrr{rrrrrs(  (  T