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__/segment.cpython-310.pyc
o

��h�`�@s�ddlmZddlmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZmZmZmZmZdd	lmZmZdd
lmZer^ddl m!Z!m"Z"m#Z#ed�Z$Gd
d�de�Z%eee%ee%ee&e'ffee%e&e&ffZ(e�Gdd�de��Z)Gdd�d�Z*Gdd�d�Z+e,dkr�ddl-m!Z!ddl.m/Z/ddl0m1Z1dZ2e1�3d�Z4e!�Z e �5d�e �6d�e �6d�e �6e/e2ddd ��e �6�e �6d!�e7e �8e4��Z9e �6e9�e �6�e �6d"�e �6e4�e �6d#�d$Sd$S)%�)�IntEnum)�	lru_cache)�filterfalse)�	getLogger)�
attrgetter)
�
TYPE_CHECKING�Dict�Iterable�List�
NamedTuple�Optional�Sequence�Tuple�Type�Union�)�_is_single_cell_widths�cached_cell_len�cell_len�get_character_cell_size�
set_cell_size)�Result�	rich_repr)�Style)�Console�ConsoleOptions�RenderResult�richc@sPeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZdS)�ControlTypezDNon-printable control codes which typically translate to ANSI codes.r��������	�
���
���N)�__name__�
__module__�__qualname__�__doc__�BELL�CARRIAGE_RETURN�HOME�CLEAR�SHOW_CURSOR�HIDE_CURSOR�ENABLE_ALT_SCREEN�DISABLE_ALT_SCREEN�	CURSOR_UP�CURSOR_DOWN�CURSOR_FORWARD�CURSOR_BACKWARD�CURSOR_MOVE_TO_COLUMN�CURSOR_MOVE_TO�
ERASE_IN_LINE�SET_WINDOW_TITLE�rBrB�C/usr/local/lib/python3.10/dist-packages/pip/_vendor/rich/segment.pyr#s$rc@s�eZdZUdZeed<dZeeed<dZ	ee
eed<ede
fdd��Zdefd	d
�Zdefdd�Zedefd
d��Zeed�ddde
dedfdd���Zde
dedfdd�ZedHdd��Ze		dIdeddeedeededfdd��Ze	dJdeddededfdd ��Zededdeedfd!d"��Ze		#	#dKdedd$e
deed%ed&edeedfd'd(��Ze		#dLd)edd$e
deed%ededf
d*d+��Z ed)edde
fd,d-��Z!ed.eeddee
e
ffd/d0��Z"e			dMd.eedd1e
d2ee
deed3edeedfd4d5��Z#e	dJd6e$dd.eedd1e
d2e
ded3edeedfd7d8��Z%e	dJd6e$dd.eedd1e
d2e
ded3edeedfd9d:��Z&e	dJd6e$dd.eedd1e
d2e
ded3edeedfd;d<��Z'ededdedfd=d>��Z(ededdedfd?d@��Z)ededdedfdAdB��Z*ededdedfdCdD��Z+ededdEee
deedfdFdG��Z,dS)N�Segmenta�A piece of text with associated style. Segments are produced by the Console render process and
    are ultimately converted in to strings to be written to the terminal.

    Args:
        text (str): A piece of text.
        style (:class:`~rich.style.Style`, optional): An optional style to apply to the text.
        control (Tuple[ControlCode], optional): Optional sequence of control codes.

    Attributes:
        cell_length (int): The cell length of this Segment.
    �textN�style�control�returncCs|\}}}|r	dSt|�S)zzThe number of terminal cells required to display self.text.

        Returns:
            int: A number of cells.
        r)r)�selfrE�_stylerGrBrBrC�cell_lengthQs
zSegment.cell_lengthccsB�|jV|jdur|jdur|jVdSdS|jV|jVdS�N)rErGrF�rIrBrBrC�
__rich_repr__[s�

�zSegment.__rich_repr__cCs
t|j�S)z#Check if the segment contains text.)�boolrErMrBrBrC�__bool__ds
zSegment.__bool__cCs
|jduS)z,Check if the segment contains control codes.N)rGrMrBrBrC�
is_controlhs
zSegment.is_controli@�segment�cut)rDrDc
Cs>|\}}}t}|j}||kr||d||�fSt}t||t|��}		|d|	�}
t|
�}||}|sC||
||�|||	d�||�fS|dkri|||	�dkri||d|	�d||�|d||	dd�||�fS|dkr�|||	d�dkr�||d|	d�d||�|d||	d�||�fS||kr�|	d7}	n|	d8}	q#)a\Split a segment in to two at a given cell position.

        Note that splitting a double-width character, may result in that character turning
        into two spaces.

        Args:
            segment (Segment): A segment to split.
            cut (int): A cell position to cut on.

        Returns:
            A tuple of two segments.
        �TN���r� r)rDrKr�int�lenr)
�clsrRrSrErFrG�_SegmentrK�	cell_size�pos�before�cell_pos�out_byrBrBrC�_split_cellsms6

���
�zSegment._split_cellscCsn|\}}}|dksJ�t|�r1|t|�kr|td||�fSt|d|�||�t||d�||�fS|�||�S)axSplit segment in to two segments at the specified column.

        If the cut point falls in the middle of a 2-cell wide character then it is replaced
        by two spaces, to preserve the display width of the parent segment.

        Args:
            cut (int): Offset within the segment to cut.

        Returns:
            Tuple[Segment, Segment]: Two segments.
        rrTN)rrXrDr`)rIrSrErFrGrBrBrC�split_cells�s
�zSegment.split_cellscCs|d�S)zMake a new line segment.�
rB)rYrBrBrC�line�szSegment.line�segments�
post_stylecs>|}|r|j���fdd�|D�}�r��fdd�|D�}|S)aApply style(s) to an iterable of segments.

        Returns an iterable of segments where the style is replaced by ``style + segment.style + post_style``.

        Args:
            segments (Iterable[Segment]): Segments to process.
            style (Style, optional): Base style. Defaults to None.
            post_style (Style, optional): Style to apply on top of segment style. Defaults to None.

        Returns:
            Iterable[Segments]: A new iterable of segments (possibly the same iterable).
        c3s.�|]\}}}�||r
dn�|�|�VqdSrLrB��.0rErJrG)�applyrYrBrC�	<genexpr>�s
��
�z&Segment.apply_style.<locals>.<genexpr>c3s6�|]\}}}�||r
dn|r|�n�|�VqdSrLrBrf)rYrerBrCri�s�
���
�)�__add__)rYrdrFre�result_segmentsrB)rhrYrerC�apply_style�s�
�zSegment.apply_styleFrQcCs |r	ttd�|�Sttd�|�S)a2Filter segments by ``is_control`` attribute.

        Args:
            segments (Iterable[Segment]): An iterable of Segment instances.
            is_control (bool, optional): is_control flag to match in search.

        Returns:
            Iterable[Segment]: And iterable of Segment instances.

        rG)�filterrr)rYrdrQrBrBrC�filter_control�szSegment.filter_controlc
cs��g}|j}|D]3}d|jvr7|js7|\}}}|r6|�d�\}}	}|r*||||��|	r4|Vg}|j}|sq||�q|rC|VdSdS)aSplit a sequence of segments in to a list of lines.

        Args:
            segments (Iterable[Segment]): Segments potentially containing line feeds.

        Yields:
            Iterable[List[Segment]]: Iterable of segment lists, one per line.
        rbN)�appendrErG�	partition)
rYrdrcrorRrErF�_�_text�new_linerBrBrC�split_lines�s(�

��
	
�zSegment.split_linesT�length�pad�include_new_linesccs��g}|j}|j}|d�}	|D]A}
d|
jvrL|
jsL|
\}}}
|rK|�d�\}}}|r1||||��|rI|||||d�}|rB|�|	�|V|��|s q||
�q|r^|||||d�VdSdS)a�Split segments in to lines, and crop lines greater than a given length.

        Args:
            segments (Iterable[Segment]): An iterable of segments, probably
                generated from console.render.
            length (int): Desired line length.
            style (Style, optional): Style to use for any padding.
            pad (bool): Enable padding of lines that are less than `length`.

        Returns:
            Iterable[List[Segment]]: An iterable of lines of segments.
        rb)rFrvN)ro�adjust_line_lengthrErGrp�clear)rYrdrurFrvrwrcrorx�new_line_segmentrRrE�
segment_stylerqrrrs�cropped_linerBrBrC�split_and_crop_liness4�
�
��

�zSegment.split_and_crop_linesrcc
Cs�tdd�|D��}||kr%|r||d|||�g}|S|dd�}|S||krag}|j}d}|D],}|j}	||	|ks@|jrI||�||	7}q2|\}
}}t|
||�}
|||
|��|S|S|dd�}|S)aAdjust a line to a given width (cropping or padding as required).

        Args:
            segments (Iterable[Segment]): A list of segments in a single line.
            length (int): The desired width of the line.
            style (Style, optional): The style of padding if used (space on the end). Defaults to None.
            pad (bool, optional): Pad lines with spaces if they are shorter than `length`. Defaults to True.

        Returns:
            List[Segment]: A line of segments with the desired length.
        css�|]}|jVqdSrL)rK)rgrRrBrBrCriXs�z-Segment.adjust_line_length.<locals>.<genexpr>rVNr)�sumrorKrGr)
