HEX
Server: Apache
System: Linux p3plzcpnl506847.prod.phx3.secureserver.net 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: slfopp7cb1df (5698090)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/python38/lib/python3.8/site-packages/pip/_vendor/rich/__pycache__/segment.cpython-38.pyc
U

�{�e�^�@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,dk�r�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$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�RenderResultZrichc@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__ZBELLZCARRIAGE_RETURN�HOMEZCLEAR�SHOW_CURSOR�HIDE_CURSORZENABLE_ALT_SCREENZDISABLE_ALT_SCREENZ	CURSOR_UPZCURSOR_DOWNZCURSOR_FORWARDZCURSOR_BACKWARDZCURSOR_MOVE_TO_COLUMNZCURSOR_MOVE_TOZ
ERASE_IN_LINEZSET_WINDOW_TITLE�r4r4�</tmp/pip-unpacked-wheel-_0scjqea/pip/_vendor/rich/segment.pyr#s"rc@s*eZdZUdZeed<dZeeed<dZ	ee
eed<ee
d�dd��Zed�d	d
�Zed�dd�Zeed�d
d��Zeed�de
edd�dd���Ze
edd�dd�Zedd�dd��ZedEedeeeeedd�dd��ZedFedeedd�dd��Zeedeedd �d!d"��ZedGede
eeeeeedd$�d%d&��ZedHede
eeeedd'�d(d)��Z eede
d*�d+d,��Z!eeedee
e
fd-�d.d/��Z"edIeede
ee
eeeeedd0�d1d2��Z#edJe$deede
e
eeeedd3�d4d5��Z%edKe$deede
e
eeeedd3�d6d7��Z&edLe$deede
e
eeeedd3�d8d9��Z'eededd �d:d;��Z(eededd �d<d=��Z)eededd �d>d?��Z*eededd �d@dA��Z+eedee
eeddB�dCdD��Z,dS)M�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|\}}}|rdSt|�S)zzThe number of terminal cells required to display self.text.

        Returns:
            int: A number of cells.
        r)r)�selfr7�_styler9r4r4r5�cell_lengthQs
zSegment.cell_lengthccs:|jV|jdkr&|jdk	r6|jVn|jV|jVdS�N)r7r9r8�r;r4r4r5�
__rich_repr__[s


zSegment.__rich_repr__cCs
t|j�S)z#Check if the segment contains text.)�boolr7r?r4r4r5�__bool__dszSegment.__bool__cCs
|jdk	S)z,Check if the segment contains control codes.N)r9r?r4r4r5�
is_controlhszSegment.is_controli@)r6r6)�segment�cutr:c
Cs,|\}}}t}|j}||kr,||d||�fSt}t||t|�d�}	|d|	�}
t|
�}||kr�||
||�|||	d�||�fS|	t|�k�r ||	}|	d7}	|||�7}|d|	�}
||kr�||
||�|||	d�||�fS||kr�||
d|	d�d||�|d||	d�||�fSq�td��dS)N�r� zWill never reach here)r6r=r�int�lenr�AssertionError)
�clsrDrEr7r8r9�_Segmentr=Z	cell_size�pos�beforeZcell_pos�charr4r4r5�_split_cellsms6

�
��zSegment._split_cells)rEr:cCsb|\}}}t|�rV|t|�kr.|td||�fSt|d|�||�t||d�||�fS|�||�S)a0Split 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.

        Returns:
            Tuple[Segment, Segment]: Two segments.
        rFN)rrIr6rP)r;rEr7r8r9r4r4r5�split_cells�s	
�zSegment.split_cellscCs|d�S)zMake a new line segment.�
r4)rKr4r4r5�line�szSegment.line)�segmentsr8�
post_styler:cs>|}|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,|]$\}}}�||rdn�|�|�VqdSr>r4��.0r7r<r9)�applyrKr4r5�	<genexpr>�s�z&Segment.apply_style.<locals>.<genexpr>c3s4|],\}}}�||rdn|r$|�n�|�VqdSr>r4rV)rKrUr4r5rY�s
���)�__add__)rKrTr8rUZresult_segmentsr4)rXrKrUr5�apply_style�s�
�zSegment.apply_styleF)rTrCr:cCs$|rttd�|�Sttd�|�SdS)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.

        r9N)�filterrr)rKrTrCr4r4r5�filter_control�szSegment.filter_control)rTr:c
cs�g}|j}|D]d}d|jkrj|jsj|\}}}|rr|�d�\}}	}|rR||||��|	r,|Vg}|j}q,q||�q|r~|VdS)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.
        rRN)�appendr7r9�	partition)
rKrTrSr^rDr7r8�_�_text�new_liner4r4r5�split_lines�s 



zSegment.split_linesT)rT�lengthr8�pad�include_new_linesr:ccs�g}|j}|j}|d�}	|D]�}
d|
jkr�|
js�|
\}}}
|r�|�d�\}}}|r`||||��|r:|||||d�}|r�|�|	�|V|��q:q||
�q|r�|||||d�VdS)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.
        rR)r8reN)r^�adjust_line_lengthr7r9r_�clear)rKrTrdr8rerfrSr^rgZnew_line_segmentrDr7�
segment_styler`rarbZcropped_liner4r4r5�split_and_crop_lines	s2
�

zSegment.split_and_crop_lines)rSrdr8rer:c
Cs�tdd�|D��}||krF|r8||d|||�g}q�|dd�}n�||kr�g}|j}d}|D]X}|j}	||	|ks||jr�||�||	7}q`|\}
}}t|
||�}
|||
|��q�q`n|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|]}|jVqdSr>)r=)rWrDr4r4r5rYKsz-Segment.adjust_line_length.<locals>.<genexpr>rGNr)�sumr^r=r9r)
rKrSrdr8reZline_lengthrbr^rDZsegment_lengthr7rir`r4r4r5rg8s(

zSegment.adjust_line_length)rSr:cst�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�|�VqdSr>r4)rWr7r8r9��	_cell_lenr4r5rYpsz*Segment.get_line_length.<locals>.<genexpr>)rrk)rKrSr4rlr5�get_line_lengthes
zSegment.get_line_length)�linesr:cs0|j�|r t�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|]}�|�VqdSr>r4�rWrS�rnr4r5rY}sz$Segment.get_shape.<locals>.<genexpr>r)rn�maxrI)rKro�	max_widthr4rqr5�	get_shapers
zSegment.get_shape)ro�width�heightr8�	new_linesr:c	s�|p
t|�}|r$|d�d��gn|d���g}|j�|d|�}���fdd�|D�|dd�<t|�|kr�|�|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.
        rGrRNcsg|]}�|��d��qS))r8r4rp�rgr8rur4r5�
<listcomp>�sz%Segment.set_shape.<locals>.<listcomp>)rIrg�extend)	rKrorurvr8rwZ_height�blankZshaped_linesr4rxr5�	set_shape�s&��zSegment.set_shape)rKrorurvr8rwr:cCs`|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.
        NrGrR�rI�rKrorurvr8rw�extra_linesr{r4r4r5�	align_top�s$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.
        NrGrRr}r~r4r4r5�align_bottom�s$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.
        NrGrRrr})
rKrorurvr8rwrr{Z	top_linesZbottom_linesr4r4r5�align_middle�s$zSegment.align_middleccsvt|�}zt|�}Wntk
r*YdSXt}|D]6}|j|jkr`|js`||j|j|j�}q4|V|}q4|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�
StopIterationr6r8r9r7)rKrTZ
iter_segmentsZlast_segmentrLrDr4r4r5�simplify�s

�zSegment.simplifyccsJ|D]@}|js|jdkr |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)r9r8Zupdate_link)rKrTrDr7r8Z_controlr4r4r5�strip_linkss


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
        Nr4)rKrTr7r<r9r4r4r5�strip_styles)s
zSegment.strip_stylesccsZi}|D]L\}}}|rF|�|�}|dkr6|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)�getZ
without_color)rKrT�cacher7r8r9Zcolorless_styler4r4r5�remove_color6s
zSegment.remove_color)rT�cutsr:ccsDg}|j}t|�}t|d�}|dkr(gS|dkr2q:gVqd}|j}|j}	t}
|D]�}|\}}
}|rR|rl|n
||
|�}||kr�||�|}qR||kr�||�|	�V|�|}t|d�}|dkr�|r�|	�VdSqRn6|�||�\}}|\}}
}||�|	�V|�|}t|d�}|dkr`|�r.|	�VdSq`qR|	�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.
        ���rN)r^r�r�rh�copyrrQ)rKrTr�Zsplit_segmentsZadd_segmentZ	iter_cutsrErMZsegments_clearZ
segments_copyrmrDr7r<r9Zend_posrNr4r4r5�divideLsX





zSegment.divide)NN)F)NTT)NT)NNF)F)F)F)-r-r.r/r0�str�__annotations__r8rrr9r
�ControlCode�propertyrHr=rr@rArBrC�classmethodrrrPrQrSr	r[r]r
rcrjrgrnrtr|rr�r�r�r�r�r�r�r�r4r4r4r5r6?s�
		&��(���
�.��,"
�

�#�

��

��

�
�r6c@s:eZdZdZd
eeedd�dd�Zddd	d
�dd�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.
    FN)rTrwr:cCst|�|_||_dSr>)�listrTrw)r;rTrwr4r4r5�__init__�s
zSegments.__init__rrr��console�optionsr:ccs8|jr(t��}|jD]}|V|Vqn|jEdHdSr>)rwr6rSrT)r;r�r�rSrDr4r4r5�__rich_console__�s

zSegments.__rich_console__)F)	r-r.r/r0r	r6rAr�r�r4r4r4r5r��s�r�c@s:eZdZdeeeedd�dd�Zdddd	�d
d�ZdS)
�SegmentLinesFN)rorwr:cCst|�|_||_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�rorw)r;rorwr4r4r5r��s
zSegmentLines.__init__rrrr�ccsF|jr,t��}|jD]}|EdH|Vqn|jD]}|EdHq2dSr>)rwr6rSro)r;r�r�rbrSr4r4r5r��s



zSegmentLines.__rich_console__)F)	r-r.r/r	r
r6rAr�r�r4r4r4r5r��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)Z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�reprrrr8rr�rrr�logrrHr�r�r6r�r�r-Zpip._vendor.rich.consoleZpip._vendor.rich.syntaxr�Zpip._vendor.rich.textr��codeZfrom_markupr7Zrule�printr��render�	fragmentsr4r4r4r5�<module>sf0
��V


�
�


