HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: sport3497 (1034)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/__pycache__/text.cpython-310.pyc
o

��h���@sJUddlZddlmZmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZddlmZddlmZdd	lmZdd
lmZddlmZmZdd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<e�6d�Z7ee8dfZ9	ee8gee-fZ:Gdd�de�Z;Gdd�de&�Z<e=dk�r#dd l>m/Z/e<d!�Z?e?�@d"gd#�e?�@d$gd%�e/�Z.e.�Ad&�e.jBe?d'd(�e.�B�e.�Ad)�e.jBe?d*d+d,�e.�B�e.�Ad-�e.jBe?d.d/d,�e.�B�e.�Ad0�e.jBe?d1d2d,�e.�B�dSdS)3�N)�partial�reduce)�gcd)�
itemgetter)�
TYPE_CHECKING�Any�Callable�Dict�Iterable�List�
NamedTuple�Optional�Pattern�Tuple�Union�)�	loop_last)�	pick_bool)�divide_line)�AlignMethod)�cell_len�
set_cell_size)�Lines)�strip_control_codes)�EmojiVariant)�JupyterMixin)�Measurement)�Segment)�Style�	StyleType)�Console�ConsoleOptions�
JustifyMethod�OverflowMethod�defaultr"�DEFAULT_JUSTIFY�foldr#�DEFAULT_OVERFLOWz\s+$�Textc@s�eZdZUdZeed<	eed<	eeefed<	defdd�Z	de
fdd	�Zd
edede
dffdd�Zd
eddfd
d�Zd
eddfdd�Zdeddfdd�ZdS)�Spanz A marked up region in some text.�start�end�style�returncCsd|j�d|j�d|j�d�S)NzSpan(z, �))r*r+r,��self�r1�@/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/text.py�__repr__9�z
Span.__repr__cCs|j|jkS�N)r+r*r/r1r1r2�__bool__<sz
Span.__bool__�offsetcCsV||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,�span1�span2r1r1r2�split?s


z
Span.splitcCs|\}}}t|||||�S)z�Move 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,r1r1r2�moveLs
	z	Span.movecCs(|\}}}||kr|St|t||�|�S)z�Crop 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_cropXs
	zSpan.right_crop�cellscCs"|r|\}}}t||||�S|S)z�Extend the span by the given number of cells.

        Args:
            cells (int): Additional space to add to end of span.

        Returns:
            Span: A span.
        r<)r0r@r*r+r,r1r1r2�extendfs	
zSpan.extendN)�__name__�
__module__�__qualname__�__doc__�int�__annotations__r�strrr3�boolr6rr
r;r>r?rAr1r1r1r2r)/s

