HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/rich/__pycache__/segment.cpython-310.pyc
o

;j�d�@s�ddlmZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZmZmZmZmZddlmZmZdd	lmZe	rXdd
lmZm Z m!Z!Gdd�de�Z"eee"ee"ee#e$ffee"e#e#ffZ%e�Gd
d�de
��Z&Gdd�d�Z'Gdd�d�Z(e)dkr�ddl*mZddl+m,Z,ddl-m.Z.dZ/e.�0d�Z1e�Ze�2d�e�3d�e�3d�e�3e,e/ddd��e�3�e�3d�e4e�5e1��Z6e�3e6�e�3�e�3d �e�3e1�e�3d!�d"Sd"S)#�)�IntEnum)�	lru_cache)�filterfalse)�
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�RenderResultc@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�HOMEZCLEARZSHOW_CURSORZHIDE_CURSORZENABLE_ALT_SCREENZDISABLE_ALT_SCREENZ	CURSOR_UPZCURSOR_DOWNZCURSOR_FORWARDZCURSOR_BACKWARDZCURSOR_MOVE_TO_COLUMNZCURSOR_MOVE_TOZ
ERASE_IN_LINEZSET_WINDOW_TITLE�r1r1�@/opt/saltstack/salt/lib/python3.10/site-packages/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�ZedJdd��Ze		dKdeddeedeededfdd��Ze	dLdeddededfdd ��Zededdeedfd!d"��Zededdeeedeffd#d$��Ze		%	%dMdedd&e
deed'ed(edeedfd)d*��Z e		%dNd+edd&e
deed'ededf
d,d-��Z!ed+edde
fd.d/��Z"ed0eeddee
e
ffd1d2��Z#e			dOd0eedd3e
d4ee
deed5edeedfd6d7��Z$e	dLd8e%dd0eedd3e
d4e
ded5edeedfd9d:��Z&e	dLd8e%dd0eedd3e
d4e
ded5edeedfd;d<��Z'e	dLd8e%dd0eedd3e
d4e
ded5edeedfd=d>��Z(ededdedfd?d@��Z)ededdedfdAdB��Z*ededdedfdCdD��Z+ededdedfdEdF��Z,ededdGee
deedfdHdI��Z-dS)P�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)�selfr4�_styler6r1r1r2�cell_lengthNs
zSegment.cell_lengthccsB�|jV|jdur|jdur|jVdSdS|jV|jVdS�N)r4r6r5�r8r1r1r2�
__rich_repr__Xs�

�zSegment.__rich_repr__cCs
t|j�S)z#Check if the segment contains text.)�boolr4r<r1r1r2�__bool__as
zSegment.__bool__cCs
|jduS)z,Check if the segment contains control codes.N)r6r<r1r1r2�
is_controles
zSegment.is_controli@�segment�cut)r3r3c
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)r3r:r�int�lenr)
�clsrArBr4r5r6�_Segmentr:Z	cell_size�pos�beforeZcell_posZout_byr1r1r2�_split_cellsjs6

���
�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.
        rrCN)rrGr3rL)r8rBr4r5r6r1r1r2�split_cells�s
�zSegment.split_cellscCs|d�S)zMake a new line segment.�
r1)rHr1r1r2�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�|�|�VqdSr;r1��.0r4r9r6)�applyrHr1r2�	<genexpr>�s
��
�z&Segment.apply_style.<locals>.<genexpr>c3s6�|]\}}}�||r
dn|r|�n�|�VqdSr;r1rR)rHrQr1r2rU�s�
���
�)�__add__)rHrPr5rQZresult_segmentsr1)rTrHrQr2�apply_style�s�
�zSegment.apply_styleFr@cCs |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.

        r6)�filterrr)rHrPr@r1r1r2�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.
        rNN��appendr4r6�	partition�
rHrPrOr[rAr4r5�_�_text�new_liner1r1r2�split_lines�s(�

��
	
�zSegment.split_linesc
cs��g}|j}|D]5}d|jvr9|js9|\}}}|r8|�d�\}}	}|r*||||��|	r6|dfVg}|j}|sq||�q|rG|dfVdSdS)a2Split a sequence of segments in to a list of lines and a boolean to indicate if there was a new line.

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

        Yields:
            Iterable[List[Segment]]: Iterable of segment lists, one per line.
        rNTFNrZr]r1r1r2�split_lines_terminators(�

��
	�zSegment.split_lines_terminatorT�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.
        rN)r5rdN)r[�adjust_line_lengthr4r6r\�clear)rHrPrcr5rdrerOr[rfZnew_line_segmentrAr4�
segment_styler^r_r`Zcropped_liner1r1r2�split_and_crop_lines2s4�
�
��

�zSegment.split_and_crop_linesrOc
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�|]}|jVqdSr;)r:)rSrAr1r1r2rUts�z-Segment.adjust_line_length.<locals>.<genexpr>rENr)�sumr[r:r6r)
rHrOrcr5rdZline_lengthr`r[rAZsegment_lengthr4rhr^r1r1r2rfas.��

�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�|�VqdSr;r1)rSr4r5r6��	_cell_lenr1r2rU�s� z*Segment.get_line_length.<locals>.<genexpr>)rrj)rHrOr1rkr2�get_line_length�s
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�|]}�|�VqdSr;r1�rSrO�rmr1r2rU�s�z$Segment.get_shape.<locals>.<genexpr>r)rm�maxrG)rHrnZ	max_widthr1rpr2�	get_shape�s
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.
        rErNNcsg|]	}�|��d��qS))r5r1ro�rfr5rsr1r2�
<listcomp>�s�z%Segment.set_shape.<locals>.<listcomp>)rGrf�extend)	rHrnrsrtr5ruZ_height�blankZshaped_linesr1rvr2�	set_shape�s&��zSegment.set_shaperHcCs`|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.
        NrErN�rG�rHrnrsrtr5ru�extra_linesryr1r1r2�	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.
        NrErNr{r|r1r1r2�align_bottom�rzSegment.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.
        NrErNrr{)
rHrnrsrtr5rur}ryZ	top_linesZbottom_linesr1r1r2�align_middles$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�
StopIterationr3r5r6r4)rHrPZ
iter_segmentsZlast_segmentrIrAr1r1r2�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)r6r5Zupdate_link)rHrPrAr4r5Z_controlr1r1r2�strip_linksAs�

�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
        Nr1)rHrPr4r9r6r1r1r2�strip_stylesRs�
�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)�getZ
without_color)rHrP�cacher4r5r6Zcolorless_styler1r1r2�remove_color_s�
�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.
        TrDNr)r[r�r�rg�copyrrM)rHrPr�Zsplit_segmentsZadd_segmentZ	iter_cutsrBrJZsegments_clearZ
segments_copyrlrAr4r9r6Zend_posrKr1r1r2�divideusb�
�



��#zSegment.divide)r7r3)NN�F)NTT)NT)NNF).r,r-r.r/�str�__annotations__r5rrr6r�ControlCode�propertyrFr:rr=r>r?r@�classmethodrr
rLrMrOrrWrYr	rarbrirfrmrrrzrr~r�r�r�r�r�r�r�r1r1r1r2r3<sJ
		/�����(���� ��������
�.������,$
�
�����
�#��
�����
���
�����
���
�����
���
�r3c@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.
    FrPrur7NcCst|�|_||_dSr;)�listrPru)r8rPrur1r1r2�__init__�s

zSegments.__init__�consoler�optionsrrccs<�|jrt��}|jD]}|V|VqdS|jEdHdSr;)rur3rOrP)r8r�r�rOrAr1r1r2�__rich_console__�s�
�zSegments.__rich_console__r��r�rr�rr7r)	r,r-r.r/rr3r>r�r�r1r1r1r2r��s���r�c@sBeZdZddeeededdfdd�Z				
			dd
d�ZdS)�SegmentLinesFrnrur7NcCst|�|_||_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�rnru)r8rnrur1r1r2r��s

zSegmentLines.__init__r�rr�rrccsJ�|jrt��}|jD]
}|EdH|VqdS|jD]}|EdHqdSr;)rur3rOrn)r8r�r�r`rOr1r1r2r��s�

�
�zSegmentLines.__rich_console__r�r�)	r,r-r.rr	r3r>r�r�r1r1r1r2r��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)7�enumr�	functoolsr�	itertoolsr�operatorr�typingrrrr	r
rrr
rrZcellsrrrrr�reprrrr5rr�rrrrrFr�r�r3r�r�r,Zrich.consoleZrich.syntaxr�Z	rich.textr��codeZfrom_markupr4Zrule�printr�ZrenderZ	fragmentsr1r1r1r2�<module>sh0
��

�
�


��