xiiddlZddlmZddlmZddlmZddlmZm Z ddl m Z ddl m Z mZmZmZmZmZmZmZdd lmZdd lmZmZmZmZdd lmZmZdd lm Z m!Z!ed dddddZ"ee#dfZ$ee dZ%GddZ&eGddZ'e'Z(GddZ)dS)N) lru_cache)count) attrgetter)dumpsloads) getrandbits)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 b/home/jenkins/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+rr boolr0r,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_definitionr:r;r 12345678921515253) rr dimdboldbitalici underlineublinkblink2reverserconcealcstrikes underline2frameencircleoverline)uurhrirjoN)colorbgcolorrYrWr[r]r_r`rarcrergrhrirjlinkmetarmrnrorpcd|_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*ttt|j nd|_d|_|jp|p|p|p| |_dS)Nrmr'cXt|tr|ntj|SN) isinstancerparse)rms r* _make_colorz#Style.__init__.._make_colors%&ue44L55%+e:L:L Lr,rLrNrR @rr)r=r>rrstrrrsumrrrrr next _id_generatorhashr<r:r;)r)rmrnrYrWr[r]r_r`rarcrergrhrirjrorprvs 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{{ ;? P4 PtM"" 6D$4$4 6 6 6b %) .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<r r;r:)rrmrnstyles r* from_colorzStyle.from_colorsr{{5)) "&   !   +G,   r,c@|t}d|_d|_d|_d|_d|_d|_d|_t||_ ttt|j |_d|_| |_|S)zCreate a new style with meta data. Returns: meta (Optional[Dict[str, Any]]): A dictionary of meta data. Defaults to None. Nr)rr!r=r>rrrrrrr rrrr<r:r;)rrprs r* from_metazStyle.from_metas{{5)) "&  ! Dkk  //Dek1B1BDD 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)@r8).0keyvalues r* zStyle.on..s$III*#uYYYIIIr,)updateitemsr)rrprs r*onzStyle.onsN\rrt II8H8HIIIJJJ}}T"""r,rrrLrMrNrOrPrQrRrSrTrUrVc|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.NrrYznot boldrLrWznot dimrNr[z not italicrRr]z not underlinerwr_z not blinkrxr`z not blink2ryraz not reverserzrcz not concealr{rez not striker|rgznot underline2r}rhz not framer~riz not encirclerrjz not overlinerro none)r>appendrrYrWr[r]r_r`rarcrergrhrirjrnamerrjoin)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.)r;rs r*__bool__zStyle.__bool__Ts :~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. NrrrLrNrRrMrrSr F foreground;) r=r _style_maprrrangerextend downgradeget_ansi_codesrr)r)rsgrrrrr%s r*_make_ansi_codeszStyle._make_ansi_codesXs : 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. )rrurStyleSyntaxErrorstriplower)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)NrmrnrYrWr[r]r_r`rarcrergrhrirorp)rmrnrYrWr[r]r_r`rarcrergrhriror rprs r* __rich_repr__zStyle.__rich_repr__sntz4''''t++++di&&&&TXt$$$$ T))))4>40000tz4'''' T))))t++++t++++ T))))DOT1111tz4''''$-----di%%%% : $$)# # # # # # $ $r,otherct|tstS||kSrsrtr!NotImplemented__hash__r)rs r*__eq__z Style.__eq__7%'' "! !}}%.."2"222r,ct|tstS||kSrsrrs r*__ne__z Style.__ne__rr,cn|j|jStt||_|jSrs)r:r _hash_getterrs r*rzStyle.__hash__s1 : !: ,t,,-- zr,c|jS)z.The foreground color or None if it is not set.)rrs r*rmz Style.colors {r,c|jS)z.The background color or None if it is not set.)rrs r*rnz Style.bgcolorrr,c|jS)zLink text, if set.)rrs r*roz Style.links zr,c,|jdup |jjS)z6Check if the style specified a transparent background.N)rn is_defaultrs r*transparent_backgroundzStyle.transparent_backgrounds|t#>t|'>>r,c,t|jS)zA Style with background only.)rn)r!rnrs r*background_stylezStyle.background_stylesT\****r,c|jin8ttttft |jS)z=Get meta information (can not be changed after construction).)r rr rr rrs r*rpz Style.metas1Z'rrT$sCx.% BSBS-T-TTr,cF|jrtS|t}d|_d|_d|_d|_|j|_|j |_ |j |_ |j rttnd|_ d|_d|_d|_|S)z+Get a copy of the style with color removed.NrF)r;rrr!r=r>rrrrrrrr<r r:r)rs r* without_colorzStyle.without_colors :  ||E** "&  , $ 4j 59ZGD//11R    r,rstyle_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 FrozURL expected after 'link'Tz as color; )rmrnror8)rrSTYLE_ATTRIBUTESitersplitrrrrrrurgetr!) rrrrmrnrrowords original_wordworderror attributers r*ruz 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; )rrrmrnrarWforeground_color get_truecolorr from_tripletrbackground_colorhexrYr[r]rerjr)r)rcssrrmrnr theme_colors r*get_html_stylezStyle.get_html_style3s// , < ,$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.combineX'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.chainerr,c|jrtS|t}|j|_|j|_|j|_|j|_|j|_|j |_ |j |_ |j rttnd|_ |j|_d|_|j|_|S)zwGet a copy of this style. Returns: Style: A new Style instance with identical attributes. rF)r;rrr!r=r>rrrrrrrr<r:r rs r*copyz Style.copyrs :  ||E**j "&"8{  , $ 4j 59ZGD//11Rj  j  r,rzc,|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)r;rrr!r=r>rrrrrr<r:r rs r*clear_meta_and_linkszStyle.clear_meta_and_linkss :  ||E**j "&"8{  , $ 4     r,cH|t}|j|_|j|_|j|_|j|_|j|_|j|_||_|rttnd|_ 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. rNF)rr!r=r>rrrrrrrr<r:r;r )r)rors r* update_linkzStyle.update_links||E**j "&"8{  , $ 4 59AD//11r  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|_|Srs)r;rr!r=r>rrrrrr<r rrpr:)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|_dSrsr)r)rs r*r+zStyleStack.__init__s$1? r,cd|jdS)Nz r!rs r*__repr__zStyleStack.__repr__s.dk....r,c|jdS)z&Get the Style at the top of the stack.r!rs 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) r1r2r3r4r5r+rr$rr!r'r)r+r8r,r*rrs I3333/#////X4%4D4444Ur,r)*r  functoolsr itertoolsroperatorrpicklerrrandomrtypingr r r r r rrrrrrmrrrrreprrrterminal_themerrrrrrr$r!rrr8r,r*r4s IIIIIIIIIIIIIIIIIIIIAAAAAAAAAAAA########AAAAAAAAz j-):GW #w,  kk"oo&&          O PO PO PO PO PO PO P O PdUWW r,