U
    „}ag·^  ã                   @   sú  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZ dd	lmZmZ dd
lmZ er¼ddl m!Z!m"Z"m#Z# edƒZ$G dd„ deƒZ%eee% ee%ee&e'f f ee%e&e&f f Z(eƒ G dd„ deƒƒZ)G dd„ dƒZ*G dd„ dƒZ+e,dk�röd dl-m!Z! d dl.m/Z/ d dl0m1Z1 dZ2e1 3d¡Z4e!ƒ Z e  5d¡ e  6d¡ e  6d¡ e  6e/e2ddd �¡ 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ÚRenderResultÚrichc                   @   sP   e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdS )ÚControlTypezDNon-printable control codes which typically translate to ANSI codes.r   é   é   é   é   é   é   é   é	   é
   é   é   é   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZBELLZCARRIAGE_RETURNÚHOMEZCLEARÚSHOW_CURSORÚHIDE_CURSORZENABLE_ALT_SCREENZDISABLE_ALT_SCREENZ	CURSOR_UPZCURSOR_DOWNZCURSOR_FORWARDZCURSOR_BACKWARDZCURSOR_MOVE_TO_COLUMNZCURSOR_MOVE_TOZERASE_IN_LINEZSET_WINDOW_TITLE© r5   r5   úP/var/www/html/publicvenv/lib/python3.8/site-packages/pip/_vendor/rich/segment.pyr   #   s"   r   c                   @   s*  e Zd ZU dZeed< dZee ed< dZ	ee
e  ed< eedœdd„ƒZedœd	d
„Zedœdd„Zeedœdd„ƒZeedƒd eed dœdd„ƒƒZeed dœdd„Zed dœdd„ƒZedEed  ee ee ed  dœdd„ƒZedFed  eed  dœdd„ƒZeed  eed   d œd!d"„ƒZedGed  eee eeeed   d$œd%d&„ƒZedHed  eee eed  d'œd(d)„ƒZ eed  ed*œd+d,„ƒZ!eeed   eeef d-œd.d/„ƒZ"edIeed   eee ee eeed   d0œd1d2„ƒZ#edJe$d  eed   eeeeeed   d3œd4d5„ƒZ%edKe$d  eed   eeeeeed   d3œd6d7„ƒZ&edLe$d  eed   eeeeeed   d3œd8d9„ƒZ'eed  ed  d œd:d;„ƒZ(eed  ed  d œd<d=„ƒZ)eed  ed  d œd>d?„ƒZ*eed  ed  d œd@dA„ƒZ+eed  ee eed   dBœdCdD„ƒZ,dS )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)Úreturnc                 C   s   | \}}}|rdS t |ƒS )zzThe number of terminal cells required to display self.text.

        Returns:
            int: A number of cells.
        r   )r   )Úselfr8   Ú_styler:   r5   r5   r6   Úcell_lengthQ   s    
zSegment.cell_lengthc                 c   s:   | j V  | jd kr&| jd k	r6| jV  n| jV  | jV  d S ©N)r8   r:   r9   ©r<   r5   r5   r6   Ú__rich_repr__[   s    


zSegment.__rich_repr__c                 C   s
   t | jƒS )z#Check if the segment contains text.)Úboolr8   r@   r5   r5   r6   Ú__bool__d   s    zSegment.__bool__c                 C   s
   | j dk	S )z,Check if the segment contains control codes.N)r:   r@   r5   r5   r6   Ú
is_controlh   s    zSegment.is_controli @  )r7   r7   )ÚsegmentÚcutr;   c                 C   s,  |\}}}t }|j}||kr,||d||ƒfS t}t|| t|ƒd  ƒ}	|d |	… }
t|
ƒ}||kr„||
||ƒ|||	d … ||ƒfS |	t|ƒk �r ||	 }|	d7 }	|||ƒ7 }|d |	… }
||krâ||
||ƒ|||	d … ||ƒfS ||kr„||
d |	d … d ||ƒ|d||	d …  ||ƒfS q„tdƒ‚d S )NÚ r   ú zWill never reach here)r7   r>   r   ÚintÚlenr   ÚAssertionError)ÚclsrE   rF   r8   r9   r:   Ú_Segmentr>   Ú	cell_sizeÚposÚbeforeZcell_posÚcharr5   r5   r6   Ú_split_cellsm   s6    

þ
þþzSegment._split_cells)rF   r;   c                 C   sb   | \}}}t |ƒrV|t|ƒkr.| td||ƒfS t|d|… ||ƒt||d… ||ƒfS |  | |¡S )a0  Split 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.
        rG   N)r   rJ   r7   rR   )r<   rF   r8   r9   r:   r5   r5   r6   Úsplit_cells•   s    	
þzSegment.split_cellsc                 C   s   | dƒS )zMake a new line segment.Ú
r5   )rL   r5   r5   r6   Úline«   s    zSegment.line)Úsegmentsr9   Ú
post_styler;   c                    s>   |}|r"|j ‰ ‡ ‡fdd„|D ƒ}ˆr:‡‡fdd„|D ƒ}|S )a  Apply 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).
        c                 3   s,   | ]$\}}}ˆ||rd nˆ |ƒ|ƒV  qd S r?   r5   ©Ú.0r8   r=   r:   )ÚapplyrL   r5   r6   Ú	<genexpr>Æ   s   ÿz&Segment.apply_style.<locals>.<genexpr>c                 3   s4   | ],\}}}ˆ ||rd n|r$|ˆ nˆ|ƒV  qd S r?   r5   rX   )rL   rW   r5   r6   r[   Ë   s   
÷ÿù)Ú__add__)rL   rV   r9   rW   Zresult_segmentsr5   )rZ   rL   rW   r6   Úapply_style°   s    þ
özSegment.apply_styleF)rV   rD   r;   c                 C   s$   |rt tdƒ|ƒS ttdƒ|ƒS dS )a2  Filter 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.

        r:   N)Úfilterr   r   )rL   rV   rD   r5   r5   r6   Úfilter_controlÙ   s    zSegment.filter_control)rV   r;   c           
      c   s‚   g }|j }|D ]d}d|jkrj|jsj|\}}}|rr| d¡\}}	}|rR|| ||ƒƒ |	r,|V  g }|j }q,q||ƒ q|r~|V  dS )a   Split 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.
        rT   N)Úappendr8   r:   Ú	partition)
rL   rV   rU   r`   rE   r8   r9   Ú_Ú_textÚnew_liner5   r5   r6   Úsplit_linesì   s     



zSegment.split_linesT)rV   Úlengthr9   ÚpadÚinclude_new_linesr;   c                 c   s¸   g }|j }| j}| dƒ}	|D ]€}
d|
jkr”|
js”|
\}}}|rœ| d¡\}}}|r`|| ||ƒƒ |r:|||||d�}|r‚|  |	¡ |V  | ¡  q:q||
ƒ q|r´|||||d�V  dS )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.
        rT   )r9   rg   N)r`   Úadjust_line_lengthr8   r:   ra   Úclear)rL   rV   rf   r9   rg   rh   rU   r`   ri   Znew_line_segmentrE   r8   Úsegment_stylerb   rc   rd   Zcropped_liner5   r5   r6   Úsplit_and_crop_lines	  s2    
   ÿ

zSegment.split_and_crop_lines)rU   rf   r9   rg   r;   c                 C   sÌ   t dd„ |D ƒƒ}||k rF|r8|| d||  |ƒg }qÈ|dd… }n‚||kr¼g }|j}d}|D ]X}|j}	||	 |k s||jrŽ||ƒ ||	7 }q`|\}
}}t|
|| ƒ}
|| |
|ƒƒ  qÈq`n|dd… }|S )a  Adjust 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.
        c                 s   s   | ]}|j V  qd S r?   )r>   )rY   rE   r5   r5   r6   r[   K  s     z-Segment.adjust_line_length.<locals>.<genexpr>rH   Nr   )Úsumr`   r>   r:   r   )rL   rU   rf   r9   rg   Zline_lengthrd   r`   rE   Zsegment_lengthr8   rk   rb   r5   r5   r6   ri   8  s(    

zSegment.adjust_line_length)rU   r;   c                    s   t ‰ t‡ fdd„|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.
        c                 3   s    | ]\}}}|sˆ |ƒV  qd S r?   r5   )rY   r8   r9   r:   ©Ú	_cell_lenr5   r6   r[   p  s      z*Segment.get_line_length.<locals>.<genexpr>)r   rm   )rL   rU   r5   rn   r6   Úget_line_lengthe  s    
zSegment.get_line_length)Úlinesr;   c                    s0   | j ‰ |r t‡ fdd„|D ƒƒnd}|t|ƒfS )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.
        c                 3   s   | ]}ˆ |ƒV  qd S r?   r5   ©rY   rU   ©rp   r5   r6   r[   }  s     z$Segment.get_shape.<locals>.<genexpr>r   )rp   ÚmaxrJ   )rL   rq   Ú	max_widthr5   rs   r6   Ú	get_shaper  s    
zSegment.get_shape)rq   ÚwidthÚheightr9   Ú	new_linesr;   c           	         sŒ   |p
t |ƒ}|r$| dˆ d ˆƒgn| dˆ ˆƒg}| j‰ |d|… }‡ ‡‡fdd„|D ƒ|dd…< t |ƒ|k rˆ| |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.
        rH   rT   Nc                    s   g | ]}ˆ |ˆˆd �‘qS ))r9   r5   rr   ©ri   r9   rw   r5   r6   Ú
<listcomp>�  s    z%Segment.set_shape.<locals>.<listcomp>)rJ   ri   Úextend)	rL   rq   rw   rx   r9   ry   Ú_heightÚblankZshaped_linesr5   rz   r6   Ú	set_shape€  s    &ÿÿzSegment.set_shape)rL   rq   rw   rx   r9   ry   r;   c                 C   s`   |t |ƒ }|s|dd… S |d|… }|r>| d| d |ƒn| d| |ƒ}||gg|  }|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.
        NrH   rT   ©rJ   ©rL   rq   rw   rx   r9   ry   Úextra_linesr~   r5   r5   r6   Ú	align_top¤  s    $zSegment.align_topc                 C   s`   |t |ƒ }|s|dd… S |d|… }|r>| d| d |ƒn| d| |ƒ}|gg| | }|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.
        NrH   rT   r€   r�   r5   r5   r6   Úalign_bottomÁ  s    $zSegment.align_bottomc           
      C   s|   |t |ƒ }|s|dd… S |d|… }|r>| d| d |ƒn| d| |ƒ}|d }|| }	|gg| | |gg|	  }|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.
        NrH   rT   r   r€   )
rL   rq   rw   rx   r9   ry   r‚   r~   Z	top_linesZbottom_linesr5   r5   r6   Úalign_middleÞ  s    $zSegment.align_middlec                 c   sv   t |ƒ}zt|ƒ}W n tk
r*   Y dS X t}|D ]6}|j|jkr`|js`||j|j |jƒ}q4|V  |}q4|V  dS )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ÚStopIterationr7   r9   r:   r8   )rL   rV   Úiter_segmentsZlast_segmentrM   rE   r5   r5   r6   Úsimplifyý  s    

 ÿzSegment.simplifyc                 c   sJ   |D ]@}|j s|jdkr |V  q|\}}}| ||r<| d¡ndƒV  qdS )zÆRemove all links from an iterable of styles.

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

        Yields:
            Segment: Segments with link removed.
        N)r:   r9   Úupdate_link)rL   rV   rE   r8   r9   Ú_controlr5   r5   r6   Ústrip_links  s
    

zSegment.strip_linksc                 c   s"   |D ]\}}}| |d|ƒV  qdS )zÔRemove all styles from an iterable of segments.

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

        Yields:
            Segment: Segments with styles replace with None
        Nr5   )rL   rV   r8   r=   r:   r5   r5   r6   Ústrip_styles)  s    
zSegment.strip_stylesc                 c   sZ   i }|D ]L\}}}|rF|  |¡}|dkr6|j}|||< | |||ƒV  q| |d|ƒV  qdS )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)rL   rV   Úcacher8   r9   r:   Zcolorless_styler5   r5   r6   Úremove_color6  s    
zSegment.remove_color)rV   Úcutsr;   c                 c   sD  g }|j }t|ƒ}t|dƒ}|dkr(g S |dkr2q:g V  qd}|j}|j}	t}
|D ]ä}|\}}}|rR|rl|n
||
|ƒ }||k rŽ||ƒ |}qR||krØ||ƒ |	ƒ V  |ƒ  |}t|dƒ}|dkrÔ|rÎ|	ƒ V   dS qRn6| || ¡\}}|\}}}||ƒ |	ƒ V  |ƒ  |}t|dƒ}|dkr`|�r.|	ƒ V   dS q`qR|	ƒ V  dS )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.
        éÿÿÿÿr   N)r`   r†   r‡   rj   Úcopyr   rS   )rL   rV   r“   Zsplit_segmentsZadd_segmentZ	iter_cutsrF   rO   Zsegments_clearZsegments_copyro   rE   r8   r=   r:   Zend_posrP   r5   r5   r6   ÚdivideL  sX    





zSegment.divide)NN)F)NTT)NT)NNF)F)F)F)-r.   r/   r0   r1   ÚstrÚ__annotations__r9   r   r   r:   r   ÚControlCodeÚpropertyrI   r>   r   rA   rB   rC   rD   Úclassmethodr   r   rR   rS   rU   r	   r]   r_   r
   re   rl   ri   rp   rv   r   r   rƒ   r„   r…   rŠ   r�   rŽ   r’   r–   r5   r5   r5   r6   r7   ?   sì   
		&  üû( ÿ þ   ú
ù.  ûú,"   ú

ù# ú

ù ú

ù ú

ù 
þr7   c                   @   s:   e Zd ZdZdee eddœdd„Zddd	d
œdd„ZdS )Ú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)rV   ry   r;   c                 C   s   t |ƒ| _|| _d S r?   )ÚlistrV   ry   )r<   rV   ry   r5   r5   r6   Ú__init__›  s    
zSegments.__init__r   r   r   ©ÚconsoleÚoptionsr;   c                 c   s8   | j r(t ¡ }| jD ]}|V  |V  qn| jE d H  d S r?   )ry   r7   rU   rV   )r<   r    r¡   rU   rE   r5   r5   r6   Ú__rich_console__Ÿ  s    

zSegments.__rich_console__)F)	r.   r/   r0   r1   r	   r7   rB   rž   r¢   r5   r5   r5   r6   rœ   ’  s    þrœ   c                   @   s:   e Zd Zdeee  eddœdd„Zdddd	œd
d„ZdS )ÚSegmentLinesFN)rq   ry   r;   c                 C   s   t |ƒ| _|| _dS )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�   rq   ry   )r<   rq   ry   r5   r5   r6   rž   ¬  s    
zSegmentLines.__init__r   r   r   rŸ   c                 c   sF   | j r,t ¡ }| jD ]}|E d H  |V  qn| jD ]}|E d H  q2d S r?   )ry   r7   rU   rq   )r<   r    r¡   rd   rU   r5   r5   r6   r¢   ·  s    



zSegmentLines.__rich_console__)F)	r.   r/   r0   r	   r
   r7   rB   rž   r¢   r5   r5   r5   r6   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)zHello, [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   Útypingr   r   r	   r
   r   r   r   r   r   r   Úcellsr   r   r   r   r   Úreprr   r   r9   r   r    r   r   r   Úlogr   rI   r—   r™   r7   rœ   r£   r.   Úpip._vendor.rich.consoleZpip._vendor.rich.syntaxr¥   Úpip._vendor.rich.textr¦   ÚcodeÚfrom_markupr8   ÚruleÚprintr�   ÚrenderÚ	fragmentsr5   r5   r5   r6   Ú<module>   sf   0þÿ    V


ÿ
ÿ


ÿ