HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/pip/_vendor/rich/__pycache__/segment.cpython-310.pyc
o

@%Nel]�@s�ddlmZddlmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZmZmZmZdd	lmZmZdd
lmZer\ddlm Z m!Z!m"Z"ed�Z#Gd
d�de�Z$eee$ee$e%fee$e%e%ffZ&e�Gdd�de��Z'Gdd�d�Z(Gdd�d�Z)e*dkr�e*dkr�ddl+m Z ddl,m-Z-ddl.m/Z/dZ0e/�1d�Z2e �Ze�3d�e�4d�e�4d�e�4e-e0ddd ��e�4�e�4d!�e5e�6e2��Z7e�4e7�e�4�e�4d"�e�4e2�e�4d#�d$Sd$Sd$S)%�)�IntEnum)�	lru_cache)�filterfalse)�	getLogger)�
attrgetter)
�
TYPE_CHECKING�Dict�Iterable�List�
NamedTuple�Optional�Sequence�Tuple�Type�Union�)�_is_single_cell_widths�cell_len�get_character_cell_size�
set_cell_size)�Result�	rich_repr)�Style)�Console�ConsoleOptions�RenderResult�richc@sLeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdS)�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�r?r?�:/usr/lib/python3/dist-packages/pip/_vendor/rich/segment.pyr"s"rc@s�eZdZUdZdZeed<	dZee	ed<	dZ
eeeed<	de
fdd	�Zdefd
d�Zedefdd
��Zedefdd��Zeed�dddededfdd���Zdededfdd�ZedIdd��Ze		dJdeddee	dee	dedfdd��Ze	dKdeddededfd d!��Zededdeedfd"d#��Ze		$	$dLdedd%edee	d&ed'edeedfd(d)��Z e		$dMd*edd%edee	d&ededf
d+d,��Z!ed*eddefd-d.��Z"ed/eeddeeeffd0d1��Z#e			dNd/eedd2ed3eedee	d4edeedfd5d6��Z$e	dKd7e%dd/eedd2ed3ede	d4edeedfd8d9��Z&e	dKd7e%dd/eedd2ed3ede	d4edeedfd:d;��Z'e	dKd7e%dd/eedd2ed3ede	d4edeedfd<d=��Z(ededdedfd>d?��Z)ededdedfd@dA��Z*ededdedfdBdC��Z+ededdedfdDdE��Z,ededdFeedeedfdGdH��Z-dS)O�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.
    ��textN�style�control�returnccsB�|jV|jdur|jdur|jVdSdS|jV|jVdS�N)rCrErD��selfr?r?r@�
__rich_repr__Ms�

�zSegment.__rich_repr__cCs
t|j�S)z#Check if the segment contains text.)�boolrCrHr?r?r@�__bool__Vs
zSegment.__bool__cCs|jrdSt|j�S)zGet cell length of segment.r)rErrCrHr?r?r@�cell_lengthZszSegment.cell_lengthcCs
|jduS)z,Check if the segment contains control codes.N)rErHr?r?r@�
is_control_s
zSegment.is_controli@�segment�cut)rArAc
Cs,|\}}}t}|j}||kr||d||�fSt}t||t|��}	|d|	�}
t|
�}||kr@||
||�|||	d�||�fS|	t|�kr�||	}|	d7}	|||�7}|d|	�}
||krn||
||�|||	d�||�fS||kr�||
d|	d�d||�|d||	d�||�fS|	t|�ksFdSdS)NrBr� )rArMr�int�lenr)
�clsrOrPrCrDrE�_SegmentrM�	cell_size�pos�before�cell_pos�charr?r?r@�_split_cellsds6

�
���zSegment._split_cellscCsb|\}}}t|�r+|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.
        rBN)rrSrAr[)rIrPrCrDrEr?r?r@�split_cells�s
	�zSegment.split_cellscCs|d�S)zMake a new line segment.�
r?)rTr?r?r@�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�|�|�VqdSrGr?��.0rC�_stylerE)�applyrTr?r@�	<genexpr>�s
��
�z&Segment.apply_style.<locals>.<genexpr>c3s6�|]\}}}�||r
dn|r|�n�|�VqdSrGr?ra)rTr`r?r@re�s�
���
�)�__add__)rTr_rDr`�result_segmentsr?)rdrTr`r@�apply_style�s�
�zSegment.apply_styleFrNcCs |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.

        rE)�filterrr)rTr_rNr?r?r@�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.
        r]N)�appendrCrE�	partition)
rTr_r^rkrOrCrD�_�_text�new_liner?r?r@�split_lines�s(�

��
	
�zSegment.split_linesT�length�pad�include_new_linesccs��g}|j}|j}|d�}	|D]B}
d|
jvrM|
jsM|
\}}}|rL|�d�\}
}}|
r1|||
|��|rJ|||||d�}|rB|�|	�|V|dd�=|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.
        r])rDrrN)rk�adjust_line_lengthrCrErl)rTr_rqrDrrrsr^rkrt�new_line_segmentrOrCrmrnro�cropped_liner?r?r@�split_and_crop_lines�s4�
�

��

�zSegment.split_and_crop_linesr^c
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�|]}|jVqdSrG)rM�rbrOr?r?r@re@s�z-Segment.adjust_line_length.<locals>.<genexpr>rQNr)�sumrkrMrEr)
rTr^rqrDrr�line_lengthrorkrO�segment_lengthrC�
segment_stylermr?r?r@rt-s.��

�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�|]}�|j�VqdSrG)rCrx��	_cell_lenr?r@rees�z*Segment.get_line_length.<locals>.<genexpr>)rry)rTr^r?r}r@�get_line_lengthZs
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�|]}�|�VqdSrGr?�rbr^�rr?r@rers�z$Segment.get_shape.<locals>.<genexpr>r)r�maxrS)rTr��	max_widthr?r�r@�	get_shapegs
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.
        rQr]Ncsg|]	}�|��d��qS))rDr?r��rtrDr�r?r@�
<listcomp>�s�z%Segment.set_shape.<locals>.<listcomp>)rSrt�extend)	rTr�r�r�rDr��_height�blank�shaped_linesr?r�r@�	set_shapeus&��zSegment.set_shaperTcCs`|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.
        NrQr]�rS�rTr�r�r�rDr��extra_linesr�r?r?r@�	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.
        NrQr]r�r�r?r?r@�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.
        NrQr]rr�)
rTr�r�r�rDr�r�r��	top_lines�bottom_linesr?r?r@�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�
StopIterationrArDrErC)rTr_�
iter_segments�last_segmentrUrOr?r?r@�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)rErD�update_link)rTr_rOrCrD�_controlr?r?r@�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
        Nr?)rTr_rCrcrEr?r?r@�strip_styless�
�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)rTr_�cacherCrDrE�colorless_styler?r?r@�remove_color+s�
�zSegment.remove_color�cutsccs��g}|j}t|�}	zt|�}WntygYSw|dkr"ngVqd}|D]�}|jr�||j}	|	|kr?||�|	}n�zi|	|krr||�|dd�V|dd�=|	}Wzt|�}Wq*tyq|rm|dd�VYdSw|�||�\}
}||
�|dd�V|dd�=|}Wzt|�}Wn3ty�|r�|dd�VYdSwzt|�}Wwty�|r�|dd�VYYdSw|js/q*|dd�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.
        TrN)rkr�r�r�rCrMr\)rTr_r��split_segments�add_segment�	iter_cutsrPrWrO�end_posrXr?r?r@�divideAst���

��
�����zSegment.divide)rFrA)NN�F)NTT)NT)NNF).r,r-r.r/rC�str�__annotations__rDrrrEr
�ControlCoderrJrKrL�propertyrRrMrN�classmethodrrr[r\r^r	rhrjr
rprwrtrr�r�rr�r�r�r�r�r�r�r�r?r?r?r@rA;sD
		$�����(���� ������
�.������,$
�
�����
�#��
�����
���
�����
���
�����
���
�rAc@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.
    Fr_r�rFNcCst|�|_||_dSrG)�listr_r�)rIr_r�r?r?r@�__init__�s

zSegments.__init__�consoler�optionsrrccs<�|jrt��}|jD]}|V|VqdS|jEdHdSrG)r�rAr^r_)rIr�r�r^rOr?r?r@�__rich_console__�s�
�zSegments.__rich_console__r��r�rr�rrFr)	r,r-r.r/r	rArKr�r�r?r?r?r@r�{s���r�c@sBeZdZddeeededdfdd�Z				
			dd
d�ZdS)�SegmentLinesFr�r�rFNcCst|�|_||_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�r?r?r@r��s

zSegmentLines.__init__r�rr�rrccsJ�|jrt��}|jD]
}|EdH|VqdS|jD]}|EdHqdSrG)r�rAr^r�)rIr�r�ror^r?r?r@r��s�

�
�zSegmentLines.__rich_console__r�r�)	r,r-r.r	r
rArKr�r�r?r?r?r@r��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_numberszVWhen you call [b]print()[/b], Rich [i]renders[/i] the object in to the 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)8�enumr�	functoolsr�	itertoolsr�loggingr�operatorr�typingrrr	r
rrr
rrr�cellsrrrr�reprrrrDrr�rrr�logrrRr�rAr�r�r,�pip._vendor.rich.console�pip._vendor.rich.syntaxr��pip._vendor.rich.textr��code�from_markuprC�rule�printr��render�	fragmentsr?r?r?r@�<module>sl0
�C

�
�
�
��