"TeiddlZddlmZddlmZmZddlmZddlm Z m Z m Z m Z m Z mZmZmZddlmZddlmZmZmZmZdd lmZmZdd lmZmZeed fZGd d Z eGdd Z!e!Z"GddZ#y)N) lru_cache)dumpsloads)randint)AnyDictIterableListOptionalTypeUnioncast)errors)ColorColorParseError ColorSystem blend_rgb)Result rich_repr)DEFAULT_TERMINAL_THEME TerminalThemeStylecFeZdZdZdgZdeddfdZddd eddee fd Z y) _Bitz.A descriptor to get/set a style attribute bit.bitbit_noreturnNcd|z|_y)Nr)r)selfrs ,/usr/lib/python3/dist-packages/rich/style.py__init__z _Bit.__init__s ;objrobjtypecn|j|jzr|j|jzdk7Sy)Nr)_set_attributesr _attributes)r r$r%s r!__get__z _Bit.__get__s/    )??TXX-2 2r#) __name__ __module__ __qualname____doc__ __slots__intr"r r boolr)r#r!rrsA8Ist7T']x~r#rc&VeZdZUdZeeed<eeed<eed<eed<eeed<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"d3Zedrd5Ze dsd/eed0eed4dfd6Zed2eeeefd4dfd7Zedtd2eeeefd8ed4dfd9Zed:Zed;Zed<Zed=Zed>Zed?Zed@ZedAZedBZ edCZ!edDZ"edEZ#edFZ$e%d4efdGZ&d4efdHZ'd4efdIZ(dJe)d4efdKZ*ee+dLMdNed4efdOZ,edPee-d4e-fdQZ.d4e/fdRZ0dSed4efdTZ1dSed4efdUZ2d4efdVZ3e%d4eefdWZ4e%d4eefdXZ5e%d4eefdYZ6e%d4efdZZ7e%drd[Z8e%d4eeeffd\Z9e%drd]Z:ee+d^Md_ed4dfd`Z;e+dLMdtdaee<d4efdbZ=edce>dd4dfddZ?edudeZ@drdfZAe+dgMdrdhZBdtd1eed4dfdiZC dve)jdjdkdledJee)dmed4efdnZEdtdleed4d-fdoZFe+dLMdNedd4dfdpZGdNedd4dfdqZHy-)wraA 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) r3r4r(r'_link_link_id_ansi_style_definitionr5r6r712345678921515253) rr dimdboldbitalici underlineublinkblink2reverserconcealcstrikes underline2frameencircleoverline)uurerfrgoN)colorbgcolorrVrTrXrZr\r]r^r`rbrdrerfrglinkmetarjrkrlrmcvd|_d|_dtttfdtfd}|dn|||_|dn|||_t|du|duxrd|duxrd|duxrd|duxrd|duxrd| duxrd | duxrd | duxrd | duxrd | duxrd |duxrd|duxrdf |_|jrt|xrdxsd|xrdxsd|xrdxsd|xrdxsd|xrdxsd|xrdxsd| xrd xsd| xrd xsd| xrd xsd| xrd xsd| xrd xsd|xrdxsd|xrdxsdf nd|_ ||_ |dn t||_ |s|r#tddt|jnd|_d|_|jxs|xs |xs|xs| |_y)NrjrcPt|tr|Stj|SN) isinstancerparse)rjs r! _make_colorz#Style.__init__.._make_colors&ue45 L%++e:L Lr#rIrKrO @rr?B)r:r;r rstrr3r4sumr'r(r8rr7rhashr9r5r6)r rjrkrVrTrXrZr\r]r^r`rbrdrerfrgrlrmrss r!r"zStyle.__init__zsD*%) 04 MuUCZ0 MU M$mdU1C '[5I "D 4%Ad"(q%+!T!(bd")rt#*t#+d"*s$&.3T!*d$-$-  F### JQO!IANLq%AO!(qLb%AMr&QN'aO(qNs'a&3+!Nd'a%*%* $' , !\TuT{ :>$wq&!"4 #3"4 5R %) ..R%R7RdRdS r#rctS)zCCreate an 'null' style, equivalent to Style(), but more performant.) NULL_STYLE)clss r!nullz Style.nulls r#c|jt}d|_d|_||_||_d|_d|_d|_d|_ d|_ |xs| |_ 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. Nrr~) __new__rr:r;r3r4r'r(r8r9r7r6r5)rrjrkstyles r! from_colorzStyle.from_colorso{{5) "&   !   +G,   r#c |jt}d|_d|_d|_d|_d|_d|_d|_t||_ tddt|j|_ d|_| |_|S)zCreate a new style with meta data. Returns: meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None. Nrr})rrr:r;r3r4r'r(r8rr7rrr9r5r6)rrmrs r! from_metazStyle.from_metas{{5) "&  ! Dk #Av./U[[0A/BC j  r#handlersc |in|}|j|jDcic] \}}d|| c}}|j|Scc}}w)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. @)updateitemsr)rrmrkeyvalues r!onzStyle.onsQ\rt 8HI*#uqY%IJ}}T""JsA rrrIrJrKrLrMrNrOrPrQrRrSc|jS)z+Get a link id, used in ansi code for links.)r9r s r!link_idz Style.link_id}}r#ct|j g}|j}|j}|dzrl|dzr||jrdnd|dzr||jrdnd|dzr||j rd nd |d zr||j rd nd |dzr|dzr||jrdnd|dzr||jrdnd|dzr||jrdnd|dzr||jrdnd|dzr||jrdnd|dzrl|dzr||jrd nd!|d"zr||jrd#nd$|d%zr||jrd&nd'|d(zr||jrd)nd*|j ||j j"|j$$|d+||j$j"|j&r|d,||j&d-j)|xsd.|_|jS)/z-Re-generate style definition from attributes.rrVznot boldrIrTznot dimrKrXz not italicrOrZz not underlinertr\z not blinkrur]z not blink2rvr^z not reverserwr`z not concealrxrbz not strikeryrdznot underline2rzrez not framer{rfz not encircler|rgz not overlinerrl none)r;appendr'rVrTrXrZr\r]r^r`rbrdrerfrgr3namer4r8join)r attributesrbitss r!__str__z Style.__str__s  ! ! )$&J&&F''Do%!8TYY6J?6?DHH5)<6?t{{8 E6?$..;oNo%6?djj7kB6?t{{8 E6? 9-H6? 9-H6?t{{8 Eo%6?4??<@PQ7#djj7kB7#:NK7#:NK{{&t{{''(}}(t t}}))*zzvtzz"%(XXj%9%CVD "%%%r#c|j S)z;A Style is false if it has no attributes, colors, or links.)r6rs r!__bool__zStyle.__bool__Ks::~r# color_systemc|jig}|j}|j}|j|jz}|r|dzr ||d|dzr ||d|dzr ||d|dzr ||d|dzr%t ddD]}|d|zzs ||||d zr%t dd D]}|d|zzs ||||j 8|j|j j|j|j:|j|jj|jd d j||_|jS)zGenerate ANSI codes for this style. Args: color_system (ColorSystem): Color system. Returns: str: String containing codes. rrrIrKrOrJrrPr F foreground;) r:r _style_mapr(r'ranger3extend downgradeget_ansi_codesr4r)r rsgrrrrrs r!_make_ansi_codeszStyle._make_ansi_codesOs} :: CZZFJ))D,@,@@J>:a=)>:a=)>:a=)>:a=)/$Q{4%c2":c?34/$Q|4%c2":c?34{{& 4;;00>MMOP}}( MM++L9HH#(I #DJzzr#rz)maxsizerc t|j|S#tj$r!|j j cYSwxYw)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. )rrrrStyleSyntaxErrorstriplower)rrs r! normalizezStyle.normalizezsE )syy'( (&& );;=&&( ( )s1AAvaluesc2|D]}||cStd)zPick first non-None style.z$expected at least one non-None style) ValueError)rrrs r! pick_firstzStyle.pick_firsts, E   ?@@r#c#DKd|jdfd|jdfd|jdfd|jdfd|jdfd|j dfd|j dfd|jdfd |jdfd |jdfd |jdfd |jdfd |jdfd|jdfd|jdf|jrd|j fyyw)NrjrkrVrTrXrZr\r]r^r`rbrdrerfrlrm)rjrkrVrTrXrZr\r]r^r`rbrdrerfrlr7rmrs r! __rich_repr__zStyle.__rich_repr__s tzz4''t++dii&&TXXt$$ T))4>>400tzz4'' T))t++t++ T))DOOT11tzz4''$----dii%% ::$))# # sDD othercpt|tstS|j|jk(SrprqrNotImplemented__hash__r rs r!__eq__z Style.__eq__*%'! !}}%.."222r#cpt|tstS|j|jk7Srprrs r!__ne__z Style.__ne__rr#c|j |jSt|j|j|j|j |j |jf|_|jSrp)r5rr3r4r(r'r8r7rs r!rzStyle.__hash__sa :: !::     $$      zzr#c|jS)z.The foreground color or None if it is not set.)r3rs r!rjz Style.colors{{r#c|jS)z.The background color or None if it is not set.)r4rs r!rkz Style.bgcolorrr#c|jS)zLink text, if set.)r8rs r!rlz Style.linkszzr#cN|jduxs|jjS)z6Check if the style specified a transparent background.N)rk is_defaultrs r!transparent_backgroundzStyle.transparent_backgrounds"||t#>t||'>'>>r#c.t|jS)zA Style with background only.)rk)rrkrs r!background_stylezStyle.background_stylesT\\**r#c~|jiSttttft |jS)z=Get meta information (can not be changed after construction).)r7rrrrrrs r!rmz Style.metas0ZZ'rTT$sCx.% BS-TTr#c\|jrtS|jt}d|_d|_d|_d|_|j|_|j|_ |j|_ |jr tddnd|_ d|_d|_ d|_|S)z+Get a copy of the style with color removed.Nrr}r~F)r6rrrr:r;r3r4r(r'r8rr9r7r5r rs r! without_colorzStyle.without_colors :: ||E* "&  ,, $ 4 4jj 48JJGAv./B    r#r|style_definitioncT|jdk(s|s|jS|j}d}d}i}d}t|j }|D]}|j } | dk(r>t |d} | stjd tj| du| }V| dk(r=t |d} |j| } | tjd | d || <| d k(r&t |d} | stjd | }| |vr d ||| < tj| | }td|||d|} | S#t$r!} tjd| d| dd} ~ wwxYw#t$r!} tjd| d| dd} ~ wwxYw)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. rNrr~zcolor expected after 'on'zunable to parse z as background color; notz,expected style attribute after 'not', found FrlzURL expected after 'link'Tz as color; )rjrkrlr1)rrSTYLE_ATTRIBUTESitersplitrnextrrrrrrgetr) rrrrjrkrrlwords original_wordworderror attributers r!rrz Style.parses  ! ! #v -5E88: //#!%/1 "%++-."' M &&(Dt|E2 112MNN KK%- E2,006 $ 11FthO). 9%E2 112MNN))59 +D12 KK% O' PLE7LL C'  11*4(2HP  6'  11*4(+eWE  s0E&E= E:E55E:= F'F""F'themec|xst}g}|j}|j}|j}|jr||}}|j rI| |j n|j|}tjt||jd}|;|j|}|d|j|d|j|(|j|d}|d|j|jr|d|jr|d|jr|d |j r|d |j"r|d d j%|S) zGet a CSS style rule.g?zcolor: ztext-decoration-color: Frzbackground-color: zfont-weight: boldzfont-style: italicztext-decoration: underlineztext-decoration: line-throughztext-decoration: overlinez; )rrrjrkr^rTforeground_color get_truecolorr from_tripletrbackground_colorhexrVrXrZrbrgr)r rcssrrjrkr theme_colors r!get_html_stylezStyle.get_html_style3sZ// ,, <<$e7E 88*/-&&U=P=PQV=W &&*E,B,BCHE  --e4K W[__-. / ,[__,=> ?  !//%/HK ' '89 : 99 & ' ;; ' ( >> / 0 ;; 2 3 == . /yy~r#stylescBt|}t|t|S)zCombine styles and get result. Args: styles (Iterable[Style]): Styles to combine. Returns: Style: A new style instance. rrrrr iter_styless r!combinez Style.combineX6l ;[ 122r#cBt|}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. rrs r!chainz Style.chainerr#c|jrtS|jt}|j|_|j |_|j |_|j|_|j|_|j|_ |j|_ |jr tddnd|_ |j|_ d|_|j|_|S)zwGet a copy of this style. Returns: Style: A new Style instance with identical attributes. rr}r~F)r6rrrr:r;r3r4r(r'r8rr9r5r7rs r!copyz Style.copyrs :: ||E*jj "&"8"8{{  ,, $ 4 4jj 48JJGAv./Bjj  jj  r#rwcz|jrtS|jt}|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. Nr~F)r6rrrr:r;r3r4r(r'r8r9r5r7rs r!clear_meta_and_linkszStyle.clear_meta_and_linkss :: ||E*jj "&"8"8{{  ,, $ 4 4 jj    r#ct|jt}|j|_|j|_|j|_|j |_|j |_|j|_||_|r tddnd|_ 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. rr}r~NF)rrr:r;r3r4r(r'r8rr9r5r6r7)r rlrs r! update_linkzStyle.update_links||E*jj "&"8"8{{  ,, $ 4 4 48GAv./b  jj  r#F)rlegacy_windowstextrc|r||S|jxs|j|}|r d|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. z[mzz]8;id=rz\z]8;;\)r:rr8r9)r rrrattrsrendereds r!renderz Style.rendersw |+K Ad33LA49U5'4&0t ::nT]]O1TZZLxjW r#c|xs t|}tjj|j |dy)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)rsysstdoutwriter)r rs r!testz Style.tests5 s4y DKK-.b12r#c| |jr|S|jr|S|jt}d|_d|_|j xs |j |_|j xs |j |_|j|jz|j|jzz|_|j|jz|_|jxs |j|_ |jxs |j|_ |j|_|jr5|jr)ti|j|j|_ n|jxs |j|_ d|_|Srp)r6rrr:r;r3r4r(r'r8r9r7rrmr5)r r new_styles r!_addz Style._adds6 =EKKK ::L<<.  &* # <<64;; "^^JT~JTJT$JT$JTJTTNJT~JT 4.!JT"4.#JT$sm%JT&tCH~&'JTXGKUO5=e_ .Xd38n5'(#htCH~.#3#7##" 7D q'C !WFQI GE !WF1gG1gG !WFaJ HEBxHBxH ,&,&\$)[)S)Vt )c )c ) )A)!4AAA$v$&3C3D3 3C3D3 # x%hsm???++Ud38nUU$t?S?W??Bt"H]$;"s""H 3Xg. 37 3 3 3 3,s, 2/:.C.C$ {+    4 3# 3$ 3t(7+0PXg.P7Pr#c\eZdZdZdgZd dZdefdZede fdZ de ddfd Z de fd Z y) StyleStackzA stack of styles._stackrNc|g|_yrpr)r default_styles r!r"zStyleStack.__init__s $1? r#c"d|jdS)Nz rrs r!__repr__zStyleStack.__repr__sdkk_A..r#c |jdS)z&Get the Style at the top of the stack.rrs r!currentzStyleStack.currents{{2r#rcZ|jj|jd|zy)z}Push a new style on to the stack. Args: style (Style): New style to combine with current style. rN)rrrs r!pushzStyleStack.push s# 4;;r?U23r#cT|jj|jdS)z}Pop last style and discard. Returns: Style: New current style (also available as stack.current) r)rpoprs r!r$zStyleStack.pops {{2r#)rrrN) r*r+r,r-r.r"rrrrr r"r$r1r#r!rrsW I3/#/4%4D4Ur#r)$r functoolsrmarshalrrrandomrtypingrrr r r r r rr~rrjrrrrreprrrterminal_themerrrrrrrrr1r#r!r+sv  IIIAA#A #w,     X PX P X PvW r#