U cfи@sBUddlZddlmZmZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZddlmZddlmZdd lmZdd lmZdd lmZmZdd lmZdd l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+m,Z,e rddl-m.Z.m/Z/m0Z0m1Z1dZ2de3d<dZ4de3d<e5dZ6ee7dfZ8e e7gee,fZ9GdddeZ:Gddde%Z;edd l=m.Z.e;d!Z>e>?d"gd#e>?d$gd%e.Z-e-@d&e-jAe>d'd(e-Ae-@d)e-jAe>d*d+d,e-Ae-@d-e-jAe>d.d/d,e-Ae-@d0e-jAe>d1d2d,e-AdS)3N)partialreduce)gcd) itemgetter) TYPE_CHECKINGAnyCallableDictIterableList NamedTupleOptionalTupleUnion) loop_last) pick_bool) divide_line) AlignMethod)cell_len set_cell_size)Lines)strip_control_codes) EmojiVariant) JupyterMixin) Measurement)Segment)Style StyleType)ConsoleConsoleOptions JustifyMethodOverflowMethoddefaultr!DEFAULT_JUSTIFYfoldr"DEFAULT_OVERFLOWz\s+$Textc@seZdZUdZeed<eed<eeefed<edddZ e ddd Z ee de dfd d d Zedd d dZedd ddZeddddZdS)Spanz A marked up region in some text.startendstylereturncCsd|jd|jd|jdS)NzSpan(z, ))r)r*r+selfr1C/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/text.py__repr__8sz Span.__repr__cCs |j|jkSN)r*r)r/r1r1r2__bool__;sz Span.__bool__offsetr-cCsV||jkr|dfS||jkr$|dfS|\}}}t|t|||}t|j||}||fS)z)Split a span in to 2 from a given offset.N)r)r*r(min)r0r7r)r*r+span1span2r1r1r2split>s   z Span.splitcCs|\}}}t|||||S)zMove start and end by a given offset. Args: offset (int): Number of characters to add to start and end. Returns: TextSpan: A new TextSpan with adjusted position. r(r0r7r)r*r+r1r1r2moveKs z Span.movecCs(|\}}}||kr|St|t|||S)zCrop the span at the given offset. Args: offset (int): A value between start and end. Returns: Span: A new (possibly smaller) span. )r(r8r=r1r1r2 right_cropWs zSpan.right_crop)cellsr-cCs&|r|\}}}t||||S|SdS)zExtend the span by the given number of cells. Args: cells (int): Additional space to add to end of span. Returns: Span: A span. Nr<)r0r@r)r*r+r1r1r2extendes  z Span.extendN)__name__ __module__ __qualname____doc__int__annotations__rstrrr3boolr5rr r;r>r?rAr1r1r1r2r(.s   r(c @seZdZdZdddddddd d g Zdd d d d d d deeeefededee eee ee e d d ddZ e dddZe dddZedddZedddZeddddZee dd d!Zee dd"d#Zee efdd$d%d&Zee dd'd(Zeedd)d*Zed d+d d d d d,eeeefe eeedededd-d.d/Zed d d d d d0d1eeeefededee eee dd2d3d4Zedd d d5ee ededdd6d7d8Z!ed d d d d d0d d9eede"ee ffeeefededee ee ee#eefdd: d;d<Z$eedd=d>Z%e%j&ed d?d@d>Z%ee e ddAdBZ'e'j&e e d dCdDdBZ'deddEdFdGZ(dddHdIZ)deeefe ee d dKdLdMZ*deeefe ee d dKdNdOZ+de#eefe ee d dPdQdRZ,dee#eefeddSdTdUZ-ed dVdWdXZ.dYe edZd[d\Z/e d d]d^d_Z0dd d`eeee1e fee dadbdcZ2d+dde3eeeefe e dedfdgZ4d ddhdiZ5e d djdkdlZ6e d dmdndoZ7dYdpe3e8dqdrdsZ9dYdpe:dqdtduZ;ddYee3dvdwdxdyZd dde ede d dddZ?d dddZ@de ed dddZAde ed dddZBde ed dddZCdeDe ed dddZEdedefeeedfddddZFdddddZGe3e"eee fddddZHdd dddZIddddee e eJdddZKe3e eJdddZLde d dddZMd d d0d ddYe edede ee eJdddZNe eJdddZOe dddZPddddee ee ddddZQd S)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 )rKrLrMr*rNspansr!r") textr+rKrLrMr*rNrSr-c CsLt|} | g|_||_||_||_||_||_||_|p:g|_t | |_ dSr4) rrJr+rKrLrMr*rNrOlenrP) r0rTr+rKrLrMr*rNrSsanitized_textr1r1r2__init__s  z Text.__init__r,cCs|jSr4)rPr/r1r1r2__len__sz Text.__len__cCs t|jSr4)rIrPr/r1r1r2r5sz Text.__bool__cCs|jSr4plainr/r1r1r2__str__sz Text.__str__cCsd|jd|jdS)Nz)rZrOr/r1r1r2r3sz Text.__repr__)otherr-cCs(t|ttfr$|}|||StSr4) isinstancerHr'copyappendNotImplemented)r0r^resultr1r1r2__add__s  z Text.__add__cCs&t|tstS|j|jko$|j|jkSr4)r_r'rbrZrOr0r^r1r1r2__eq__s z Text.__eq__cCs.t|tr||jkSt|tr*|j|jkSdS)NF)r_rHrZr'rer1r1r2 __contains__s     zText.__contains__)slicer-csftddfdd }t|tr&||S|tj\}}}|dkrZ||g}|dStddS)Nr'r6cs.ttjfddjDdd}|S)Ncs6g|].\}}}|kr"|krnqdd|qS)rrr1.0r)r*r+_Spanr7r1r2 s  z9Text.__getitem__..get_text_at..rQ)rSr*)r(r'rZrO)r7rTr/rkr2 get_text_ats  z%Text.__getitem__..get_text_atrz%slices with step!=1 are not supported)rFr_indicesrUrZdivide TypeError)r0rhrnr)stopsteplinesr1r/r2 __getitem__s zText.__getitem__cCs t|jS)z5Get the number of cells required to render this text.)rrZr/r1r1r2rsz Text.cell_lenc Csddlm}g}|j}dd|jffdd|jDdd|jDt|d|jff}|jtddd d}|j}|D]N\}}} ||kr||||||}| rr||rd | d n d | d qrd |} | S)z~Get console markup to render this Text. Returns: str: A string potentially creating markup tags. r)escaperFcss|]}|jd|jfVqdSFN)r)r+rjspanr1r1r2 szText.markup..css|]}|jd|jfVqdSTN)r*r+rxr1r1r2rzsTkeyz[/][rQ) markuprvrZr+rOrUsortrrajoin) r0rvoutputrZ markup_spanspositionrar7closingr+rr1r1r2rs(  " z Text.markupT)r+emoji emoji_variantrKrLr*)rTr+rrrKrLr*r-c Cs2ddlm}|||||d} || _|| _|| _| 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)rrrKrLr*) clsrTr+rrrKrLr*r rendered_textr1r1r2 from_markups  zText.from_markupr+rKrLrMr*rN)rTr+rKrLrMr*rNr-c CsFddlm}td||||||d} |} | dd| |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) AnsiDecoderrR)rKrLrMr*rNr+css|] }|VqdSr4r1rjliner1r1r2rzGsz!Text.from_ansi..)ansirr'rdecode) rrTr+rKrLrMr*rNrjoinerdecoderrcr1r1r2 from_ansi$s  zText.from_ansirKrL)rTr+rKrLr-cCs||||d}|||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)rrTr+rKrL styled_textr1r1r2styledJs z Text.styled)r+rKrLrMr*rNmeta) partsr+rKrLrMr*rNrr-c GsZ|||||||d} | j} t} |D]$} t| | tfr>| | q"| | q"|rV| || 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)rar'r_rH apply_meta) rr+rKrLrMr*rNrrrTra_Textpartr1r1r2assemblecs"   z Text.assemblecCs0t|jdkr&d|jg|jdd<|jdS)z Get the text as a single string.rrQNr)rUrJrr/r1r1r2rZsz Text.plain)new_textr-cCsH||jkrDt|}|g|jdd<|j}t||_||jkrD|dS)zSet the text to a new value.N)rZrrJrPrU _trim_spans)r0rrV old_lengthr1r1r2rZs   cCs|jS)z.Get a reference to the internal list of spans.rOr/r1r1r2rSsz Text.spans)rSr-cCs|dd|_dS)z Set spans.Nr)r0rSr1r1r2rSs)rZr-c Cs&t||j|j|j|j|j|jd}|S)zNReturn a new Text instance with copied metadata (but not the string or spans).r)r'r+rKrLrMr*rN)r0rZ copy_selfr1r1r2 blank_copys zText.blank_copyc Cs8t|j|j|j|j|j|j|jd}|j|jdd<|S)zReturn a copy of this instance.rN) r'rZr+rKrLrMr*rNrO)r0rr1r1r2r`s z Text.copyr)r+r)r*r-cCsj|rft|}|dkr||}|dkr(|}|dkr8||}||ksH||krLdS|jt|t|||dS)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)rUrOrar(r8r0r+r)r*lengthr1r1r2rs z Text.stylizecCsl|rht|}|dkr||}|dkr(|}|dkr8||}||ksH||krLdS|jdt|t|||dS)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)rUrOinsertr(r8rr1r1r2stylize_befores zText.stylize_before)rr)r*r-cCst|}|j|||ddS)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)r0rr)r*r+r1r1r2rs zText.apply_meta)rhandlersr-cKs<|dkr in|}|dd|D|t||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. NcSsi|]\}}d||qS)@r1)rjr}valuer1r1r2 szText.on..)updateitemsrrr)r0rrr1r1r2on szText.on)suffixr-cCs|j|r|t|dS)zaRemove a suffix if it exists. Args: suffix (str): Suffix to remove. N)rZendswithr?rU)r0rr1r1r2 remove_suffixs zText.remove_suffixr)consoler7r-cCsf|dkrt||}|j}||j}|jD]2\}}}||krL|kr.nq.|||dd7}q.|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. rrQr#)rU get_styler+r`rO)r0rr7rr+r)r* span_styler1r1r2get_style_at_offset's  zText.get_style_at_offset)spacesr-csrdkr dS|j}d}|r`t|fdd|D|jdd<|j||j7_n|j|7_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. rNr\cs$g|]}|jkr|n|qSr1)r*rArxZ end_offsetrr1r2rmGsz%Text.extend_style..)rSrUrOrJrarPrZ)r0rrSZ new_spacesr1rr2 extend_style;s  zText.extend_style) style_prefix) re_highlightr+rr-cCsd}|jj}t}|j}t||D]}|j} |rv| \} } t|rR||| | n|} | dk rv| | krv||| | | |d7}| D]8} | | \} } | dkr| | kr||| | || qq"|S)aHighlight text with a regular expression, where group names are translated to styles. Args: re_highlight (str): A regular expression. 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) rOrar(rZrefinditerrycallable groupdictkeys)r0rr+rcount append_spanrlrZmatchget_spanr)r* match_stylenamer1r1r2highlight_regexPs"  zText.highlight_regex)case_sensitive)wordsr+rr-c Cspddd|D}|jj}d}t}tj||j|r6dntjdD]*}|d\} } ||| | ||d7}q@|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. |css|]}t|VqdSr4)rrvrjwordr1r1r2rzsz'Text.highlight_words..rflagsr) rrOrar(rrrZ IGNORECASEry) r0rr+rre_wordsadd_spanrrlrr)r*r1r1r2highlight_wordsvs  zText.highlight_wordscCs|j|_dS)z"Strip whitespace from end of text.N)rZrstripr/r1r1r2rsz Text.rstrip)sizer-cCsNt|}||krJ||}t|j}|dk rJt|d}|t||dS)zRemove whitespace beyond a certain width at the end of the text. Args: size (int): The desired size of the text. Nr)rU_re_whitespacesearchrZgroupr?r8)r0r text_lengthexcesswhitespace_matchwhitespace_countr1r1r2 rstrip_ends zText.rstrip_end) new_lengthr-cCs:t|}||kr6||kr(|||n|||dS)z.rcss|]}t|VqdSr4rrr1r1r2rzs)rZ splitlinesmaxr;r)r0rrrTrtmax_text_widthrmin_text_widthr1r1r2__rich_measure__szText.__rich_measure__r)rr*r-c#sXt}|j}|js,t|V|r(||VdSt|jtdtt|jd}fdd|D|j d<ddd |Dd d |Dt |d dff}|j t ddd gj }j}ijtjtd fdd } t||ddD]J\\} } } \} }}| r|| n|| | | kr||| | | Vq|rT||VdS)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. Nrrcsi|]\}}||jqSr1r+rjindexry)rr1r2rszText.render..rrFrcss|]\}}|jd|fVqdSrw)r)rr1r1r2rzszText.render..css|]\}}|jd|fVqdSr{rrr1r1r2rzsTr|r,csBtfddtD}|}|dk r.|S|}||<|S)z#Construct current style from stack.c3s|]}|VqdSr4r1)rj _style_id) style_mapr1r2rzsz9Text.render..get_current_style..N)tuplesorted)styles cached_style current_style)combinestack style_cachestyle_cache_getrr1r2get_current_stylesz&Text.render..get_current_style)r)rrZrOrrrnulllist enumerater+rUrrraremovegetrzip)r0rr*_SegmentrTenumerated_spansrS stack_append stack_poprr7leavingstyle_id next_offset_r1)rrrrrrr2rsB       & z Text.render)rtr-cs}tddfdd }|jj}|jj}|jj}dt|D]T}||j|jrt|t||j|fdd|jDt|7qF|_ |S)zJoin text together with this instance as the separator. Args: lines (Iterable[Text]): An iterable of Text instances to join. Returns: Text: A new text instance containing join text. r'r,c3s8jr*tD]\}}|V|sVqn EdHdSr4)rZr)lastr)rtr0r1r2 iter_texts  zText.join..iter_textrc3s(|] \}}}|||VqdSr4r1rirkr1r2rz'szText.join..) rr rJrArOrar(r+rUrP)r0rtrr extend_textr extend_spansrTr1)rlrtr7r0r2rs"    z Text.join)rNr-c Csd|jkrdS|dkr|j}|dkr(d}g}|j}|jdddD]}d|jkrX||q@d}|jddd}|D]p}|jdr|jdddd |jd<||j7}||}|r||} || || 7}n ||j7}||qnq@td  |} | jg|_t |j|_ | j |j dd<dS) ztConverts tabs to spaces. Args: tab_size (int, optional): Size of tabs. Defaults to 8.  NrrRT)include_separatorrrr\rQ) rZrNrar;rrJrrr'rrUrPrO) r0rNrrarZ cell_positionrrZ tab_remainderrrcr1r1r2 expand_tabs/s8           zText.expand_tabsF)rLpad)rrLrr-cCs|p |jp t}|dkrt|j}||krV|dkrHt|j|dd|_nt|j||_|r||kr||}|jd|g|_t|j|_dS)auTruncate text if it is longer that a given width. Args: max_width (int): Maximum number of characters in text. overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow. pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False. ignoreellipsisru…r\N)rLr&rrZrrJrUrP)r0rrLr _overflowrrr1r1r2truncateYs  z Text.truncatecs2t|jtfdd|jD|jdd<dS)z=Remove or modify any spans that are over the end of the text.cs<g|]4}|jkr|jkr |n|jt|j|jqSr1r)r*r8r+rxrl max_offsetr1r2rmxs  z$Text._trim_spans..N)rUrZr(rOr/r1rr2rts   zText._trim_spansr\)r characterr-cs\t|dkstdrX|}||j||_tfdd|jD|jdd<dS)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 1cs&g|]\}}}|||qSr1r1rirlrr1r2rmszText.pad..NrUAssertionErrorrZr(rO)r0rrpad_charactersr1r!r2rs zText.padcsTt|dkstdrP||j|_tfdd|jD|jdd<dS)zPad the left with a given character. Args: count (int): Number of characters to pad. character (str, optional): Character to pad with. Defaults to " ". rr cs&g|]\}}}|||qSr1r1rir!r1r2rmsz!Text.pad_left..Nr"r0rrr1r!r2pad_lefts z Text.pad_leftcCs0t|dkstd|r,|j|||_dS)zPad the right with a given character. Args: count (int): Number of characters to pad. character (str, optional): Character to pad with. Defaults to " ". rr N)rUr#rZr%r1r1r2rszText.pad_right)alignwidthrr-cCsp|||t|j}|rl|dkr2|||n:|dkr`|d}|||||||n |||dS)zAlign text to a given width. Args: align (AlignMethod): One of "left", "center", or "right". width (int): Desired width. character (str, optional): Character to pad with. Defaults to " ". leftcenterN)rrrZrr&)r0r'r(r excess_spacer)r1r1r2r's  z Text.alignr)rTr+r-cst|ttfstdt|rt|trxt|}|j|t|}t||rh|jt ||||j 7_ nt|trt |dk rt d|j |j r|jt||j |j|j |jfdd|jD|j t|7_ |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 instancec3s(|] \}}}|||VqdSr4r1rirlrr1r2rzszText.append..)r_rHr'rqrUrrJrarOr(rP ValueErrorr+rZrA)r0rTr+rVr7r1r-r2ras8    z Text.append)rTr-cspt|j|jr.|jt||j|j|j|jfdd|jD|jt|7_|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. c3s(|] \}}}|||VqdSr4r1rir-r1r2rzsz#Text.append_text..) r(rPr+rOrarUrJrZrAr0rTr1r-r2 append_texts zText.append_text)tokensr-cCsd|jj}|jj}t}t|}|D]8\}}|||rL||||t|||t|7}q ||_|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. )rJrarOr(rUrP)r0r1r0rrlr7contentr+r1r1r2 append_tokenss  zText.append_tokenscCs|j|jdS)zCopy styles from another Text instance. Args: text (Text): A Text instance to copy styles from, must be the same length. N)rOrAr/r1r1r2 copy_stylesszText.copy_styles)r allow_blank) separatorrr5r-css td|jkr(t|gS|rP|ddttD}n6tt dfdd }tfdd||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 emptycss|]}|VqdSr4rrjrr1r1r2rz;szText.split..r,c3s4ttD]}|\}}|V|VqdSr4)rrrvry)rr)r*r6rTr1r2 flatten_spans@s z!Text.split..flatten_spansc3s|]}|jkr|VqdSr4rYr)r6r1r2rzFs ) r#rZrr`rprrrvr rFrpop)r0r6rr5rtr9r1r8r2r;#s     z Text.split)offsetsr-cst|}|st|gS|jt}d ||f}tt||dd}|j|j|jt tfdd|D}|j s|Sdd|j D}t|}t } |j D]$\} } d} |} | | d}||\}}| |kr|d} n| |kr|d} nq | | d}q| |kr|}nT|}} |} ||\}}| |krH|d} n| |krp|d} nqp| | d}q(t ||dD]P}||\}}td| |}t| |||}||kr~||| ||q~q|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. rrNc3s*|]"\}}||dVqdS))r+rKrLNr1)rjr)r*rrKrLr+rTr1r2rzfs zText.divide..cSsg|] }|jjqSr1)rOrarr1r1r2rmrszText.divide..r+)r)rrr`rZrUrr+rKrLr'rO_linesr(rangerr8)r0r;_offsetsrdivide_offsets line_ranges new_lines _line_appends line_countrl span_startspan_end lower_bound upper_bound start_line_no line_startline_end end_line_noline_no new_startnew_endr1r<r2rpOs`               z Text.divider)amountr-csXt|j|tfdd|jD|jdd<|jd| g|_|j|8_dS)z7Remove a number of characters from the end of the text.cs<g|]4}|jkr|jkr |n|jt|j|jqSr1rrxrr1r2rms  z#Text.right_crop..N)rUrZr(rOrJrP)r0rPr1rr2r?s  zText.right_cropr)rr(rKrLrNrMr-c Cs|p |jp t}|p|jpt}t||jdp0|dk}t} |jddD]} d| krZ| ||rjt| g} n t t | ||dkd} | | } | D]} | |q|r| j||||d| D]} | j ||d q| | qD| 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. FrTr5rr%)r%r)rL)rKr$rLr&rrMrr;rrrHrprrrA) r0rr(rKrLrNrM wrap_justify wrap_overflowrtrrBr;r1r1r2rs0     z Text.wrap)r(r-cCs0t}|j}|D]}||||q|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. )rrar;r)r0r(rtrarr1r1r2fits    zText.fitcCsXddtjd|jtjdD}zttdd|Dp6d}Wntk rRd}YnX|S)zrAuto-detect indentation of code. Returns: int: Number of spaces used to indent code. cSsh|]}t|dqS)r)rUrr7r1r1r2 sz*Text.detect_indentation.. ^( *)(.*)$rcSsg|]}|ds|qS)r+r1)rjindentr1r1r2rmsz+Text.detect_indentation..r)rrrZ MULTILINErrrq)r0 _indentations indentationr1r1r2detect_indentations zText.detect_indentationu│z dim green)rr+) indent_sizerr+r-cCs:|dkr|n|}|}||d|d}td}g}|j} d} |jddD]} || j} | rz| ds| d7} q\| d} t t | |\}}||d|}|| jt |d| _| |dt || r| t||d g| d} | | q\| r&| td |d g| |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. Nr\rrVrTrQr+rrQrR)r[r`rrcompilerar;rrZrdivmodrUrrAr'rr)r0r\rr+ _indent_sizerT indent_line re_indentrBadd_line blank_linesrrrW full_indentsremaining_space new_indentrr1r1r2with_indent_guidess4    zText.with_indent_guides)rQrQ)rQ)rQ)rN)rN)rN)N)N)rQ)N)r\)r\)r\)r\)N)rR)r)N)RrBrCrDrE __slots__rHrrr rIrFr r(rWrXr5r[r3rrdobjectrfrgrhrupropertyrr classmethodrrrrrrr rrZsetterrSrr`rrrrrrrGetStyleCallablerr rrrrrrrrrrrrrrr&rrr'rar0r3r4rr;rpr?rrTr[rgr1r1r1r2r'us    ! % -           +     ;'.    ,   ,O 0__main__)ra 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. ZLoremboldZipsumitaliczjustify='left'redrzjustify='center'greenr*)r+rKzjustify='right'bluerightzjustify='full'magentafull)Br functoolsrrmathroperatorrtypingrrrr r r r r rr_loopr_pickr_wraprr'rr@rr containersrcontrolrrrjupyterrmeasurersegmentrr+rrrrr r!r"r$rGr&r]rrHTextTypermr(r'rBpip._vendor.rich.consolerTrruleprintr1r1r1r2sn  0              GH