r)c@s�eZdZdZgd�Z		d�ddddddd�dedeeefd	ed
dedd
ee	dedee
deeeddfdd�Z
de
fdd�Zde	fdd�Zdefdd�Zdefdd�Zdeddfdd�Zdede	fdd �Zdede	fd!d"�Zd#ee
efddfd$d%�Zede
fd&d'��Zedefd(d)��Zedd*ddddd+�dedeeefd,e	d-eed	ed
deddeddfd.d/��Zedddddd0d1�dedeeefd	ed
dedd
ee	dedee
ddfd2d3��Ze	d�ddd4�dede d	ed
dedddf
d5d6��Z!edddddd0dd7�d8eede"ee ffdeeefd	ed
dedd
ee	dede
d9ee#eefddfd:d;��Z$edefd<d=��Z%e%j&d>eddfd?d=��Z%edeefd@dA��Z'e'j&deeddfdBdA��Z'd�dCeddfdDdE�Z(d�dFdG�Z)	H	d�deeefdIe
dee
ddfdJdK�Z*	H	d�deeefdIe
dee
ddfdLdM�Z+	d�d9e#eefdIe
dee
ddfdNdO�Z,d�d9ee#eefdPeddfdQdR�Z-dSeddfdTdU�Z.dVdWdXe
defdYdZ�Z/d[e
ddfd\d]�Z0	d�dd^�d_ee1eefdeee2e fd`ede
fdadb�Z3d*dc�dde4edeeefdee	de
fdfdg�Z5d�dhdi�Z6dje
ddfdkdl�Z7dme
ddfdndo�Z8dVdWdpdqde4e9fdrds�Z:dVdWdpdqde;fdtdu�Z<d�dVdWdede4dvfdwdx�Z=dye4dddfdzd{�Z>d�dee
ddfd|d}�Z?dd~d�d�e
dedd�e	ddfd�d��Z@d�d�d��ZAd�d�e
d�eddfd�d��ZBd�d�e
d�eddfd�d��ZCd�d�e
d�eddfd�d��ZDd�d�eEd�e
d�eddfd�d��ZF	d�dedefdeeed�fddfd�d��ZGd�d�d��ZHd�e4e"eee fddfd�d��ZId�d�d��ZJ	d�d~d~d��d�ed�e	d�e	deKfd�d��ZLd�e4e
deKfd�d��ZMd�d�e
ddfd�d��ZNddd0dd��dVdWd�e
d	ed
dedde
d
ee	deKfd�d��ZOd�e
deKfd�d��ZPde
fd�d��ZQ	d�d�d�d��d�ee
d�ede ddfd�d��ZRdS)�r(a�Text 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,�justify�overflow�no_wrapr+�tab_size�_spans�_length�N�
)rKrLrMr+rN�spans�textr,rKr"rLr#rMr+rNrSr-c
CsLt|�}	|	g|_||_||_||_||_||_||_|pg|_t	|	�|_
dSr5)rrJr,rKrLrMr+rNrO�lenrP)
r0rTr,rKrLrMr+rNrS�sanitized_textr1r1r2�__init__�s
z
Text.__init__cC�|jSr5)rPr/r1r1r2�__len__��zText.__len__cC�
t|j�Sr5)rIrPr/r1r1r2r6�s
z
Text.__bool__cCrXr5��plainr/r1r1r2�__str__�rZzText.__str__cCsd|j�d|j�d|j�d�S)Nz<text � �>)r]rOr,r/r1r1r2r3�r4z
Text.__repr__�othercCs(t|ttf�r|��}|�|�|StSr5)�
isinstancerHr(�copy�append�NotImplemented)r0ra�resultr1r1r2�__add__�s

zText.__add__cCs&t|t�stS|j|jko|j|jkSr5)rbr(rer]rO�r0rar1r1r2�__eq__�s
zText.__eq__cCs.t|t�r
||jvSt|t�r|j|jvSdS)NF)rbrHr]r(rhr1r1r2�__contains__�s



zText.__contains__�slicecsddtddf�fdd�}t|t�r||�S|�t�j��\}}}|dkr.��||g�}|dStd��)Nr7r-r(cs.t�t�j���fdd��jD�dd�}|S)Ncs6g|]\}}}|�kr|krnn�dd|��qS)rrr1��.0r*r+r,��_Spanr7r1r2�
<listcomp>�s

�z9Text.__getitem__.<locals>.get_text_at.<locals>.<listcomp>rQ)rSr+)r)r(r]rO)r7rTr/rnr2�get_text_at�s��	z%Text.__getitem__.<locals>.get_text_atrz%slices with step!=1 are not supported)rFrb�indicesrUr]�divide�	TypeError)r0rkrqr*�stop�step�linesr1r/r2�__getitem__�s

zText.__getitem__cCr[)z5Get the number of cells required to render this text.)rr]r/r1r1r2r�s
z
Text.cell_lencCs�ddlm}g}|j}dd|jfgdd�|jD��dd�|jD��t|�d|jf�}|jtdd�d	�d}|j}|D]'\}}}	||krO|||||���|}|	ra||rZd
|	�d�nd|	�d��q:d
�	|�}
|
S)z~Get console markup to render this Text.

        Returns:
            str: A string potentially creating markup tags.
        r)�escaperFcs��|]
}|jd|jfVqdS�FN)r*r,�rm�spanr1r1r2�	<genexpr>���zText.markup.<locals>.<genexpr>csrz�TN)r+r,r|r1r1r2r~�rT��keyz[/�]�[rQ)
�markupryr]r,rOrU�sortrrd�join)r0ry�outputr]�markup_spans�positionrdr7�closingr,r�r1r1r2r��s.
���� �
zText.markupT)r,�emoji�
emoji_variantrKrLr+r�r�c
Cs2ddlm}|||||d�}	||	_||	_||	_|	S)a�Create 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)r�r�)r�r�rKrLr+)
�clsrTr,r�r�rKrLr+r��
rendered_textr1r1r2�from_markupszText.from_markup��r,rKrLrMr+rNc	CsFddlm}td||||||d�}	|�}
|	�dd�|
�|�D��}|S)a�Create 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�|]}|VqdSr5r1�rm�liner1r1r2r~Hs�z!Text.from_ansi.<locals>.<genexpr>)�ansir�r(r��decode)r�rTr,rKrLrMr+rNr��joiner�decoderrfr1r1r2�	from_ansi%s�	zText.from_ansi�rKrLcCs||||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)r�rTr,rKrL�styled_textr1r1r2�styledKs
zText.styled)r,rKrLrMr+rN�meta�partsr�c
GsZ|||||||d�}	|	j}
t}|D]}t||tf�r|
|�q|
|�q|r+|	�|�|	S)a�Construct 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�)rdr(rbrH�
apply_meta)
r�r,rKrLrMr+rNr�r�rTrd�_Text�partr1r1r2�assembleds"�


z
Text.assemblecCs0t|j�dkrd�|j�g|jdd�<|jdS)z Get the text as a single string.rrQNr)rUrJr�r/r1r1r2r]�s
z
Text.plain�new_textcCsP||jkr$t|�}|g|jdd�<|j}t|�|_||jkr&|��dSdSdS)zSet the text to a new value.N)r]rrJrPrU�_trim_spans)r0r�rV�
old_lengthr1r1r2r]�s


�cCrX)z.Get a reference to the internal list of spans.�rOr/r1r1r2rS�sz
Text.spanscCs|dd�|_dS)z
Set spans.Nr�)r0rSr1r1r2rS�sr]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)r0r]�	copy_selfr1r1r2�
blank_copy�s�	zText.blank_copyc	Cs8t|j|j|j|j|j|j|jd�}|j|jdd�<|S)zReturn a copy of this instance.r�N)	r(r]r,rKrLrMr+rNrO)r0r�r1r1r2rc�s�	z	Text.copyrr*cCsn|r5t|�}|dkr||}|dur|}|dkr||}||ks$||kr&dS|j�t|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)rUrOrdr)r8�r0r,r*r+�lengthr1r1r2r��s
�zText.stylizecCsp|r6t|�}|dkr||}|dur|}|dkr||}||ks$||kr&dS|j�dt|t||�|��dSdS)a�Apply 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)rUrO�insertr)r8r�r1r1r2�stylize_before�s
 �zText.stylize_beforecCst�|�}|j|||d�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�)r0r�r*r+r,r1r1r2r��s
zText.apply_meta�handlerscKs<|durin|}|�dd�|��D��|�t�|��|S)a�Apply 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)rmr��valuer1r1r2�
<dictcomp>�zText.on.<locals>.<dictcomp>)�update�itemsr�rr�)r0r�r�r1r1r2�onszText.on�suffixcCs"|j�|�r|�t|��dSdS)zaRemove a suffix if it exists.

        Args:
            suffix (str): Suffix to remove.
        N)r]�endswithr?rU)r0r�r1r1r2�
remove_suffixs�zText.remove_suffix�consoler r7cCsf|dkr
t|�|}|j}||j���}|jD]\}}}||kr&|kr0nq|||dd�7}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.
        rrQ�r$)rU�	get_styler,rcrO)r0r�r7r�r,r*r+�
span_styler1r1r2�get_style_at_offset(s�zText.get_style_at_offset�spacescst�dkrdS|j}d�}|r1t|����fdd�|D�|jdd�<|j�|�|j�7_dS|j|7_dS)z�Extend 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|]}|j�kr|���n|�qSr1)r+rAr|��
end_offsetr�r1r2rpHs��z%Text.extend_style.<locals>.<listcomp>)rSrUrOrJrdrPr])r0r�rS�
new_spacesr1r�r2�extend_style<s�zText.extend_style)�style_prefix�re_highlightr�cCs�d}|jj}t}|j}t|t�rt�|�}|�|�D]Q}|j	}	|rD|	�\}
}t
|�r2|||
|��n|}|durD||
krD|||
||��|d7}|����D]}
|	|
�\}
}|
dkrj||
krj|||
||�|
����qNq|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���)
rOrdr)r]rbrH�re�compile�finditerr}�callable�	groupdict�keys)r0r�r,r��count�append_spanror]�match�get_spanr*r+�match_style�namer1r1r2�highlight_regexQs*


��zText.highlight_regex)�case_sensitive�wordsr�cCspd�dd�|D��}|jj}d}t}tj||j|rdntjd�D]}|�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�|�VqdSr5)r�ry�rm�wordr1r1r2r~�s�z'Text.highlight_words.<locals>.<genexpr>r��flagsr)	r�rOrdr)r�r�r]�
IGNORECASEr})r0r�r,r��re_words�add_spanr�ror�r*r+r1r1r2�highlight_wordsys
�
zText.highlight_wordscCs|j��|_dS)z"Strip whitespace from end of text.N)r]�rstripr/r1r1r2r��szText.rstrip�sizecCsVt|�}||kr'||}t�|j�}|dur)t|�d��}|�t||��dSdSdS)z�Remove whitespace beyond a certain width at the end of the text.

        Args:
            size (int): The desired size of the text.
        Nr)rU�_re_whitespace�searchr]�groupr?r8)r0r��text_length�excess�whitespace_match�whitespace_countr1r1r2�
rstrip_end�s�zText.rstrip_end�
new_lengthcCs@t|�}||kr||kr|�||�dS|�||�dSdS)z<Set new length of the text, clipping or padding is required.N)rU�	pad_rightr?)r0r�r�r1r1r2�
set_length�s�zText.set_length�optionsr!c
cs��|jdur	|jn|j}|jp|jpt}|jp|jpt}|j||j|||p&dt|j|jd�d�}t	d��
|�}|j||jd�EdHdS)Nr�F�rKrLrNrMrR�r+)
rNrKr%rLr'�wrap�	max_widthrrMr(r�r�r+)r0r�r�rNrKrLrw�	all_linesr1r1r2�__rich_console__�s��zText.__rich_console__cCsT|j}|��}|rtdd�|D��nd}|��}|r#tdd�|D��n|}t||�S)Ncs��|]}t|�VqdSr5�rr�r1r1r2r~���z(Text.__rich_measure__.<locals>.<genexpr>rcsr�r5r�r�r1r1r2r~�r�)r]�
splitlines�maxr;r)r0r�r�rTrw�max_text_widthr��min_text_widthr1r1r2�__rich_measure__�s�
zText.__rich_measure__rc#s^�t}|j}|jst|�V|r||�VdSt|jt��d��tt|jd��}�fdd�|D���|j	��d<dgdd	�|D��d
d	�|D��t
|�ddf�}|jtdd�d�g��j
}�j}i��j�tj�d
tf�����fdd�}	t||dd��D]$\\}
}}\}
}}|r�||�n||�|
|
kr�|||
|
�|	��Vq|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.
        Nr�rcsi|]
\}}|�|j��qSr1�r,�rm�indexr})r�r1r2r��r�zText.render.<locals>.<dictcomp>r)rFrcs� �|]\}}|jd|fVqdSr{)r*r�r1r1r2r~���zText.render.<locals>.<genexpr>csrr�r�r�r1r1r2r~�rTr�r-csBt�fdd�t��D��}�|�}|dur|S�|�}|�|<|S)z#Construct current style from stack.c3s�|]}�|VqdSr5r1)rm�	_style_id)�	style_mapr1r2r~�r�z9Text.render.<locals>.get_current_style.<locals>.<genexpr>N)�tuple�sorted)�styles�cached_style�
current_style)�combine�stack�style_cache�style_cache_getrr1r2�get_current_style�sz&Text.render.<locals>.get_current_style)rr]rOrr�r�null�list�	enumerater,rUr�rrd�remove�getr	�zip)r0r�r+�_SegmentrT�enumerated_spansrS�stack_append�	stack_popr
r7�leaving�style_id�next_offset�_r1)r	r�r
rrrr2r��sL�


����&

��zText.renderrwcs����}dtdf��fdd�}|jj}|jj}|jj}d�t�|�D]*}||j�|jr:|���t|�|j��|��fdd�|jD���t|�7�q#�|_	|S)z�Join 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(c3s<��jrt��D]\}}|V|s�VqdS�EdHdSr5)r]r)�lastr�)rwr0r1r2�	iter_texts���zText.join.<locals>.iter_textrc3s*�|]\}}}��|�||�VqdSr5r1rlrnr1r2r~*�
��
�zText.join.<locals>.<genexpr>)
r�r
rJrArOrdr)r,rUrP)r0rwr�r�extend_textr��extend_spansrTr1)rorwr7r0r2r�s"
	

�z	Text.joincCsd|jvrdS|dur|j}|durd}g}|j}|jddd�D]P}d|jvr,||�q d}|jddd�}|D]8}|j�d�rf|jddd�d	|jd<||j7}||}|re||}	|�|	�||	7}n||j7}||�q7q td
��	|�}
|
jg|_t
|j�|_|
j|jdd�<dS)ztConverts tabs to spaces.

        Args:
            tab_size (int, optional): Size of tabs. Defaults to 8.

        �	Nr�rRT)�include_separatorrr�r_rQ)
r]rNrdr;r�rJrr�r(r�rUrPrO)r0rNr�rdr��
cell_positionr�r��
tab_remainderr�rfr1r1r2�expand_tabs2s<




�

�
zText.expand_tabsF)rL�padr�r&cCs�|p|jpt}|dkrHt|j�}||kr+|dkr$t|j|d�d|_nt|j|�|_|rJ||krL||}|j�d|��g|_t|j�|_dSdSdSdS)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.
        �ignore�ellipsisru…r_N)rLr'rr]rrJrUrP)r0r�rLr&�	_overflowr�r�r1r1r2�truncate\s
�z
Text.truncatecs2t|j��t���fdd�|jD�|jdd�<dS)z=Remove or modify any spans that are over the end of the text.c�<g|]}|j�kr|j�kr|n�|jt�|j�|j��qSr1�r*r+r8r,r|�ro�
max_offsetr1r2rp{�

��z$Text._trim_spans.<locals>.<listcomp>N�rUr]r)rOr/r1r-r2r�ws

�zText._trim_spansr_r��	charactercs`t|�dks
Jd���r.|�}|�|j�|��|_t���fdd�|jD�|jdd�<dSdS)z�Pad 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|]\}}}�|�|�|��qSr1r1rl�ror�r1r2rp����zText.pad.<locals>.<listcomp>Nr0)r0r�r1�pad_charactersr1r4r2r&�s��zText.padcsXt|�dks
Jd���r*|��|j��|_t���fdd�|jD�|jdd�<dSdS)z�Pad the left with a given character.

        Args:
            count (int): Number of characters to pad.
            character (str, optional): Character to pad with. Defaults to " ".
        rr2cr3r1r1rlr4r1r2rp�r5z!Text.pad_left.<locals>.<listcomp>Nr0�r0r�r1r1r4r2�pad_left�s��z
