a
    ýÓEbl]  ã                   @   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 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%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ôe*dk�rôd dl+m Z  d dl,m-Z- d dl.m/Z/ dZ0e/ 1d¡Z2e ƒ Ze 3d¡ e 4d¡ e 4d¡ e 4e-e0ddd �¡ e 4¡  e 4d!¡ e5e 6e2¡ƒZ7e 4e7¡ e 4¡  e 4d"¡ e 4e2¡ e 4d#¡ d$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                   @   sL   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S )ÚControlTypezDNon-printable control codes which typically translate to ANSI codes.r   é   é   é   é   é   é   é   é	   é
   é   é   é   é   é   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ZBELLZCARRIAGE_RETURNÚHOMEZCLEARZSHOW_CURSORZ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_LINE© r1   r1   úX/home/ja/django-apps/lartica_env/lib/python3.9/site-packages/pip/_vendor/rich/segment.pyr   "   s    r   c                   @   s.  e Zd ZU dZdZeed< dZee	 ed< dZ
eee  ed< edœdd	„Zedœd
d„Ze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dFed  ee	 ee	 ed  dœdd„ƒZedGed  eed  dœdd „ƒZeed  eed   d!œd"d#„ƒZedHed  eee	 eeeed   d%œd&d'„ƒZ edIe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/d0„ƒZ#edJeed   eee ee	 eeed   d1œd2d3„ƒZ$edKe%d  eed   eee	eeed   d4œd5d6„ƒZ&edLe%d  eed   eee	eeed   d4œd7d8„ƒZ'edMe%d  eed   eee	eeed   d4œd9d:„ƒ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!œdAdB„ƒZ,eed  ee eed   dCœdDdE„ƒZ-dS )NÚ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)Úreturnc                 c   s:   | j V  | jd u r&| jd ur6| jV  n| jV  | jV  d S ©N)r5   r7   r6   ©Úselfr1   r1   r2   Ú__rich_repr__M   s    


zSegment.__rich_repr__c                 C   s
   t | jƒS )z#Check if the segment contains text.)Úboolr5   r:   r1   r1   r2   Ú__bool__V   s    zSegment.__bool__c                 C   s   | j r
dS t| jƒS )zGet cell length of segment.r   )r7   r   r5   r:   r1   r1   r2   Úcell_lengthZ   s    zSegment.cell_lengthc                 C   s
   | j duS )z,Check if the segment contains control codes.N)r7   r:   r1   r1   r2   Ú
is_control_   s    zSegment.is_controli @  )r3   r3   )ÚsegmentÚcutr8   c                 C   s   |\}}}t }|j}||kr,||d||ƒfS t}t|| t|ƒ ƒ}	|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€d S )Nr4   r   ú )r3   r?   r   ÚintÚlenr   )ÚclsrA   rB   r5   r6   r7   Ú_Segmentr?   Z	cell_sizeÚposÚbeforeZcell_posÚcharr1   r1   r2   Ú_split_cellsd   s4    

þ
þþzSegment._split_cells)rB   r8   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.
        r4   N)r   rE   r3   rK   )r;   rB   r5   r6   r7   r1   r1   r2   Úsplit_cellsŠ   s    	
þzSegment.split_cellsc                 C   s   | dƒS )zMake a new line segment.Ú
r1   )rF   r1   r1   r2   Úline    s    zSegment.line)Úsegmentsr6   Ú
post_styler8   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 r9   r1   ©Ú.0r5   Ú_styler7   )ÚapplyrF   r1   r2   Ú	<genexpr>»   s   ÿz&Segment.apply_style.<locals>.<genexpr>c                 3   s4   | ],\}}}ˆ ||rd n|r$|ˆ nˆ|ƒV  qd S r9   r1   rQ   )rF   rP   r1   r2   rU   À   s   
÷ÿù)Ú__add__)rF   rO   r6   rP   Zresult_segmentsr1   )rT   rF   rP   r2   Úapply_style¥   s    þ
özSegment.apply_styleF)rO   r@   r8   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.

        r7   N)Úfilterr   r   )rF   rO   r@   r1   r1   r2   Úfilter_controlÎ   s    zSegment.filter_control)rO   r8   c           
      c   s‚   g }|j }|D ]d}d|jv 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.
        rM   N)Úappendr5   r7   Ú	partition)
rF   rO   rN   rZ   rA   r5   r6   Ú_Ú_textÚnew_liner1   r1   r2   Úsplit_linesá   s     



zSegment.split_linesT)rO   Úlengthr6   ÚpadÚinclude_new_linesr8   c                 c   sº   g }|j }| j}| dƒ}	|D ]‚}
d|
jv r–|
js–|
\}}}|rž| d¡\}}}|r`|| ||ƒƒ |r:|||||d�}|r‚|  |	¡ |V  |dd…= 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.
        rM   )r6   ra   N)rZ   Úadjust_line_lengthr5   r7   r[   )rF   rO   r`   r6   ra   rb   rN   rZ   rc   Znew_line_segmentrA   r5   r\   r]   r^   Zcropped_liner1   r1   r2   Úsplit_and_crop_linesþ   s,    
ÿ

