HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/site-packages/pip/_vendor/rich/__pycache__/segment.cpython-37.pyc
B

L��g�^�@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-hv55ucu3/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.)�boolr7)r;r4r4r5�__bool__dszSegment.__bool__cCs
|jdk	S)z,Check if the segment contains control codes.N)r9)r;r4r4r5�
is_controlhszSegment.is_controli@)r6r6)�segment�cutr:c
Cs0|\}}}t}|j}||kr,||d||�fSt}t||t|�d�}	|d|	�}
t|
�}||kr�||
||�|||	d�||�fSx�|	t|�k�r"||	}|	d7}	|||�7}|d|	�}
||kr�||
||�|||	d�||�fS||kr�||
d|	d�d||�|d||	d�||�fSq�Wtd��dS)N�r� zWill never reach here)r6r=r�int�lenr�AssertionError)
�clsrBrCr7r8r9�_Segmentr=Z	cell_size�pos�beforeZcell_pos�charr4r4r5�_split_cellsms0


zSegment._split_cells)rCr: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.
        rDN)rrGr6rN)r;rCr7r8r9r4r4r5�split_cells�s	
zSegment.split_cellscCs|d�S)zMake a new line segment.�
r4)rIr4r4r5�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�|�|�VqdS)Nr4)�.0r7r<r9)�applyrIr4r5�	<genexpr>�sz&Segment.apply_style.<locals>.<genexpr>c3s4|],\}}}�||rdn|r$|�n�|�VqdS)Nr4)rTr7r<r9)rIrSr4r5rV�s	)�__add__)rIrRr8rSZresult_segmentsr4)rUrIrSr5�apply_style�s	zSegment.apply_styleF)rRrAr: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)rIrRrAr4r4r5�filter_control�szSegment.filter_control)rRr:c
cs�g}|j}xp|D]h}d|jkrp|jsp|\}}}xH|rl|�d�\}}	}|rV||||��|	r0|Vg}|j}q0Wq||�qW|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.
        rPN)�appendr7r9�	partition)
rIrRrQr[rBr7r8�_�_text�new_liner4r4r5�split_lines�s 


zSegment.split_linesT)rR�lengthr8�pad�include_new_linesr:ccs�g}|j}|j}|d�}	x�|D]�}
d|
jkr�|
js�|
\}}}
xd|r�|�d�\}}}|rd||||��|r>|||||d�}|r�|�|	�|V|��q>Wq||
�qW|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.
        rP)r8rbN)r[�adjust_line_lengthr7r9r\�clear)rIrRrar8rbrcrQr[rdZnew_line_segmentrBr7�
segment_styler]r^r_Zcropped_liner4r4r5�split_and_crop_lines	s*


zSegment.split_and_crop_lines)rQrar8rbr:c
Cs�tdd�|D��}||krF|r8||d|||�g}q�|dd�}n�||kr�g}|j}d}xl|D]V}|j}	||	|ks~|jr�||�||	7}qb|\}
}}t|
||�}
|||
|��PqbWn|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|]}|jVqdS)N)r=)rTrBr4r4r5rVKsz-Segment.adjust_line_length.<locals>.<genexpr>rENr)�sumr[r=r9r)
rIrQrar8rbZline_lengthr_r[rBZsegment_lengthr7rfr]r4r4r5rd8s(


zSegment.adjust_line_length)rQr: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�|�VqdS)Nr4)rTr7r8r9)�	_cell_lenr4r5rVpsz*Segment.get_line_length.<locals>.<genexpr>)rrh)rIrQr4)rir5�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|]}�|�VqdS)Nr4)rTrQ)rjr4r5rV}sz$Segment.get_shape.<locals>.<genexpr>r)rj�maxrG)rIrk�	max_widthr4)rjr5�	get_shapers
zSegment.get_shape)rk�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.
        rErPNcsg|]}�|��d��qS))r8r4)rTrQ)rdr8ror4r5�
<listcomp>�sz%Segment.set_shape.<locals>.<listcomp>)rGrd�extend)	rIrkrorpr8rqZ_height�blankZshaped_linesr4)rdr8ror5�	set_shape�s(zSegment.set_shape)rIrkrorpr8rqr: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.
        NrErP)rG)rIrkrorpr8rq�extra_linesrtr4r4r5�	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.
        NrErP)rG)rIrkrorpr8rqrvrtr4r4r5�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.
        NrErPr)rG)
rIrkrorpr8rqrvrtZ	top_linesZbottom_linesr4r4r5�align_middle�s$zSegment.align_middleccsxt|�}yt|�}Wntk
r(dSXt}x>|D]6}|j|jkr`|js`||j|j|j�}q4|V|}q4W|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)rIrRZ
iter_segmentsZlast_segmentrJrBr4r4r5�simplify�s

zSegment.simplifyccsNxH|D]@}|js|jdkr"|Vq|\}}}|||r>|�d�nd�VqWdS)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)rIrRrBr7r8Z_controlr4r4r5�strip_linkss



zSegment.strip_linksccs&x |D]\}}}||d|�VqWdS)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)rIrRr7r<r9r4r4r5�strip_styles)s
zSegment.strip_stylesccs^i}xT|D]L\}}}|rH|�|�}|dkr8|j}|||<||||�Vq
||d|�Vq
WdS)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)rIrR�cacher7r8r9Zcolorless_styler4r4r5�remove_color6s
zSegment.remove_color)rR�cutsr:ccsNg}|j}t|�}x*t|d�}|dkr*gS|dkr4PgVqWd}|j}|j}	t}
x�|D]�}|\}}
}x�|�r<|rv|n
||
|�}||kr�||�|}P||kr�||�|	�V|�|}t|d�}|dkr�|r�|	�VdSPn6|�||�\}}|\}}
}||�|	�V|�|}t|d�}|dkrh|�r6|	�VdSqhWqXW|	�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[rzr{re�copyrrO)rIrRr�Zsplit_segmentsZadd_segmentZ	iter_cutsrCrKZsegments_clearZ
segments_copyrirBr7r<r9Zend_posrLr4r4r5�divideLsZ






zSegment.divide)NN)F)NTT)NT)NNF)F)F)F)-r-r.r/r0�str�__annotations__r8rrr9r
�ControlCode�propertyrFr=rr>r?r@rA�classmethodrrrNrOrQr	rXrZr
r`rgrdrjrnrurrwrxryr}r~rr�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)rRrqr:cCst|�|_||_dS)N)�listrRrq)r;rRrqr4r4r5�__init__�s
zSegments.__init__rrr)�console�optionsr:ccs<|jr,t��}x(|jD]}|V|VqWn|jEdHdS)N)rqr6rQrR)r;r�r�rQrBr4r4r5�__rich_console__�szSegments.__rich_console__)F)	r-r.r/r0r	r6r?r�r�r4r4r4r5r��sr�c@s:eZdZdeeeedd�dd�Zdddd	�d
d�ZdS)
�SegmentLinesFN)rkrqr: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�rkrq)r;rkrqr4r4r5r��s
zSegmentLines.__init__rrr)r�r�r:ccsN|jr0t��}x:|jD]}|EdH|VqWnx|jD]}|EdHq8WdS)N)rqr6rQrk)r;r�r�r_rQr4r4r5r��s
zSegmentLines.__rich_console__)F)	r-r.r/r	r
r6r?r�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�logrrFr�r�r6r�r�r-Zpip._vendor.rich.consoleZpip._vendor.rich.syntaxr�Zpip._vendor.rich.textr��codeZfrom_markupr7Zrule�printr��render�	fragmentsr4r4r4r5�<module>s\0
V