Text.pad_leftcCs4t|�dks
Jd��|r|j�||��|_dSdS)z�Pad the right with a given character.

        Args:
            count (int): Number of characters to pad.
            character (str, optional): Character to pad with. Defaults to " ".
        rr2N)rUr]r7r1r1r2r��s�zText.pad_right�align�widthcCsx|�|�|t|j�}|r:|dkr|�||�dS|dkr2|d}|�||�|�|||�dS|�||�dSdS)z�Align 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 " ".
        �left�center�N)r*rr]r�r8)r0r9r:r1�excess_spacer;r1r1r2r9�s
�z
Text.alignrcst|ttf�std��t|�r�t|t�r=t|�}|j�|�t|�}t|��|r4|j�t	||�|��|j
�7_
|St|t�r�t	�|durLtd��|j
�|jra|j����t|�|j��|j�|j
�|j���fdd�|j��D��|j
t|�7_
|S)z�Add 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 instancec3�*�|]\}}}�|�|�|�VqdSr5r1rl�ror�r1r2r~�rzText.append.<locals>.<genexpr>)rbrHr(rtrUrrJrdrOr)rP�
ValueErrorr,r]rArc)r0rTr,rVr7r1r@r2rd�s:


����zText.appendcstt�|j�|jr|j����t|�|j��|j�|j�|j���fdd�|j�	�D��|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.
        c3r?r5r1rlr@r1r2r~rz#Text.append_text.<locals>.<genexpr>)
r)rPr,rOrdrUrJr]rArc�r0rTr1r@r2�append_text�s
�zText.append_text�tokenscCsl|jj}|jj}t}t|�}|D] \}}t|�}||�|r*||||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.
        )rJrdrOr)rUrrP)r0rDrCr�ror7�contentr,r1r1r2�
append_tokensszText.append_tokenscCs|j�|j�dS)z�Copy styles from another Text instance.

        Args:
            text (Text): A Text instance to copy styles from, must be the same length.
        N)rOrArBr1r1r2�copy_stylesszText.copy_styles)r"�allow_blank�	separatorr"rHcs��sJd��|j���vrt|��g�S|r(|�dd�t�t�����D��}ndttf��fdd�}t�fdd�|�|��D��}|sN��	��rN|�
�|S)a�Split 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�|]}|��VqdSr5r��rmr�r1r1r2r~?s�
�zText.split.<locals>.<genexpr>r-c3s6�t�t�����D]}|��\}}|V|Vq
dSr5)r�r�ryr})r�r*r+�rIrTr1r2�
flatten_spansDs��z!Text.split.<locals>.flatten_spansc3s�|]
}|j�kr|VqdSr5r\r�)rIr1r2r~Js��)r]rrcrsr�r�ryr
rFr��pop)r0rIr"rHrwrLr1rKr2r;'s

