%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/rich/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/rich/__pycache__/segment.cpython-312.pyc

�

"T�e�^���ddlmZddlmZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZmZmZmZddlmZmZmZmZmZdd	lmZmZdd
lmZer
ddl m!Z!m"Z"m#Z#ed�Z$Gd
�de�Z%eee%ee%ee&e'ffee%e&e&ffZ(e�Gd�de��Z)Gd�d�Z*Gd�d�Z+e,dk(�rddl-m!Z!ddl.m/Z/ddl0m1Z1dZ2e1jfd�Z4e!�Z e jkd�e jmd�e jmd�e jme/e2dd� ��e jm�e jmd!�e7e jqe4��Z9e jme9�e jm�e jmd"�e jme4�e jmd#�y$y$)%�)�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�P�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZdZdZy)�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���./usr/lib/python3/dist-packages/rich/segment.pyr r #sY��N��D��O��D�
�E��K��K������I��K��N��O����N��M��rEr c�v�eZdZUdZeed<dZeeed<dZ	ee
eed<ede
fd��Zdefd�Zdefd	�Zedefd
��Zeed�ddd
e
dedfd���Zd
e
dedfd�Zed/d��Ze		d0deddeedeededfd��Ze	d1deddededfd��Zededdeedfd��Ze			d2dedde
deedededeedfd��Ze		d3dedde
deedededf
d��Z ededde
fd��Z!edeeddee
e
ffd ��Z"e			d4deedd!e
d"ee
deed#edeedfd$��Z#e	d1d%e$ddeedd!e
d"e
ded#edeedfd&��Z%e	d1d%e$ddeedd!e
d"e
ded#edeedfd'��Z&e	d1d%e$ddeedd!e
d"e
ded#edeedfd(��Z'ededdedfd)��Z(ededdedfd*��Z)ededdedfd+��Z*ededdedfd,��Z+ededd-ee
deedfd.��Z,y)5�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�returnc�,�|\}}}|rdSt|�S)zzThe number of terminal cells required to display self.text.

        Returns:
            int: A number of cells.
        r)r)�selfrI�_stylerKs    rF�cell_lengthzSegment.cell_lengthQs!��!%���f�g��q�/��$��/rEc#�K�|j��|j�|j�|j��yy|j��|j��y�w�N)rIrKrJ�rNs rF�
__rich_repr__zSegment.__rich_repr__[sH�����i�i���<�<���z�z�%��j�j� �&��*�*���,�,��s�AAc�,�t|j�S)z#Check if the segment contains text.)�boolrIrSs rF�__bool__zSegment.__bool__ds���D�I�I��rEc��|jduS)z,Check if the segment contains control codes.N)rKrSs rF�
is_controlzSegment.is_controlhs���|�|�4�'�'rEi@�segment�cut)rHrHc��|\}}}t}|j}||k\r||d||�fSt}t||zt	|�dz
z�}	|d|	}
t|
�}||k(r||
||�|||	d||�fS|	t	|�krm||	}|	dz
}	|||�z
}|d|	}
||k(r||
||�|||	d||�fS||kDr#||
d|	dz
dz||�|d||	dz||�fS|	t	|�kr�mt
d��)N�r� zWill never reach here)rHrPr�int�lenr�AssertionError)
�clsrZr[rIrJrK�_SegmentrP�	cell_size�pos�before�cell_pos�chars
             rF�_split_cellszSegment._split_cellsmsi�� '���e�W����)�)���+���H�R���8�8�8�+�	��3��$��T��Q��7�8���d�s����F�#���s�?�����0���c�d��U�G�4��
��C��I�o���9�D��1�H�C��	�$��'�H��$�3�Z�F��3���V�U�G�4��T�#�$�Z���8����#�~��V�I�c�A�g�.��4�e�W�E��S�4���:�-�u�g�>����C��I�o� �4�5�5rEc���|\}}}t|�r=|t|�k\r|td||�fSt|d|||�t||d||�fS|j||�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.
        r]N)rr`rHri)rNr[rIrJrKs     rF�split_cellszSegment.split_cells�s{�� $���e�W�!�$�'��c�$�i���W�R���8�8�8���T�c�
�E�7�3���S�T�
�E�7�3��
�
� � ��s�+�+rEc��|d�S)zMake a new line segment.�
rD)rbs rF�linezSegment.line�s���4�y�rE�segments�
post_stylec�`����|}|r|j���fd�|D�}�r��fd�|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).
        c3�N�K�|]\}}}�||rdn�|�|����y�wrRrD)�.0rIrOrK�applyrbs    ��rF�	<genexpr>z&Segment.apply_style.<locals>.<genexpr>�s0������)�D�&�'��D�'�$�u�V�}�g�F��s�"%c3�P�K�|]\}}}�||rdn|r|�zn�|����y�wrRrD)rsrIrOrKrbrps    ��rFruz&Segment.apply_style.<locals>.<genexpr>�sB������*�D�&�'���#��5;�f�z�1�����s�#&)�__add__)rbrorJrp�result_segmentsrts`  ` @rF�apply_stylezSegment.apply_style�sC���&#����M�M�E��-<��O���.=��O��rErYc�Z�|rttd�|�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.

        rK)�filterrr)rbrorYs   rF�filter_controlzSegment.filter_control�s+����*�Y�/��:�:��z�)�4�h�?�?rEc#�K�g}|j}|D]k}d|jvrS|jsG|\}}}|s�&|jd�\}}	}|r||||��|	r|��g}|j}|r�=�d||��m|r|��yy�w)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.
        rmN)�appendrIrK�	partition)