rYrcrurFrv�line_lengthrsrorR�segment_lengthrEr{rqrBrBrCrxEs.��

�zSegment.adjust_line_lengthcst�t�fdd�|D��S)z�Get the length of list of segments.

        Args:
            line (List[Segment]): A line encoded as a list of Segments (assumes no '\\n' characters),

        Returns:
            int: The length of the line.
        c3s"�|]\}}}|s�|�VqdSrLrB)rgrErFrG��	_cell_lenrBrCri}s� z*Segment.get_line_length.<locals>.<genexpr>)rr~)rYrcrBr�rC�get_line_lengthrs
zSegment.get_line_length�linescs0|j�|rt�fdd�|D��nd}|t|�fS)z�Get the shape (enclosing rectangle) of a list of lines.

        Args:
            lines (List[List[Segment]]): A list of lines (no '\\n' characters).

        Returns:
            Tuple[int, int]: Width and height in characters.
        c3s�|]}�|�VqdSrLrB�rgrc�r�rBrCri�s�z$Segment.get_shape.<locals>.<genexpr>r)r��maxrX)rYr��	max_widthrBr�rC�	get_shapes
zSegment.get_shape�width�height�	new_linesc	s�|pt|�}|r|d�d��gn|d���g}|j�|d|�}���fdd�|D�|dd�<t|�|krD|�|g|t|��|S)a�Set the shape of a list of lines (enclosing rectangle).

        Args:
            lines (List[List[Segment]]): A list of lines.
            width (int): Desired width.
            height (int, optional): Desired height or None for no change.
            style (Style, optional): Style of any padding added.
            new_lines (bool, optional): Padded lines should include "
". Defaults to False.

        Returns:
            List[List[Segment]]: New list of lines.
        rVrbNcsg|]	}�|��d��qS))rFrBr��rxrFr�rBrC�
<listcomp>�s�z%Segment.set_shape.<locals>.<listcomp>)rXrx�extend)	rYr�r�r�rFr��_height�blank�shaped_linesrBr�rC�	set_shape�s&��zSegment.set_shaperYcCs`|t|�}|s|dd�S|d|�}|r|d|d|�n|d||�}||gg|}|S)a�Aligns lines to top (adds extra lines to bottom as required).

        Args:
            lines (List[List[Segment]]): A list of lines.
            width (int): Desired width.
            height (int, optional): Desired height or None for no change.
            style (Style): Style of any padding added.
            new_lines (bool, optional): Padded lines should include "
". Defaults to False.

        Returns:
            List[List[Segment]]: New list of lines.
        NrVrb�rX�rYr�r�r�rFr��extra_linesr�rBrBrC�	align_top��$zSegment.align_topcCs`|t|�}|s|dd�S|d|�}|r|d|d|�n|d||�}|gg||}|S)a�Aligns render to bottom (adds extra lines above as required).

        Args:
            lines (List[List[Segment]]): A list of lines.
            width (int): Desired width.
            height (int, optional): Desired height or None for no change.
            style (Style): Style of any padding added. Defaults to None.
            new_lines (bool, optional): Padded lines should include "
". Defaults to False.

        Returns:
            List[List[Segment]]: New list of lines.
        NrVrbr�r�rBrBrC�align_bottom�r�zSegment.align_bottomc
Cs||t|�}|s|dd�S|d|�}|r|d|d|�n|d||�}|d}||}	|gg|||gg|	}|S)a�Aligns lines to middle (adds extra lines to above and below as required).

        Args:
            lines (List[List[Segment]]): A list of lines.
            width (int): Desired width.
            height (int, optional): Desired height or None for no change.
            style (Style): Style of any padding added.
            new_lines (bool, optional): Padded lines should include "
". Defaults to False.

        Returns:
            List[List[Segment]]: New list of lines.
        NrVrbrr�)
rYr�r�r�rFr�r�r��	top_lines�bottom_linesrBrBrC�align_middle�s$zSegment.align_middleccsv�t|�}zt|�}Wn
tyYdSwt}|D]}|j|jkr0|js0||j|j|j�}q|V|}q|VdS)a)Simplify an iterable of segments by combining contiguous segments with the same style.

        Args:
            segments (Iterable[Segment]): An iterable of segments.

        Returns:
            Iterable[Segment]: A possibly smaller iterable of segments that will render the same way.
        N)�iter�next�
StopIterationrDrFrGrE)rYrd�
iter_segments�last_segmentrZrRrBrBrC�simplify
s �
��
zSegment.simplifyccsL�|D] }|js
|jdur|Vq|\}}}|||r|�d�nd�VqdS)z�Remove all links from an iterable of styles.

        Args:
            segments (Iterable[Segment]): An iterable segments.

        Yields:
            Segment: Segments with link removed.
        N)rGrF�update_link)rYrdrRrErF�_controlrBrBrC�strip_links%s�

�zSegment.strip_linksccs$�|D]\}}}||d|�VqdS)z�Remove all styles from an iterable of segments.

        Args:
            segments (Iterable[Segment]): An iterable segments.

        Yields:
            Segment: Segments with styles replace with None
        NrB)rYrdrErJrGrBrBrC�strip_styles6s�
�zSegment.strip_stylesccs\�i}|D]&\}}}|r$|�|�}|dur|j}|||<||||�Vq||d|�VqdS)z�Remove all color from an iterable of segments.

        Args:
            segments (Iterable[Segment]): An iterable segments.

        Yields:
            Segment: Segments with colorless style.
        N)�get�
without_color)rYrd�cacherErFrG�colorless_stylerBrBrC�remove_colorCs�
�zSegment.remove_color�cutsccsF�g}|j}t|�}	t|d�}|dkrdS|dkrngVqd}|j}|j}	t}
|D]q}|\}}
}|r�|r8|n||
|�}||krI||�|}nS||krm||�|	�V|�|}t|d�}|dkrl|ri|	�VdSn/|�||�\}}|\}}
}||�|	�V|�|}t|d�}|dkr�|r�|	�VdS|s4q+|	�VdS)z�Divides an iterable of segments in to portions.

        Args:
            cuts (Iterable[int]): Cell positions where to divide.

        Yields:
            [Iterable[List[Segment]]]: An iterable of Segments in List.
        TrUNr)ror�r�ry�copyrra)rYrdr��split_segments�add_segment�	iter_cutsrSr\�segments_clear�
segments_copyr�rRrErJrG�end_posr]rBrBrC�divideYsb�
�



��#zSegment.divide)rHrD)NN�F)NTT)NT)NNF)-r.r/r0r1�str�__annotations__rFrrrGr
�ControlCode�propertyrWrKrrNrOrPrQ�classmethodrrr`rarcr	rlrnr
rtr}rxr�r�r�rr�r�r�r�r�r�r�r�rBrBrBrCrD?s>
		/�����(���� ������
�.������,$
�
�����
�#��
�����
���
�����
���
�����
���
�rDc@sBeZdZdZddeededdfdd�Z			
				
ddd�ZdS)�Segmentsa=A simple renderable to render an iterable of segments. This class may be useful if
    you want to print segments outside of a __rich_console__ method.

    Args:
        segments (Iterable[Segment]): An iterable of segments.
        new_lines (bool, optional): Add new lines between segments. Defaults to False.
    Frdr�rHNcCst|�|_||_dSrL)�listrdr�)rIrdr�rBrBrC�__init__�s

zSegments.__init__�consoler�optionsrrccs<�|jrt��}|jD]}|V|VqdS|jEdHdSrL)r�rDrcrd)rIr�r�rcrRrBrBrC�__rich_console__�s�
�zSegments.__rich_console__r��r�rr�rrHr)	r.r/r0r1r	rDrOr�r�rBrBrBrCr��s���r�c@sBeZdZddeeededdfdd�Z				
			dd
d�ZdS)�SegmentLinesFr�r�rHNcCst|�|_||_dS)a=A simple renderable containing a number of lines of segments. May be used as an intermediate
        in rendering process.

        Args:
            lines (Iterable[List[Segment]]): Lists of segments forming lines.
            new_lines (bool, optional): Insert new lines after each line. Defaults to False.
        N)r�r�r�)rIr�r�rBrBrCr��s

zSegmentLines.__init__r�rr�rrccsJ�|jrt��}|jD]
}|EdH|VqdS|jD]}|EdHqdSrL)r�rDrcr�)rIr�r�rsrcrBrBrCr��s�

�
�zSegmentLines.__rich_console__r�r�)	r.r/r0r	r
rDrOr�r�rBrBrBrCr��s ���r��__main__)r)�Syntax)�Textz�from rich.console import Console
console = Console()
text = Text.from_markup("Hello, [bold magenta]World[/]!")
console.print(text)zHello, [bold magenta]World[/]!zrich.Segmentz]A Segment is the last step in the Rich render process before generating text with ANSI codes.z
Consider the following code:
�pythonT)�line_numberszRWhen you call [b]print()[/b], Rich [i]renders[/i] the object in to the following:
zAThe Segments are then processed to produce the following output:
zS
You will only need to know this if you are implementing your own Rich renderables.N):�enumr�	functoolsr�	itertoolsr�loggingr�operatorr�typingrrr	r
rrr
rrr�cellsrrrrr�reprrrrFrr�rrr�logrrWr�r�rDr�r�r.�pip._vendor.rich.console�pip._vendor.rich.syntaxr��pip._vendor.rich.textr��code�from_markuprE�rule�printr��render�	fragmentsrBrBrBrC�<module>sj0
��c

�
�


��