zSegment.split_and_crop_lines)rN   r`   r6   ra   r8   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 r9   )r?   ©rR   rA   r1   r1   r2   rU   @  ó    z-Segment.adjust_line_length.<locals>.<genexpr>rC   Nr   )ÚsumrZ   r?   r7   r   )rF   rN   r`   r6   ra   Zline_lengthr^   rZ   rA   Zsegment_lengthr5   Zsegment_styler\   r1   r1   r2   rc   -  s(    

zSegment.adjust_line_length)rN   r8   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   | ]}ˆ |j ƒV  qd S r9   )r5   re   ©Z	_cell_lenr1   r2   rU   e  rf   z*Segment.get_line_length.<locals>.<genexpr>)r   rg   )rF   rN   r1   rh   r2   Úget_line_lengthZ  s    
zSegment.get_line_length)Úlinesr8   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 r9   r1   ©rR   rN   ©ri   r1   r2   rU   r  rf   z$Segment.get_shape.<locals>.<genexpr>r   )ri   ÚmaxrE   )rF   rj   Ú	max_widthr1   rl   r2   Ú	get_shapeg  s    
zSegment.get_shape)rj   ÚwidthÚheightr6   Ú	new_linesr8   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.
        rC   rM   Nc                    s   g | ]}ˆ |ˆˆd �‘qS ))r6   r1   rk   ©rc   r6   rp   r1   r2   Ú
<listcomp>’  s   z%Segment.set_shape.<locals>.<listcomp>)rE   rc   Úextend)	rF   rj   rp   rq   r6   rr   Ú_heightÚblankZshaped_linesr1   rs   r2   Ú	set_shapeu  s    &ÿÿzSegment.set_shape)rF   rj   rp   rq   r6   rr   r8   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.
        NrC   rM   ©rE   ©rF   rj   rp   rq   r6   rr   Úextra_linesrw   r1   r1   r2   Ú	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.
        NrC   rM   ry   rz   r1   r1   r2   Ú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.
        NrC   rM   r   ry   )
rF   rj   rp   rq   r6   rr   r{   rw   Z	top_linesZbottom_linesr1   r1   r2   Úalign_middleÓ  s    $zSegment.align_middlec                 c   st   t |ƒ}zt|ƒ}W n ty(   Y dS 0 t}|D ]6}|j|jkr^|js^||j|j |jƒ}q2|V  |}q2|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ÚStopIterationr3   r6   r7   r5   )rF   rO   Ziter_segmentsZlast_segmentrG   rA   r1   r1   r2   Úsimplifyò  s    
ÿzSegment.simplifyc                 c   sJ   |D ]@}|j s|jdu 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)r7   r6   Úupdate_link)rF   rO   rA   r5   r6   Ú_controlr1   r1   r2   Ú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
        Nr1   )rF   rO   r5   rS   r7   r1   r1   r2   Ústrip_styles  s    
zSegment.strip_stylesc                 c   sZ   i }|D ]L\}}}|rF|  |¡}|du 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)rF   rO   Úcacher5   r6   r7   Zcolorless_styler1   r1   r2   Úremove_color+  s    
zSegment.remove_color)rO   Úcutsr8   c                 c   s´  g }|j }t|ƒ}zt|ƒ}W n ty4   g  Y S 0 |dkr@qHg V  qd}|D �]N}|jrP||j }	|	|k r|||ƒ |	}qPzÜ|	|kræ||ƒ |dd… V  |dd…= |	}W zt|ƒ}W n( tyà   |rØ|dd… V  Y  dS 0 qPn6| || ¡\}
}||
ƒ |dd… V  |dd…= |}W zt|ƒ}W n, t�yV   |�rN|dd… V  Y  dS 0 qVzt|ƒ}W n4 t�yš   |�rŠ|dd… V  Y    Y  dS 0 0 qVqP|dd… 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)rZ   r   r€   r�   r5   r?   rL   )rF   rO   r‹   Zsplit_segmentsZadd_segmentZ	iter_cutsrB   rH   rA   Zend_posrI   r1   r1   r2   ÚdivideA  sd    




ó
ûzSegment.divide)NN)F)NTT)NT)NNF)F)F)F).r,   r-   r.   r/   r5   ÚstrÚ__annotations__r6   r   r   r7   r   ÚControlCoder   r<   r=   r>   ÚpropertyrD   r?   r@   Úclassmethodr   r   rK   rL   rN   r	   rW   rY   r
   r_   rd   rc   ri   ro   rx   r   r|   r}   r~   r‚   r…   r†   rŠ   rŒ   r1   r1   r1   r2   r3   ;   sè   
		$  üû( ÿþ   ú
ù.  ûú,"   ú

ù# ú

ù ú

ù ú

ù
þr3   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)rO   rr   r8   c                 C   s   t |ƒ| _|| _d S r9   )ÚlistrO   rr   )r;   rO   rr   r1   r1   r2   Ú__init__„  s    
zSegments.__init__r   r   r   ©ÚconsoleÚoptionsr8   c                 c   s8   | j r(t ¡ }| jD ]}|V  |V  qn| jE d H  d S r9   )rr   r3   rN   rO   )r;   r–   r—   rN   rA   r1   r1   r2   Ú__rich_console__ˆ  s    

zSegments.__rich_console__)F)	r,   r-   r.   r/   r	   r3   r=   r”   r˜   r1   r1   r1   r2   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)rj   rr   r8   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“   rj   rr   )r;   rj   rr   r1   r1   r2   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 r9   )rr   r3   rN   rj   )r;   r–   r—   r^   rN   r1   r1   r2   r˜      s    



zSegmentLines.__rich_console__)F)	r,   r-   r.   r	   r
   r3   r=   r”   r˜   r1   r1   r1   r2   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_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   Útypingr   r   r	   r
   r   r   r   r   r   r   Úcellsr   r   r   r   Úreprr   r   r6   r   r–   r   r   r   Úlogr   rD   r�   r3   r’   r™   r,   Úpip._vendor.rich.consoleZpip._vendor.rich.syntaxr›   Úpip._vendor.rich.textrœ   ÚcodeÚfrom_markupr5   ÚruleÚprintr“   ÚrenderÚ	fragmentsr1   r1   r1   r2   Ú<module>   sf   0ÿ    C



ÿ
ÿ
ÿ
ÿ