whniTddlZddlmZddlmZddlmZmZddlm Z ddl m Z m Z m Z mZmZmZmZmZddlmZdd lmZmZmZmZdd lmZmZdd lmZmZed d ddddZ ee!dfZ"GddZ#eGddZ$e$Z%GddZ&dS)N) lru_cache) attrgetter)dumpsloads)randint)AnyDictIterableListOptionalTypeUnioncast)errors)ColorColorParseError ColorSystem blend_rgb)Result rich_repr)DEFAULT_TERMINAL_THEME TerminalTheme_color_bgcolor _attributes_set_attributes_link_metaStylecTeZdZdZdgZdeddfdZddd eddee fd Z dS) _Bitz.A descriptor to get/set a style attribute bit.bitbit_noreturnNcd|z|_dS)Nr)r#)selfr$s Z/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/rich/style.py__init__z _Bit.__init__s;objr objtypecJ|j|jzr|j|jzdkSdS)Nr)rr#r)r'r+r,s r(__get__z _Bit.__get__s-   ) 3?TX-2 2tr*) __name__ __module__ __qualname____doc__ __slots__intr)r r boolr.r*r(r"r"st88Ist7T']x~r*r"c&:eZdZUdZeeed<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"d3Zedsd5Ze dtd/eed0eed4dfd6Zed2eeeefd4dfd7Zedud2eeeefd8ed4dfd9Zed: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%dsd[Z8e%d4eeeffd\Z9e%dsd]Z:ee+d^Md_ed4dfd`Z;e+dLMdudaee<d4efdbZ=edce>dd4dfddZ?edvdeZ@dsdfZAe+dgMdsdhZBdud1eed4dfdiZC dwe)jDdkdldmedJee)dned4efdoZEdudmeed4d-fdpZFe+dLMdNedd4dfdqZGdNedd4dfdrZHd-S)xr aA 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. rrrr_hash_nullr) rrrrr_link_id_ansi_style_definitionr8r9r12345678921515253) rr dimdboldbitalici underlineublinkblink2reverserconcealcstrikes underline2frameencircleoverline)uurfrgrhoN)colorbgcolorrWrUrYr[r]r^r_rarcrerfrgrhlinkmetarkrlrmrncd|_d|_dtttfdtfd}|dn |||_|dn |||_t|du|duod|duod|duod|duod|duod| duod | duod | duod | duod | duod |duod|duodf |_|jrPt|rdpd|rdpd|rdpd|rdpd|rdpd|rdpd| rd pd| rd pd| rd pd| rd pd| rd pd|rdpd|rdpdf nd|_ ||_ |dnt||_ |s|r&tddt|j nd|_d|_|jp|p|p|p| |_dS)Nrkr%cXt|tr|ntj|SN) isinstancerparse)rks r( _make_colorz#Style.__init__.._make_colors%&ue44L55%+e:L:L Lr*rJrLrP @rr?B)r;r<rrstrrrsumrrrrrrhashr:r8r9)r'rkrlrWrUrYr[r]r^r_rarcrerfrgrhrmrnrts r(r)zStyle.__init__s*%) 04 MuUCZ0 MU M M M M$mddU1C1C '[[5I5I "D 4%Ad"(q%+!T!(bd")rt#*t#+d"*s$&.3T!*d$-$-   F## CJQO!IANLq%AO!(qLb%AMr&QN'aO(qNs'a&3+!Nd'a%*%*   $' , !\TTuT{{ :> O$ Owq&!! 54 #3#3 5 5 5R %) .R%R7RdRdS r*r%ctS)zCCreate an 'null' style, equivalent to Style(), but more performant.) NULL_STYLE)clss r(nullz Style.nulls r*c|t}d|_d|_||_||_d|_d|_d|_d|_ d|_ |p| |_ 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__r r;r<rrrrrr:rr9r8)rrkrlstyles r( from_colorzStyle.from_colorsr{{5)) "&   !   +G,   r*c8|t}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~)rr r;r<rrrrrrrrrr:r8r9)rrnrs r( from_metazStyle.from_metas{{5)) "&  ! Dkk #Av..CU[0A0ACC j  r*handlersc |in|}|d|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. Nc i|] \}}d|| S)@r6).0keyvalues r( zStyle.on.. s$III*#uYYYIIIr*)updateitemsr)rrnrs r(onzStyle.onsN\rrt II8H8HIIIJJJ}}T"""r*rrrJrKrLrMrNrOrPrQrRrSrTc|jS)z+Get a link id, used in ansi code for links.)r:r's r(link_idz Style.link_id }r*c|jg}|j}|j}|dzrd|dzr||jrdnd|dzr||jrdnd|d zr||jrd nd |d zr||jrd nd|dzr}|dzr||jrdnd|dzr||jrdnd|dzr||j rdnd|dzr||j rdnd|dzr||j rdnd|dzrd|d zr||j rd!nd"|d#zr||j rd$nd%|d&zr||jrd'nd(|d)zr||jrd*nd+|j||jj|j |d,||jj|jr|d-||jd.|pd/|_|jS)0z-Re-generate style definition from attributes.NrrWznot boldrJrUznot dimrLrYz not italicrPr[z not underlinerur]z not blinkrvr^z not blink2rwr_z not reverserxraz not concealryrcz not strikerzreznot underline2r{rfz not framer|rgz not encircler}rhz not overlinerrm none)r<appendrrWrUrYr[r]r^r_rarcrerfrgrhrnamerrjoin)r' attributesrbitss r(__str__z Style.__str__"s  ! )$&J&F'Do% O!8@FTY>66J???6?=FDH;55)<<<6?FFt{D88 EEE6?OF$.M;;oNNNo% F6?CFdjA77kBBB6?FFt{D88 EEE6?IF G99-HHH6?IF G99-HHH6?FFt{D88 EEEo% L6?RF4?P<<@PQQQ7#CFdjA77kBBB7#LFJ::NKKK7#LFJ::NKKK{&t{'(((}(t t})***z #vtz"""%(XXj%9%9%CVD "%%r*c|j S)z;A Style is false if it has no attributes, colors, or links.)r9rs r(__bool__zStyle.__bool__Ps :~r* color_systemc&|jg}|j}|j}|j|jz}|r|dzr||d|dzr||d|dzr||d|dzr||d|dzr,t dd D]}|d|zzr||||d zr,t d d D]}|d|zzr||||j?||j| |j A||j | d d ||_|jS)zGenerate ANSI codes for this style. Args: color_system (ColorSystem): Color system. Returns: str: String containing codes. NrrrJrLrPrKrrQr F foreground;) r;r _style_maprrrangerextend downgradeget_ansi_codesrr)r'rsgrrrrr#s r(_make_ansi_codeszStyle._make_ansi_codesTs : CZFJ)D,@@J 4>*F:a=)))>*F:a=)))>*F:a=)))>*F:a=)))/4$Q{{44%c24"F:c?333/4$Q||44%c24"F:c?333{& 4;00>>MMOOPPP}( M++L99HH#(I #DJzr*r{)maxsizerc t||S#tj$r)|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. )rrsrStyleSyntaxErrorstriplower)rrs r( normalizezStyle.normalizes_ )syy''(( (& ) ) );;==&&(( ( ( ( )s!$5AAvaluesc6|D]}||cS td)zPick first non-None style.Nz$expected at least one non-None style) ValueError)rrrs r( pick_firstzStyle.pick_firsts6  E  !?@@@r*c#Kd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd|jdfVd |jdfVd |j dfVd |j dfVd |j dfVd |j dfVd|j dfVd|jdfV|jr d|jfVdSdS)NrkrlrWrUrYr[r]r^r_rarcrerfrgrmrn)rkrlrWrUrYr[r]r^r_rarcrerfrgrmrrnrs r( __rich_repr__zStyle.__rich_repr__sntz4''''t++++di&&&&TXt$$$$ T))))4>40000tz4'''' T))))t++++t++++ T))))DOT1111tz4''''$-----di%%%% : $$)# # # # # # $ $r*otherct|tstS||kSrqrrr NotImplemented__hash__r'rs r(__eq__z Style.__eq__7%'' "! !}}%.."2"222r*ct|tstS||kSrqrrs r(__ne__z Style.__ne__rr*cn|j|jStt||_|jSrq)r8r _hash_getterrs r(rzStyle.__hash__s1 : !: ,t,,-- zr*c|jS)z.The foreground color or None if it is not set.)rrs r(rkz Style.colors {r*c|jS)z.The background color or None if it is not set.)rrs r(rlz Style.bgcolorrr*c|jS)zLink text, if set.)rrs r(rmz Style.links zr*c,|jdup |jjS)z6Check if the style specified a transparent background.N)rl is_defaultrs r(transparent_backgroundzStyle.transparent_backgrounds|t#>t|'>>r*c,t|jS)zA Style with background only.)rl)r rlrs r(background_stylezStyle.background_stylesT\****r*c|jin8ttttft |jS)z=Get meta information (can not be changed after construction).)rrr rrrrs r(rnz Style.metas1Z'rrT$sCx.% BSBS-T-TTr*c>|jrtS|t}d|_d|_d|_d|_|j|_|j |_ |j |_ |j rtddnd|_ d|_d|_ d|_|S)z+Get a copy of the style with color removed.Nrr~rF)r9rrr r;r<rrrrrrr:rr8r'rs r( without_colorzStyle.without_colors :  ||E** "&  , $ 4j 48JFGAv..00B    r*r}style_definitionc|dks|s|S|j}d}d}i}d}t|}|D]Y}|} | dkrlt |d} | stjd tj | n-#t$r } tjd| d| dd} ~ wwxYw| }| dkrDt |d} | | } | tjd | d || <| d kr*t |d} | stjd | }| |vr d ||| < tj | n-#t$r } tjd| d| dd} ~ wwxYw| }[td|||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. rNrrzcolor expected after 'on'zunable to parse z as background color; notz,expected style attribute after 'not', found FrmzURL expected after 'link'Tz as color; )rkrlrmr6)rrSTYLE_ATTRIBUTESitersplitrnextrrrrsrgetr ) rrrrkrlrrmwords original_wordworderror attributers r(rsz Style.parsesc  ! ! # #v - -5E -88:: /#!%/1 "%++--.."' ' M &&((Dt||E2O 12MNNN K%%%%&    1P4PPPP  E2,0066 $ 1OtOO). 9%%E2O 12MNNN)))59 +D122 K%%%%&    1E4EEeEE  LE7LLLL s0%B:: C$CC$6F  F5F00F5themec|pt}g}|j}|j}|j}|jr||}}|jrF||jn||}tj t||j d}|;||}|d|j |d|j |*||d}|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; )rrrkrlr_rUforeground_color get_truecolorr from_tripletrbackground_colorhexrWrYr[rcrhr)r'rcssrrkrlr theme_colors r(get_html_stylezStyle.get_html_style/s// , < ,$e7E 8 */-&&U=P=PQV=W=W &*E,BCHHE  --e44K F.[_.. / / / F>[_>> ? ? ?  !//%/HHK F9 99 : : : 9 ( F& ' ' ' ; ) F' ( ( ( > 1 F/ 0 0 0 ; 4 F2 3 3 3 = 0 F. / / /yy~~r*stylescZt|}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.combineT'6ll ;[ 1 1222r*cZt|}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.chainarr*cz|jrtS|t}|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |j rtddnd|_ |j |_ d|_|j|_|S)zwGet a copy of this style. Returns: Style: A new Style instance with identical attributes. rr~rF)r9rrr r;r<rrrrrrr:r8rrs r(copyz Style.copyns :  ||E**j "&"8{  , $ 4j 48JFGAv..00Bj  j  r*rxc,|jrtS|t}|j|_|j|_|j|_|j|_|j|_|j |_ d|_ d|_ d|_ d|_d|_ |S)zGet a copy of this style with link and meta information removed. Returns: Style: New style object. NrF)r9rrr r;r<rrrrrr:r8rrs r(clear_meta_and_linkszStyle.clear_meta_and_linkss :  ||E**j "&"8{  , $ 4     r*c@|t}|j|_|j|_|j|_|j|_|j|_|j|_||_|rtddnd|_ 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~rNF)rr r;r<rrrrrrr:r8r9r)r'rmrs r( update_linkzStyle.update_links||E**j "&"8{  , $ 4 48@GAv..00b  j  r*rF)rlegacy_windowstextrc|r||S|jp||}|r d|d|dn|}|jr|sd|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;;\)r;rrr:)r'rrrattrsrendereds r(renderz Style.renders  |+K Ad33LAA49C050040000t : n WT]WWTZWWxWWW r*c|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)rsysstdoutwriter)r'rs r(testz Style.testsE s4yy DKK--11122222r*c6||jr|S|jr|S|t}d|_d|_|jp|j|_|jp|j|_|j|jz|j|jzz|_|j|jz|_|j p|j |_ |j p|j |_ |j|_|j r*|j r#ti|j |j |_ n|j p|j |_ d|_|Srq)r9rr r;r<rrrrrr:rrrnr8)r'r new_styles r(_addz Style._adds =EK=K : L<<..  &* # <64; "^JT~JTJT$JT$JTJTTNJT~JT 4.!JT"4.#JT$sm%JT&tCH~&'JTJTJTJTX[GKUO5=e_ [.Xd38n5'[(##htCH~.#3#7###[#" 477D $q''C T!WWFQI DGGE T!WWFd1ggGd1ggG T!WWFaJ DHHEtBxxHtBxxH X,&,&,&,&,&\$)[)S))))VYt )c )c ) ) )[ )A)!4AAAA[A$v$$$$&3C3D3333 3C3D3333 # xX%XhsmX????X?+++X+Ud38nUUUXUX$Yt?S?W???[?BYt""H]$;"s""""H 3Xg. 37 3 3 3[ 3 3 3 3[ 3,Ys, 2/:.C$ {+    4 3 3# 3$ 3 3 3 3Yt(7+0PXg.P7PPPPPPr*cdeZdZdZdgZd dZdefdZede fd Z d e ddfd Z de fd Z dS) StyleStackzA stack of styles._stack default_styler r%Nc|g|_dSrqr)r'rs r(r)zStyleStack.__init__s$1? r*cd|jdS)Nz rrs r(__repr__zStyleStack.__repr__s.dk....r*c|jdS)z&Get the Style at the top of the stack.rrs r(currentzStyleStack.currents{2r*rcV|j|jd|zdS)z}Push a new style on to the stack. Args: style (Style): New style to combine with current style. r$N)rrrs r(pushzStyleStack.push s+ 4;r?U233333r*cN|j|jdS)z}Pop last style and discard. Returns: Style: New current style (also available as stack.current) r$)rpoprs r(r)zStyleStack.pops" {2r*)rr r%N) r/r0r1r2r3r)rr"rr r%r'r)r6r*r(rrs I3333/#////X4%4D4444Ur*r)'r  functoolsroperatorrpicklerrrandomrtypingrr r r r r rrrrrkrrrrreprrrterminal_themerrrrrr"r rrr6r*r(r1s IIIIIIIIIIIIIIIIIIIIAAAAAAAAAAAA########AAAAAAAAz j-):GW #w,           O PO PO PO PO PO PO P O PdUWW r*