hvUddlZddlmZmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lm Z dd l!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-e r ddl.m/Z/m0Z0m1Z1m2Z2dZ3de4d<dZ5de4d<ej6dZ7ee8dfZ9 e e8gee-fZ:GddeZ;Gdde&Zm/Z/e|r|\}}}t|||z|S|S)zExtend the span by the given number of cells. Args: cells (int): Additional space to add to end of span. Returns: Span: A span. rA)r3rFr,r-r.s r4extendz Span.extendfs3   $ E3sU{E22 2Kr6N)__name__ __module__ __qualname____doc__int__annotations__rstrrr5boolr9rrr?rCrErHr6r4r+r+/s** JJJ HHH e )A#AAAA%$%%%% C E&(62B*B$C     93 96 9 9 9 9 4 4 4 4 4 4 C F      r6r+ceZdZdZgdZ dddddddddedeeefd ed d ed d ee dedee dee e ddfdZ de fdZde fdZdefdZdefdZdeddfdZdede fdZdede fdZdee efddfdZede fdZedefdZeddddddd dedeeefd!e d"eed ed d ed deddfd#Zedddddd$d%dedeeefd ed d ed d ee dedee ddfd&Ze dddd'dede d ed d ed ddf d(Z!edddddd$dd)d*eede"ee ffdeeefd ed d ed d ee dede d+ee#eefddfd,Z$edefd-Z%e%j&d.eddfd/Z%ede e fd0Z'e'j&de e ddfd1Z'dd2eddfd3Z(dd4Z) ddeeefd6e dee ddfd7Z* ddeeefd6e dee ddfd8Z+ dd+e#eefd6e dee ddfd9Z,dd+ee#eefd:eddfd;Z-dd?d@e defdAZ/dBe ddfdCZ0 dddDdEee1eefdeee2e fdFede fdGZ3ddHdIe4edeeefdJe de fdKZ5ddLZ6dMe ddfdNZ7dOe ddfdPZ8d>d?dQdRde4e9fdSZ:d>d?dQdRde;fdTZ
d?dede4dUfdVZ=dWe4dddfdXZ>ddee ddfdYZ?ddZd[d\e d ed d]e ddfd^Z@dd_ZAddae dbeddfdcZBddae dbeddfddZCddae dbeddfdeZDddfeEdge dbeddfdhZF ddedefdeeedifddfdjZGddkZHdle4e"eee fddfdmZIddnZJ ddZdZdodpedqe dre deKfdsZLdte4e deKfduZMddwe ddfdxZNddd$ddyd>d?dge d ed d ed de d ee deKfdzZOdge deKfd{ZPde fd|ZQ dd}d~ddee dbede ddfdZRdS)r)aText with color / style. Args: text (str, optional): Default unstyled text. Defaults to "". style (Union[str, Style], optional): Base style for text. Defaults to "". justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None. end (str, optional): Character to end text with. Defaults to "\\n". tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to None. spans (List[Span], optional). A list of predefined style spans. Defaults to None. ) _textr.justifyoverflowno_wrapr-tab_size_spans_lengthN )rTrUrVr-rWspanstextr.rTr#rUr$rVr-rWr\r/ct|} | g|_||_||_||_||_||_||_|pg|_t| |_ dSr8) rrSr.rTrUrVr-rWrXlenrY) r3r]r.rTrUrVr-rWr\sanitized_texts r4__init__z Text.__init__sc-T22$%  29 4<    "'+2 // r6c|jSr8)rYr2s r4__len__z Text.__len__s |r6c*t|jSr8)rPrYr2s r4r9z Text.__bool__sDL!!!r6c|jSr8plainr2s r4__str__z Text.__str__s zr6c8d|jd|jd|jdS)Nz)rgrXr.r2s r4r5z Text.__repr__s)F FFt{FFtzFFFFr6otherct|ttfr+|}|||St Sr8) isinstancerOr)copyappendNotImplemented)r3rlresults r4__add__z Text.__add__sB ec4[ ) ) YY[[F MM% Mr6czt|tstS|j|jko|j|jkSr8)rnr)rqrgrXr3rls r4__eq__z Text.__eq__s7%&& "! !zU[(HT[EL-HHr6ct|tr ||jvSt|tr|j|jvSdS)NF)rnrOrgr)rus r4 __contains__zText.__contains__sG eS ! ! -DJ& & t $ $ -;$*, ,ur6slicec dtddffd }t|tr ||S|tj\}}}|dkr||g}|dSt d)Nr:r/r)cxttjfdjDd}|S)NcRg|]#\}}}|cxkr|knn dd|$S)rrrQ.0r,r-r._Spanr:s r4 z9Text.__getitem__..get_text_at..sY)sEV,,,,u,,,,,E!Q&&,,,r6rZ)r\r-)r+r)rgrX)r:r]rr3s` @r4 get_text_atz%Text.__getitem__..get_text_atsaE 6"-1[ DKr6rz%slices with step!=1 are not supported)rMrnindicesr_rgdivide TypeError)r3ryrr,stopstepliness` r4 __getitem__zText.__getitem__s         eS ! ! I;u%% % % c$*oo > > E4qyy UDM22Qx GHHHr6c*t|jS)z5Get the number of cells required to render this text.)rrgr2s r4rz Text.cell_lens ###r6cddlm}g}|j}dd|jfgd|jDd|jDt |d|jf}|tddd}|j}|D]C\}}} ||kr||||||}| r||rd | d nd | d Dd |} | S) z~Get console markup to render this Text. Returns: str: A string potentially creating markup tags. r)escaperFc34K|]}|jd|jfVdSFN)r,r.r~spans r4 zText.markup..s- F F$tz5$*- F F F F F Fr6c34K|]}|jd|jfVdSTN)r-r.rs r4rzText.markup..s- C Cttxtz* C C C C C Cr6Tkeyz[/][rZ) markuprrgr.rXr_sortrrpjoin) r3routputrg markup_spanspositionrpr:closingr.rs r4rz Text.markupsB #"""""  tz " F F$+ F F F D Ct{ C C C ZZtz *  jA..///&2 C C "FGU  vveHVO455666! CA}E}}}}\\\\BBB r6T)r.emoji emoji_variantrTrUr-rrcZddlm}|||||} || _|| _|| _| S)aCreate Text instance from markup. Args: text (str): A string containing console markup. style (Union[str, Style], optional): Base style for text. Defaults to "". emoji (bool, optional): Also render emoji code. Defaults to True. emoji_variant (str, optional): Optional emoji variant, either "text" or "emoji". Defaults to None. justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. end (str, optional): Character to end text with. Defaults to "\\n". Returns: Text: A Text instance with markup rendered. r)render)rr)rrrTrUr-) clsr]r.rrrTrUr-r rendered_texts r4 from_markupzText.from_markupsL4 #"""""tU%}UUU ' !)  r6r.rTrUrVr-rWc ddlm}td||||||} |} | d| |D} | S)aCreate a Text object from a string containing ANSI escape codes. Args: text (str): A string containing escape codes. style (Union[str, Style], optional): Base style for text. Defaults to "". justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None. end (str, optional): Character to end text with. Defaults to "\\n". tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to None. r) AnsiDecoderr[)rTrUrVr-rWr.c3K|]}|VdSr8rQr~lines r4rz!Text.from_ansi..Hs"CCdTCCCCCCr6)ansirr)rdecode) rr]r.rTrUrVr-rWrjoinerdecoderrrs r4 from_ansizText.from_ansi%s}. &%%%%%    +--CCgnnT.B.BCCCCC r6rTrUcL||||}|||S)aaConstruct a Text instance with a pre-applied styled. A style applied in this way won't be used to pad the text when it is justified. Args: text (str): A string containing console markup. style (Union[str, Style]): Style to apply to the text. Defaults to "". justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. Returns: Text: A text instance with a style applied to the entire string. r)stylize)rr]r.rTrU styled_texts r4styledz Text.styledKs4*c$(CCC E"""r6)r.rTrUrVr-rWmetapartsrc|||||||} | j} t} |D]*} t| | tfr | | %| | +|r| || S)aConstruct a text instance by combining a sequence of strings with optional styles. The positional arguments should be either strings, or a tuple of string + style. Args: style (Union[str, Style], optional): Base style for text. Defaults to "". justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None. overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None. no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None. end (str, optional): Character to end text with. Defaults to "\\n". tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to None. meta (Dict[str, Any], optional). Meta data to apply to text, or None for no meta data. Default to None Returns: Text: A new text instance. r)rpr)rnrO apply_meta) rr.rTrUrVr-rWrrr]rp_Textparts r4assemblez Text.assembleds6s      D$ -- t   " OOD ! ! ! r6ct|jdkr%d|jg|jdd<|jdS)z Get the text as a single string.rrZNr)r_rSrr2s r4rgz Text.plainsC tz??a  WWTZ001DJqqqMz!}r6new_textc||jkrXt|}|g|jdd<|j}t ||_||jkr|dSdSdS)zSet the text to a new value.N)rgrrSrYr_ _trim_spans)r3rr` old_lengths r4rgz Text.plains{ tz ! !0::N+,DJqqqMJ~..DLDL((  """"" " ! )(r6c|jS)z.Get a reference to the internal list of spans.rXr2s r4r\z Text.spanss {r6c$|dd|_dS)z Set spans.Nr)r3r\s r4r\z Text.spanssAAAh r6rgc nt||j|j|j|j|j|j}|S)zNReturn a new Text instance with copied metadata (but not the string or spans).r)r)r.rTrUrVr-rW)r3rg copy_selfs r4 blank_copyzText.blank_copys? *L]L]   r6c t|j|j|j|j|j|j|j}|j|jdd<|S)zReturn a copy of this instance.rN) r)rgr.rTrUrVr-rWrX)r3rs r4roz Text.copysT J*L]L]   #k r6rr,c |rpt|}|dkr||z}||}|dkr||z}||ks||krdS|jt|t |||dSdS)azApply a style to the text, or a portion of the text. Args: style (Union[str, Style]): Style instance or style definition to apply. start (int): Start offset (negative indexing is supported). Defaults to 0. end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None. rN)r_rXrpr+r<r3r.r,r-lengths r4rz Text.stylizes  EYYFqyy{Qwwsl#,, K  tE3vs+;+;UCC D D D D D E Er6c |rqt|}|dkr||z}||}|dkr||z}||ks||krdS|jdt|t |||dSdS)aApply a style to the text, or a portion of the text. Styles will be applied before other styles already present. Args: style (Union[str, Style]): Style instance or style definition to apply. start (int): Start offset (negative indexing is supported). Defaults to 0. end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None. rN)r_rXinsertr+r<rs r4stylize_beforezText.stylize_befores  HYYFqyy{Qwwsl#,, K  q$uc&#.>.>"F"F G G G G G H Hr6c^tj|}||||dS)agApply metadata to the text, or a portion of the text. Args: meta (Dict[str, Any]): A dict of meta information. start (int): Start offset (negative indexing is supported). Defaults to 0. end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None. )r,r-N)r from_metar)r3rr,r-r.s r4rzText.apply_metas1%% U%S 11111r6handlersc |in|}|d|D|tj||S)aApply event handlers (used by Textual project). Example: >>> from rich.text import Text >>> text = Text("hello world") >>> text.on(click="view.toggle('world')") Args: meta (Dict[str, Any]): Mapping of meta information. **handlers: Keyword args are prefixed with "@" to defined handlers. Returns: Text: Self is returned to method may be chained. Nc i|] \}}d|| S)@rQ)r~rvalues r4 zText.on..s$III*#uYYYIIIr6)updateitemsrrr)r3rrs r4onzText.on s]\rrt II8H8HIIIJJJ U_T**+++ r6suffixc|j|r$|t|dSdS)zaRemove a suffix if it exists. Args: suffix (str): Suffix to remove. N)rgendswithrEr_)r3rs r4 remove_suffixzText.remove_suffixsD :  v & & ) OOCKK ( ( ( ( ( ) )r6consoler!r:c|dkrt||z}|j}||j}|jD]&\}}}||cxkr|krn|||dz }'|S)a Get the style of a character at give offset. Args: console (~Console): Console where text will be rendered. offset (int): Offset in to text (negative indexing supported) Returns: Style: A Style instance. rrZr%)r_ get_styler.rorX)r3rr:rr.r,r- span_styles r4get_style_at_offsetzText.get_style_at_offset(s A::YY'F%  $*%%**,,&*k ; ; "E3 V$$$$u$$$$$:r:::: r6spacescdkrdS|j}dz}|rTt|fd|D|jdd<|j||xjz c_dS|xj|z c_dS)zExtend the Text given number of spaces where the spaces have the same style as the last character. Args: spaces (int): Number of spaces to add to the Text. rNrjcTg|]$}|jkr|n|%SrQ)r-rH)r~r end_offsetrs r4rz%Text.extend_style..HsF(,x:'='= F###4r6)r\r_rXrSrprYrg)r3rr\ new_spacesrs ` @r4 extend_stylezText.extend_style<s Q;; F 6\  %TJ!DKN J  j ) ) ) LLF "LLLL JJ* $JJJJr6) style_prefix re_highlightrc 4d}|jj}t}|j}t |t rt j|}||D]}|j } |rO| \} } t|r||| | n|} | | | kr||| | | |dz }| D]6} | | \} } | dkr | | kr||| | || 7|S)a%Highlight text with a regular expression, where group names are translated to styles. Args: re_highlight (Union[re.Pattern, str]): A regular expression object or string. style (Union[GetStyleCallable, StyleType]): Optional style to apply to whole match, or a callable which accepts the matched text and returns a style. Defaults to None. style_prefix (str, optional): Optional prefix to add to style group names. Returns: int: Number of regex matches rNr) rXrpr+rgrnrOrecompilefinditerrcallable groupdictkeys)r3rr.rcount append_spanrrgmatchget_spanr,r- match_stylenames r4highlight_regexzText.highlight_regexQs[&k(   lC ( ( 4:l33L!**511 L LEzH @%XZZ s9A%SeeE%)$4555e *sU{{KeS+ > >??? QJE))..00 L L%Xd^^ sB;;3;;KeS\2I42I2I J JKKK L r6)case_sensitivewordsrc.dd|D}|jj}d}t}t j||j|rdn tjD]5}|d\} } ||| | ||dz }6|S)aBHighlight words with a style. Args: words (Iterable[str]): Words to highlight. style (Union[str, Style]): Style to apply. case_sensitive (bool, optional): Enable case sensitive matching. Defaults to True. Returns: int: Number of words highlighted. |c3>K|]}tj|VdSr8)rrr~words r4rz'Text.highlight_words..s*>>BIdOO>>>>>>r6rflagsr) rrXrpr+rrrg IGNORECASEr) r3rr.rre_wordsadd_spanrrrr,r-s r4highlight_wordszText.highlight_wordsys"88>>>>>>>;%[ dj^(N     EAJE3 HUU5#u-- . . . QJEE r6cB|j|_dS)z"Strip whitespace from end of text.N)rgrstripr2s r4r z Text.rstripsZ&&(( r6sizect|}||krm||z }t|j}|It|d}|t ||dSdSdS)zRemove whitespace beyond a certain width at the end of the text. Args: size (int): The desired size of the text. Nr)r__re_whitespacesearchrggrouprEr<)r3r  text_lengthexcesswhitespace_matchwhitespace_counts r4 rstrip_endzText.rstrip_ends $ii    4'F-44TZ@@ +#&'7'='=a'@'@#A#A $4f = =>>>>>  ,+r6 new_lengthct|}||kr:||kr|||z dS|||z dSdS)z.s(>>Xd^^>>>>>>r6rc34K|]}t|VdSr8r"rs r4rz(Text.__rich_measure__..s(114111111r6)rg splitlinesmaxr?r)r3rrr]rmax_text_widthrmin_text_widths r4__rich_measure__zText.__rich_measure__sz!!BGN>>>>>>>>Q 5: NC115111 1 1 1 >>:::r6rc#NKt}|j}|js"t|V|r ||VdSt|jt jtt|jd}fd|D|j d<dgd|Dd|Dt|d df}| tdd gj }j}ijt jd t ffd } t#||ddD]J\\} } } \} }}| r || n || | | kr||| | | VK|r||VdSdS) aRender the text as Segments. Args: console (Console): Console instance. end (Optional[str], optional): Optional end character. Returns: Iterable[Segment]: Result of render that may be written to the console. Nrrc8i|]\}}||jSrQr.)r~indexrrs r4rzText.render..s+VVVkeTUIIdj11VVVr6r)rFrc30K|]\}}|jd|fVdSr)r,r~r,rs r4rzText.render..s/ M M[UDtz5%( M M M M M Mr6c30K|]\}}|jd|fVdSrrr.s r4rzText.render..s/ J J+%txu% J J J J J Jr6Trr/ctfdtD}|}||S|}||<|S)z#Construct current style from stack.c3(K|] }|V dSr8rQ)r~ _style_id style_maps r4rz9Text.render..get_current_style..s(OOI9Y/OOOOOOr6)tuplesorted)styles cached_style current_stylecombinestack style_cachestyle_cache_getr3s r4get_current_stylez&Text.render..get_current_stylescOOOOOOOOOF*?622L'###GFOOM"/K  r6)rrgrXrrrnulllist enumerater.r_rrrpremovegetr9zip)r3rr-_Segmentr]enumerated_spansr\ stack_append stack_popr=r:leavingstyle_id next_offset_r9rr:r;r<r3s @@@@@@r4rz Text.rendersZz{ $--    $hsmm### FG-uz||DDD  $+q 9 9::VVVVEUVVV  y,, !   M M.iter_textsqz !"+E"2"2##JD$JJJ#" ## !         r6rc3FK|]\}}}|z|z|VdSr8rQr}s r4rzText.join..*sS%E3funfslE::r6) rr rSrHrXrpr+r.r_rY) r3rrrO extend_textr extend_spansr]rr:s `` @@r4rz Text.join s/??$$ !8F+ ! ! ! ! ! ! !n+ o, - IKK  D K # # #z K EE&&3t99*.{f   zJ&& 8j((U4:s:tx'@'@$*MM'&&r6Nr_rgr+rX)r3rrcs @@r4rzText._trim_spanswsU__           AAAr6rjr characterct|dks Jdr>|z}||j||_tfd|jD|jdd<dSdS)zPad left and right with a given number of characters. Args: count (int): Width of padding. character (str): The character to pad with. Must be a string of length 1. r&Character must be a string of length 1c>g|]\}}}|z|z|SrQrQr~r,r-r.rrs r4rzText.pad..E%E3eemS5[%88r6Nre)r3rrfpad_charactersrs ` @r4rYzText.pads9~~"""$L"""  &.N*HDJHHHDJE)-DKNNN   r6ct|dks Jdr:|z|j|_tfd|jD|jdd<dSdS)zPad the left with a given character. Args: count (int): Number of characters to pad. character (str, optional): Character to pad with. Defaults to " ". rrhc>g|]\}}}|z|z|SrQrQrjs r4rz!Text.pad_left..rkr6Nre)r3rrfrs ` @r4pad_leftz Text.pad_lefts9~~"""$L"""  %-;tz;;DJE)-DKNNN  r6cnt|dks Jd|r|j||z|_dSdS)zPad the right with a given character. Args: count (int): Number of characters to pad. character (str, optional): Character to pad with. Defaults to " ". rrhN)r_rg)r3rrfs r4rzText.pad_rightsS9~~"""$L"""  < J; E(9;;DJJJ < >>>> lI66666 7 7r6rc t|ttfstdt |rt|trt |}|j|t |}t ||r,|jt||z||xj z c_ nt|trt|td|j |j r:|jt |z|j |j|j |jfd|jD|xj t |z c_ |S)zAdd text with an optional style. Args: text (Union[Text, str]): A str or Text to append. style (str, optional): A style name. Defaults to None. Returns: Text: Returns self for chaining. z(Only str or Text can be appended to TextNz2style must not be set when appending Text instancec3FK|]\}}}|z|z|VdSr8rQr~r,r-r.rrs r4rzText.append..sU##)sEE%+-s[/@%HH######r6)rnrOr)rr_rrSrprXr+rY ValueErrorr.rgrHro)r3r]r.r`r:rrs @@r4rpz Text.appends$d ,, HFGG G t99 *$$$ *!4T!:!: !!.111T!.11 RK&&tFF[4H%'P'PQQQ + D$'' *$$L#l :K&&k;T+BDJOO !!$*--- ""#####-1[-=-=-?-?### D )  r6c t|j|jr:|jt |z|j|j|j|jfd|j D|xjt |z c_|S)a Append another Text instance. This method is more performant that Text.append, but only works for Text. Args: text (Text): The Text instance to append to this instance. Returns: Text: Returns self for chaining. c3FK|]\}}}|z|z|VdSr8rQrzs r4rz#Text.append_text..sU  !sE E%+%s['8% @ @      r6) r+rYr.rXrpr_rSrgrHro)r3r]rrs @@r4 append_textzText.append_textsl : X K  uu[+D 2I4:VV W W W $*%%%      %)[%5%5%7%7       D !  r6tokensc (|jj}|jj}t}t |}|D]Y\}}t |}|||r&||||t |z||t |z }Z||_|S)a)Append iterable of str and style. Style may be a Style instance or a str style definition. Args: tokens (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style. Returns: Text: Returns self for chaining. )rSrprXr+r_rrY)r3rr~rrr:contentr.s r4 append_tokenszText.append_tokenssj' k( T$ # #NGU)'22G K  I EE&&3w<<*?GGHHH c'll "FF  r6cD|j|jdS)zCopy styles from another Text instance. Args: text (Text): A Text instance to copy styles from, must be the same length. N)rXrH)r3r]s r4 copy_styleszText.copy_styless" 4;'''''r6)rU allow_blank separatorrUrcs Jd|jvr"t|gS|rE|dt jt jD}nOdttffd }tfd||D}|s) r| |S)aSplit rich text in to lines, preserving styles. Args: separator (str, optional): String to split on. Defaults to "\\n". include_separator (bool, optional): Include the separator in the lines. Defaults to False. allow_blank (bool, optional): Return a blank line if the text ends with a separator. Defaults to False. Returns: List[RichText]: A list of rich text, one per line of the original. zseparator must not be emptyc3>K|]}|VdSr8rr~rs r4rzText.split..?s;   %       r6r/c3KtjtjD]!}|\}}|V|V"dSr8)rrrr)rr,r-rr]s r4 flatten_spansz!Text.split..flatten_spansDs[[9)=)=tDDE!&JE3KKKIIIIr6c32K|]}|jk |VdSr8rf)r~rrs r4rzText.split..Js8yAXAXAXAXAXAXr6) rgrrorrrrr rMrpop)r3rrUrrrr]s ` @r4r?z Text.split's9"77777yz D $))++'' '  KK  )+RYy5I5I4)P)P   EE  8C=        !%]]__!=!=E t}}Y77  IIKKK r6offsetsc t|}|s"t|gS|jt }dg||}tt ||dd}|j|j|jttfd|D}|j s|Sd|j D}t |}t} |j D]\} } d} |} | | zdz} ||\}}| |kr|dz } n | |kr|dz} nn | | zdz}-| |kr|}n4|x}} |} ||\}}| |kr|dz } n | |kr|dz} nn | | zdz}-t||dzD]X}||\}}td| |z }t| |z ||z }||kr||| ||Y|S)zDivide text in to a number of lines at given offsets. Args: offsets (Iterable[int]): Offsets used to divide text. Returns: Lines: New RichText instances between offsets. rrNc3LK|]\}}||VdS))r.rTrUNrQ)r~r,r-rrTrUr.r]s r4rzText.divide..jsb  s EU3Y!          r6c&g|]}|jjSrQ)rXrprs r4rzText.divide..vsIII+IIIr6rv)r?rrorgr_rCr.rTrUr)rX_linesr+ranger%r<)r3r_offsetsrdivide_offsets line_ranges new_lines _line_appends line_countr span_startspan_end lower_bound upper_bound start_line_no line_startline_end end_line_noline_no new_startnew_endrrTrUr.r]s @@@@@r4rz Text.divideSs== ($))++'' 'z$ii 4h4 43~~abb/ABBCC  ,=        *     {  II 8HIII %% +/;$ M$ M 'J%K$K(;61.rdr6N)r_rgr+rXrSrY)r3rrrcs @@r4rEzText.right_crops__v-           AAAj6'*+   r6rc`|p |jpt}|p |jpt}t ||jdp|dk}t } |dD]} d| vr| ||rt | g} n8tt| ||dk} | | } | D]} | ||r| ||||| D]} | || | | | S) aCWord wrap the text. Args: console (Console): Console instance. width (int): Number of cells available per line. justify (str, optional): Justify method: "default", "left", "center", "full", "right". Defaults to "default". overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None. tab_size (int, optional): Default tab size. Defaults to 8. no_wrap (bool, optional): Disable wrapping, Defaults to False. Returns: Lines: Number of lines. Fr[TrrTr')r'r)rU)rTr&rUr(rrVrr?rXrrOrrr^rH) r3rrrrTrUrWrV wrap_justify wrap_overflowrrrrs r4rz Text.wrapsd.A$,A/  EDME5E GT\599QX=QJJ4J00 $ $Dt||  *** 1!4&MM %c$ii]f=TUUU KK00 ! ' '&&&& !!UL="" = = em <<<< LL # # # # r6ct}|j}|D]"}||||#|S)zFit the text in to given width by chopping in to lines. Args: width (int): Maximum characters in a line. Returns: Lines: Lines container. )rrpr?r)r3rrrrprs r4fitzText.fitsQwwJJLL  D OOE " " " F4LLLL r6cdtjd|jtjD} t t d|Dpd}n#t $rd}YnwxYw|S)zrAuto-detect indentation of code. Returns: int: Number of spaces used to indent code. cRh|]$}t|d%Sr)r_rrs r4 z*Text.detect_indentation..s:     A     r6 ^( *)(.*)$rcg|] }|dz| S)rvrQ)r~indents r4rz+Text.detect_indentation..s"RRRvPQzRVRRRr6r)rrrg MULTILINErrr)r3 _indentations indentations r4detect_indentationzText.detect_indentations  ]DJblSSS    sRR-RRRSSXWX K   KKK s!A A#"A#u│z dim green)rfr. indent_sizec||n|}|}||d|dz z}tjd}g}|j} d} |dD]} || j} | r| ds| dz } 9| d} tt| |\}}||zd|z}|| jt|dz| _| |dt|| r*| t|| g| zd} | | | r(| td | g| z|d |}|S) uAdds indent guide lines to text. Args: indent_size (Optional[int]): Size of indentation, or None to auto detect. Defaults to None. character (str, optional): Character to use for indentation. Defaults to "│". style (Union[Style, str], optional): Style of indent guides. Returns: Text: New text with indentation guides. NrjrrrTrrvr+rZr[)rrorXrrrpr?rrgrdivmodr_rrHr)rr)r3rrfr. _indent_sizer] indent_line re_indentradd_line blank_linesrrr full_indentsremaining_space new_indentrs r4with_indent_guideszText.with_indent_guidess$5@4Gt..000[ yy{{ ">C> J}-- " # JJ4J00  DOODJ//E  A q [[^^F,23v;; ,M,M )L/',6Oo8MOOJ#djZ1B1B&CCDJ LL3z?? 3 3 3   $z"?"?"?!@;!NOOO HTNNNN  D   d2U3334{B C C C??4((--i88r6)rZrZ)rZ)r/r))rNr8)r/N)rj)r]r)r/r))r]r)r/N)r[r)SrIrJrKrL __slots__rOrrrrPrMr r+rarcr9rhr5rrsobjectrvrxryrpropertyrr classmethodrrrr rrr rrgsetterr\rrorrrrrrrrGetStyleCallablerr rr rrrrrr(rrrXr^rrYrorrrqrpr~rrrr?rrErrrrrQr6r4r)r)vs      I#%0 .2/3"&"&&*0000S%Z 0 /* 0 +, 0$003-0T #0 0000."$""""G#GGGGSVIFItIIII &TIsEz!2IvIIII4$#$$$X$X: $&04-1/3S%Z     - /*+, [B $&-1/3"&"#####S%Z # /* # +, #$##3-# ###[#J .2/3  /*  +,  [0$&-1/3"&)-+++c65i#889+S%Z +/* + +, + $ +++tCH~&+ +++[+ZsX  \#c#d###\#tDzX \4:$\   V        "! EES%Z EEc] E  EEEE:! HHS%Z HHc] H  HHHH6JN 2 2cN 2+. 29A# 2  2 2 2 2xS#X/CF()C)D))))9ce(%3%4%%%%0?C&  &&&GCL#-.&. 9:;&  & &&&&Z $ }S%Z    :)))) ?s ?t ? ? ? ?5S5T5555; ;+;; ' ;;;;& ;  ;+; ;  ; ; ; ;9 9 i9 c9 8I;N9 9 9 9 v%(6*%v%%%%N('('HSM('T('('('('\04 ////+, /  /  ////6     t"ccD < ? 0((((*#(! **** *  *  ****XMhsmMMMMM^T*.2/3"&..... /* . +, ..$. ....` C.&*.& ...c]. .  .  ......r6__main__)r!a Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Loremboldipsumitaliczjustify='left'redr+zjustify='center'greenru)r.rTzjustify='right'bluerightzjustify='full'magentafull)Cr functoolsrrmathroperatorrtypingrrr r r r r rrrr_loopr_pickr_wraprrqrrFrr containersrcontrolrrrjupyterrmeasurersegmentrr.rr rr!r"r#r$r&rNr(rr rOTextTyperr+r)rIpip._vendor.rich.consoler]rruleprintrQr6r4rs %%%%%%%%                          ********((((((!!!!!! ########POOOOOOOOOOOO#,,,,%+"+++G$$ f 1SE8I#667DDDDD:DDDN<D& z000000 4 P  D 'F+++'H---giiG LL!""" MM$eM$$$ MMOOO LL#$$$ MM$gxM888 MMOOO LL"### MM$fgM666 MMOOO LL!""" MM$iM888 MMOOOOO3r6