rbrornr~rZrIrJ�_�_text�new_lines
          rF�split_lineszSegment.split_lines�s�����!�������	 �G��w�|�|�#�G�O�O�!(���e�Q��,0�N�N�4�,@�)�E�8�T���s�5�%�0�1��"�
�!��!%������w��	 ���J��s�6B	�<B	�6B	�length�pad�include_new_linesc#�K�g}|j}|j}|d�}	|D]�}
d|
jvrt|
jsh|
\}}}
|s�&|j	d�\}}}|r||||��|r3|||||��}|r|j|	�|��|j�|r�^��||
���|r|||||����yy�w)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.
        rm)rJr�N)r~�adjust_line_lengthrIrKr�clear)rbror�rJr�r�rnr~r��new_line_segmentrZrI�
segment_styler�r�r��cropped_lines                 rF�split_and_crop_lineszSegment.split_and_crop_liness�����*!������ �3�3���t�9���	 �G��w�|�|�#�G�O�O�)0�&��m�Q��,0�N�N�4�,@�)�E�8�T���s�5�-�8�9��'9� �&��3�(��-�(�/�/�0@�A�*�*��
�
����w��!	 �"�$�T�6��C�H�H��s�A
C�
AC�+Crnc�^�td�|D��}||kr|r||d||z
z|�gz}|S|dd}|S||kDrmg}|j}d}|D]V}|j}	||	z|ks|jr||�||	z
}�1|\}
}}t	|
||z
�}
|||
|��|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.
        c3�4K�|]}|j���y�wrR)rP)rsrZs  rFruz-Segment.adjust_line_length.<locals>.<genexpr>Js����B�'�'�-�-�B�s�r^Nr)�sumr~rPrKr)
rbrnr�rJr��line_lengthr�r~rZ�segment_lengthrIr�r�s
             rFr�zSegment.adjust_line_length7s��&�B�T�B�B�������3�s�f�{�.B�'C�U�#K�"L�L��&��# ��7��"��!�6�
!��H��_�_�F��K��	
��!(�!4�!4����/�&�8�G�O�O��7�O��>�1�K�-4�*�D�-��(��v��/C�D�D��3�t�]�3�4����	
����A�w�H��rEc�8��t�t�fd�|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.
        c3�<�K�|]\}}}|r�
�|����y�wrRrD)rsrIrJrK�	_cell_lens    �rFruz*Segment.get_line_length.<locals>.<genexpr>os�����S�';�t�U�G�7�9�T�?�S�s��
)rr�)rbrnr�s  @rF�get_line_lengthzSegment.get_line_lengthds����	��S�t�S�S�SrE�linesc�f��|j�|rt�fd�|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.
        c3�.�K�|]}�|����y�wrRrD)rsrnr�s  �rFruz$Segment.get_shape.<locals>.<genexpr>|s�����@�$���-�@�s�r)r��maxr`)rbr��	max_widthr�s   @rF�	get_shapezSegment.get_shapeqs3����-�-��DI�C�@�%�@�@�q�	��3�u�:�&�&rE�width�height�	new_linesc�$�|xst|�}|r|d|zdz|�gn|d|z|�g}|j}|d|}	|D�
cgc]
}
||
||����c}
|	ddt|	�|kr!|	j|g|t|	�z
z�|	Scc}
w)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.
        r^rmN)rJ)r`r��extend)rbr�r�r�rJr��_height�blankr��shaped_linesrns           rF�	set_shapezSegment.set_shapes���*�&�C��J��1:�S��u��t�#�U�
+�,��C�%�K�QV�@W�?X�	�!�3�3���X�g���EJ�
�=A��t�U�%�8�
��Q���|��w�&������7�S��5F�+F� G�H����
s�B
rbc��|t|�z
}|s|ddS|d|}|r|d|zdz|�n|d|z|�}||gg|zz}|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.
        Nr^rm�r`�rbr�r�r�rJr��extra_linesr�s        rF�	align_topzSegment.align_top�sf��*�s�5�z�)�����8�O��g�v���2;��C�%�K�$�&��.��S�5�[�RW�AX���%��	�K�/�/���rEc��|t|�z
}|s|ddS|d|}|r|d|zdz|�n|d|z|�}|gg|z|z}|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.
        Nr^rmr�r�s        rF�align_bottomzSegment.align_bottom�sf��*�s�5�z�)�����8�O��g�v���2;��C�%�K�$�&��.��S�5�[�RW�AX����	�K�'�%�/���rEc��|t|�z
}|s|ddS|d|}|r|d|zdz|�n|d|z|�}|dz}||z
}	|gg|z|z|gg|	zz}|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.
        Nr^rmr!r�)
rbr�r�r�rJr�r�r��	top_lines�bottom_liness
          rF�align_middlezSegment.align_middle�s���*�s�5�z�)�����8�O��g�v���2;��C�%�K�$�&��.��S�5�[�RW�AX���1�$�	�"�Y�.����	�I�%��-�%��	�L�0H�H���rEc#�&K�t|�}	t|�}t}|D]X}|j|jk(r7|j
s+||j|jz|j�}�S|��|}�Z|��y#t$rYywxYw�w)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�
StopIterationrHrJrKrI)rbro�
iter_segments�last_segmentrcrZs      rF�simplifyzSegment.simplify�s������X��
�	��
�.�L���$�	'�G��!�!�W�]�]�2�7�?�?�'� �%�%����4�l�6H�6H� ��#�"�&��	'�����	��	�s(�B�B�A(B�	B�B�
B�Bc#�K�|D]C}|js|j�|��� |\}}}|||r|jd�nd����Ey�w)z�Remove all links from an iterable of styles.

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

        Yields:
            Segment: Segments with link removed.
        N)rKrJ�update_link)rbrorZrIrJ�_controls      rF�strip_linkszSegment.strip_linkssV���� �	L�G����'�-�-�"7��
�(/�%��e�X��$�5�� 1� 1�$� 7�d�K�K�	L�s�A
Ac#�:K�|D]\}}}||d|����y�w)z�Remove all styles from an iterable of segments.

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

        Yields:
            Segment: Segments with styles replace with None
        NrD)rbrorIrOrKs     rF�strip_styleszSegment.strip_styles(s-����&.�	+�!�D�&�'��d�D�'�*�*�	+�s�c#�K�i}|D]E\}}}|r1|j|�}|�|j}|||<||||����:||d|����Gy�w)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)rbro�cacherIrJrK�colorless_styles       rF�remove_colorzSegment.remove_color5sl����%'��$,�	/� �D�%���"'�)�)�E�"2��"�*�&+�&9�&9�O�#2�E�%�L��$���9�9��$��g�.�.�	/�s�AA�cutsc#�XK�g}|j}t|�}	t|d�}|dk(rgS|dk7rng���d}|j}|j}	t
}
|D]�}|\}}
}|s�|r|n
||
|�z}||kr||�|}�+||k(r9||�|	���|�|}t|d�}|dk(r
|r	|	���y�i|j
||z
�\}}|\}}
}||�|	���|�|}t|d�}|dk(r
|r	|	���y|r����|	���y�w)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�r��copyrrk)rbror��split_segments�add_segment�	iter_cutsr[re�segments_clear�
segments_copyr�rZrIrOrK�end_posrfs                 rF�dividezSegment.divideKsr����+-��$�+�+����J�	���y�"�%�C��b�y��	��a�x���H�
���'�-�-��&�+�+�
�#�	��#	�G�$+�!�D�&�'��!(�#�c�I�d�O�.C���S�=���(�!�C���c�>���(�'�/�)�"�$�!�C��y�"�-�C��b�y�)�"/�/�1���'.�&9�&9�#��)�&D�O�F�G�,3�)�D�&�'���'�'�/�)�"�$��C��9�b�)���"�9�%�+�o�-��C�#	�J�o��s�A&D*�)B4D*�D*)rLrH)NN�F)NTT)NT)NNF)-r0r1r2r3�str�__annotations__rJr
rrKr�ControlCode�propertyr_rPrrTrVrWrY�classmethodrrrirkrnr
ryr|rr�r�r�r�r�r�rr�r�r�r�r�r�r�r�rDrErFrHrH?s���
��I�!�E�8�E�?�!�/3�G�X�h�{�+�
,�3�
�0�S�0��0��v���$���(�D�(��(���y��#6�9�#6�3�#6�5�AU�;V�#6���#6�J,�s�,�u�-A�'B�,�,�����"&�&*�	&��9�%�&����&��U�O�	&�

�)�	�&��&�P�?D�@��	�*�@�8<�@�	�)�	�@��@�$��8�I�#6��8�D��O�;T����8�
"&��"&�
,I��9�%�,I��,I����	,I�
�,I� �
,I�
�$�y�/�	"�,I��,I�\�
"&��*��9�o�*��*����	*�
�*�
�i��
*��*�X�
T�4�	�?�
T�s�
T��
T��'�d�4�	�?�3�'��c�3�h��'��'��
!%�!%��
!��D��O�$�!��!���
�	!�
���!��
!�
�d�9�o�	�!��!�F� �
�
�)�_���D��O�$�����	�
���
�
�d�9�o�	����8� �
�
�)�_���D��O�$�����	�
���
�
�d�9�o�	����8� �
�
�)�_���D��O�$�����	�
���
�
�d�9�o�	����<���� 3����8K����4�L�8�I�#6�L�8�I�;N�L��L� �
+�H�Y�$7�
+�H�Y�<O�
+��
+��/�H�Y�$7�/�H�Y�<O�/��/�*�B��	�*�B�2:�3�-�B�	�$�y�/�	"�B��BrErHc�@�eZdZdZddeededdfd�Z						d	d�Zy)
�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.
    ror�rLNc�2�t|�|_||_yrR)�listror�)rNror�s   rF�__init__zSegments.__init__�s���X���
�"��rEc#�K�|jr.tj�}|jD]
}|��|���y|jEd{���y7��wrR)r�rHrnro)rN�console�optionsrnrZs     rF�__rich_console__zSegments.__rich_console__�sF�����>�>��<�<�>�D��=�=�
���
��
�
��}�}�$�$�s�A
A�A�
Ar��r�rr�rrLr)	r0r1r2r3r
rHrVr�r�rDrErFr�r��sD���#��'�!2�#�t�#�PT�#�	%� �	%�+;�	%�	�	%rEr�c�B�eZdZddeeededdfd�Z						dd�Zy)	�SegmentLinesr�r�rLNc�2�t|�|_||_y)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�)rNr�r�s   rFr�zSegmentLines.__init__�s���%�[��
�"��rEc#��K�|jr4tj�}|jD]}|Ed{���|���y|jD]}|Ed{����y7�'7�	�wrR)r�rHrnr�)rNr�r�r�rns     rFr�zSegmentLines.__rich_console__�s`�����>�>��|�|�~�H��
�
�
�������
��
�
�
 �����
 � �� �s!�5A#�A�A#�A!�A#�!A#r�r�)	r0r1r2r
rrHrVr�r�rDrErFr�r��sC��	#�h�t�G�}�5�	#�$�	#�SW�	#�
 � �
 �+;�
 �	�
 rEr��__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�typingrr	r
rrr
rrrr�cellsrrrrr�reprrrrJrr�rrr�logr r_r�r�rHr�r�r0�rich.console�rich.syntaxr��	rich.textr��code�from_markuprI�rule�printr��render�	fragmentsrDrErF�<module>r�s�����!��������$���>�>������'��*�	�+��	�+�u�S�#�X��
&�'�	�+�s�C�
� �"�����N	�j�N	�
�N	�b%�%�2 � �2�z��$�"���D�
�4���<�=�D��i�G��L�L�� ��M�M�g���M�M�4�5��M�M�&��x�d�;�<��M�M�O��M�M�]���W�^�^�D�)�*�I��M�M�)���M�M�O��M�M�V�W��M�M�$���M�M�^��;rE

Zerion Mini Shell 1.0