�
�z
Text.split�offsetscs�t|�}|s
t|��g�S|j�t��}dg|�|�}tt||dd���}|j�|j�|j�t	�t�����fdd�|D��}|j
sE|Sdd�|jD�}t|�}t}	|j
D]�\}
}�d}|}
||
d}	||\}}|
|kru|d}
n
|
|kr~|d}nn||
d}qf||kr�|}n'|}}|}
	||\}}||kr�|d}
n
||kr�|d}nn||
d}q�t
||d�D]&}||\}}td|
|�}t||||�}||kr�|||	||���q�qV|S)	z�Divide 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,�|]\}}��||����d�VqdS))r,rKrLNr1)rmr*r+�r�rKrLr,rTr1r2r~js��
�
�zText.divide.<locals>.<genexpr>cSsg|]}|jj�qSr1)rOrdr�r1r1r2rpvszText.divide.<locals>.<listcomp>r=)rrrcr]rUrr,rKrLr(rO�_linesr)�ranger�r8)r0rN�_offsetsr��divide_offsets�line_ranges�	new_lines�
_line_appends�
line_countro�
span_start�span_end�lower_bound�upper_bound�
start_line_no�
line_start�line_end�end_line_no�line_no�	new_start�new_endr1rOr2rsSsl	�	

�


�
��zText.divider�amountcsXt|j�|�t���fdd�|jD�|jdd�<|jd|�g|_|j|8_dS)z7Remove a number of characters from the end of the text.cr+r1r,r|r-r1r2rp�r/z#Text.right_crop.<locals>.<listcomp>N)rUr]r)rOrJrP)r0rcr1r-r2r?�s�	zText.right_cropr�c
Cs�|p|jpt}|p
|jp
t}t||jd�p|dk}t�}	|jdd�D]I}
d|
vr-|
�|�|r5t|
g�}nt	t
|
�||dkd�}|
�|�}|D]}
|
�|�qG|rZ|j||||d�|D]	}
|
j
||d	�q\|	�|�q"|	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'T�rHr!r&)r&r�)rL)rKr%rLr'rrMrr;r%rrHrsr�r*rA)
r0r�r:rKrLrNrM�wrap_justify�
wrap_overflowrwr�rUrNr1r1r2r��s*

�z	Text.wrapcCs0t�}|j}|��D]}|�|�||�q
|S)z�Fit the text in to given width by chopping in to lines.

        Args:
            width (int): Maximum characters in a line.

        Returns:
            Lines: Lines container.
        )rrdr;r�)r0r:rwrdr�r1r1r2�fit�s	

zText.fitcCsVdd�tjd|jtjd�D�}zttdd�|D��pd}W|Sty*d}Y|Sw)zrAuto-detect indentation of code.

        Returns:
            int: Number of spaces used to indent code.
        cSsh|]	}t|�d���qS�r)rUr�rJr1r1r2�	<setcomp>�s��z*Text.detect_indentation.<locals>.<setcomp>�
^( *)(.*)$r�cSsg|]}|ds|�qS)r=r1)rm�indentr1r1r2rpsz+Text.detect_indentation.<locals>.<listcomp>r)r�r�r]�	MULTILINErrrt)r0�
_indentations�indentationr1r1r2�detect_indentation�s����zText.detect_indentationu│z	dim green)r1r,�indent_sizecCs8|dur|��n|}|��}|��|�d|d��}t�d�}g}|j}	d}
|jdd�D]U}|�|j�}|r=|�	d�sB|
d7}
q.|�	d�}
t
t|
�|�\}}||�d|��}||jt|�d�|_|�|dt|��|
r|�
t||d	�g|
�d}
|	|�q.|
r�|�
td
|d	�g|
�|�d��|�}|S)u�Adds 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_rrjrTrdr=r�rQrR)rorcr%r�r�rdr;r�r]r��divmodrUr�rAr(r�r�)r0rpr1r,�_indent_sizerT�indent_line�	re_indentrU�add_line�blank_linesr�r�rk�full_indents�remaining_space�
new_indentr�r1r1r2�with_indent_guidess4


zText.with_indent_guides)rQrQ)rQ)r-r()rNr5)r-N)r_)rTr(r-r()rTr(r-N)rRrh)SrBrCrDrE�	__slots__rHrrr
rIrFrr)rWrYr6r^r3rrg�objectrirjrkrx�propertyrr��classmethodrr�r�rr�rr	r�r]�setterrSr�rcr�r�r�r�r�r�r�r�GetStyleCallabler�r
r�r�r�r�rr�rr�r�r�r%r*r�r&r8r�rr9rdrCrFrGrr;rsr?r�rgrorzr1r1r1r2r(vs\
���
�����	�

�
���
�����	�
�!��
�����	�
�%���������
������	�
�-


�
���
��
���
��
���
�$	�����
�-��
��
�
	��
���
�;'.����
�
�
��
�
,�
�

�����
�,O�������	
�0�������__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.
�Lorem�bold�ipsum�italiczjustify='left'�redr�zjustify='center'�greenr<)r,rKzjustify='right'�blue�rightzjustify='full'�magenta�full)Cr��	functoolsrr�mathr�operatorr�typingrrrr	r
rrr
rrr�_loopr�_pickr�_wraprr9rr@rr�
containersr�controlrr�r�jupyterr�measurer�segmentrr,rrr�r r!r"r#r%rGr'r�r�rH�TextTyper�r)r(rB�pip._vendor.rich.consolerTr��rule�printr1r1r1r2�<module>sr
4
G
K�



