
    Kxh^                     D   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e          Z%eee%         ee%ee&e'f         f         ee%e&e&f         f         Z( e             G d de                      Z) G d d          Z* G d d          Z+e,dk    r?d dl-m!Z! d dl.m/Z/ d dl0m1Z1 dZ2 e1j3        d          Z4 e!            Z e 5                    d           e 6                    d           e 6                    d           e 6                     e/e2dd                      e 6                                 e 6                    d!            e7e 8                    e4                    Z9e 6                    e9           e 6                                 e 6                    d"           e 6                    e4           e 6                    d#           d$S 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                   R    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__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     K/var/www/html/what/lib/python3.11/site-packages/pip/_vendor/rich/segment.pyr    r    #   sj        NNDODEKKIKNONMrE   r    c                   X   e Zd ZU dZeed<   dZee         ed<   dZ	ee
e                  ed<   edefd            ZdefdZdefd	Zedefd
            Ze ed          dd deded         fd                        Zdeded         fdZed1d            Ze	 	 d2ded          dee         dee         ded          fd            Ze	 d3ded          deded          fd            Zeded          deed                   fd            Ze	 	 	 d4ded          dedee         dededeed                   fd            Ze	 	 d5ded          dedee         deded          f
d            Z eded          defd             Z!ed!eed                   deeef         fd"            Z"e	 	 	 d6d!eed                   d#ed$ee         dee         d%edeed                   fd&            Z#e	 d3d'e$d          d!eed                   d#ed$eded%edeed                   fd(            Z%e	 d3d'e$d          d!eed                   d#ed$eded%edeed                   fd)            Z&e	 d3d'e$d          d!eed                   d#ed$eded%edeed                   fd*            Z'eded          ded          fd+            Z(eded          ded          fd,            Z)eded          ded          fd-            Z*eded          ded          fd.            Z+eded          d/ee         deed                   fd0            Z,dS )7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                 4    | \  }}}|rdnt          |          S )zzThe number of terminal cells required to display self.text.

        Returns:
            int: A number of cells.
        r   )r   )selfrI   _stylerK   s       rF   cell_lengthzSegment.cell_lengthQ   s%     !%fg/qq$/rE   c              #   v   K   | j         V  | j        | j        | j        V  d S d S | j        V  | j        V  d S N)rI   rK   rJ   rN   s    rF   __rich_repr__zSegment.__rich_repr__[   sa      i<z%j      &% *,rE   c                 *    t          | j                  S )z#Check if the segment contains text.)boolrI   rS   s    rF   __bool__zSegment.__bool__d   s    DIrE   c                     | j         duS )z,Check if the segment contains control codes.N)rK   rS   s    rF   
is_controlzSegment.is_controlh   s     |4''rE   i @  segmentcut)rH   rH   c                    |\  }}}t           }|j        }||k    r| |d||          fS t          }t          ||z  t	          |          z            }	|d |	         }
t          |
          }||k    r" ||
||           |||	d          ||          fS |	t	          |          k     r||	         }|	dz  }	| ||          z  }|d |	         }
||k    r" ||
||           |||	d          ||          fS ||k    r3 ||
d |	dz
           dz   ||           |d||	d          z   ||          fS |	t	          |          k     t          d          )N r    zWill never reach here)rH   rP   r   intlenr   AssertionError)clsrZ   r[   rI   rJ   rK   _SegmentrP   	cell_sizeposbeforecell_poschars                rF   _split_cellszSegment._split_cellsm   s     'eW)+HHR8888+	3$D		122dsdF##s??00cddUG44  CIIoo9D1HC		$'H$3$ZF3HVUG44HT#$$Z88  #~~HVIcAgI.4eWEEHS4:-ug>>  CIIoo  4555rE   c                    | \  }}}t          |          rX|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.
        r]   N)r   r`   rH   ri   )rN   r[   rI   rJ   rK   s        rF   split_cellszSegment.split_cells   s      $eW!$'' 	c$iiWR8888TcT
E733STT
E733 
   s+++rE   c                      | d          S )zMake a new line segment.
rD   )rb   s    rF   linezSegment.line   s     s4yyrE   segments
post_stylec                 b     |}|r|j          fd|D             }r f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   T   K   | ]"\  }}} ||rd n
 |          |          V  #d S rR   rD   ).0rI   rO   rK   applyrb   s       rF   	<genexpr>z&Segment.apply_style.<locals>.<genexpr>   s\        )D&' D'<$$uuV}}gFF     rE   c              3   P   K   | ] \  }}} ||rd n|r|z   n|          V  !d S rR   rD   )rs   rI   rO   rK   rb   rp   s       rF   ru   z&Segment.apply_style.<locals>.<genexpr>   sr         *D&'  #M5;Kfz11      rE   )__add__)rb   ro   rJ   rp   result_segmentsrt   s   `  ` @rF   apply_stylezSegment.apply_style   s    & # 	ME    -<  O  	     .=  O rE   FrY   c                 z    |rt          t          d          |          S t          t          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.

        rK   )filterr   r   )rb   ro   rY   s      rF   filter_controlzSegment.filter_control   s=      	@*Y//:::z)44h???rE   c              #      K   g }|j         }|D ]g}d|j        v rQ|j        sJ|\  }}}|rA|                    d          \  }}	}|r | | ||                     |	r|V  g }|j         }|A\ ||           h|r|V  dS 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)appendrI   rK   	partition)
rb   ro   rn   r~   rZ   rI   rJ   __textnew_lines
             rF   split_lineszSegment.split_lines   s       ! 	  	 Gw|##GO#!(eQ -,0NN4,@,@)E8T 2ss5%00111 -"


!!%  - w 	JJJJJ	 	rE   Tlengthpadinclude_new_linesc              #     K   g }|j         }| j        } | d          }	|D ]}
d|
j        v rs|
j        sl|
\  }}}|rc|                    d          \  }}}|r | | ||                     |r/ |||||          }|r|                     |	           |V  |dd= |c~ ||
           |r |||||          V  dS 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   )rJ   r   N)r~   adjust_line_lengthrI   rK   r   )rb   ro   r   rJ   r   r   rn   r~   r   new_line_segmentrZ   rI   segment_styler   r   r   cropped_lines                    rF   split_and_crop_lineszSegment.split_and_crop_lines	  sT     * ! 33t99 	  	 Gw|##GO#)0&mQ $,0NN4,@,@)E8T :ss5-88999 $'9'9 &3( ( ( - B(//0@AAA**** G  $ w 	I$$T6CHHHHHHHH	I 	IrE   rn   c                 z   t          d |D                       }||k     r$|r| | d||z
  z  |          gz   }n|dd         }nw||k    rgg }|j        }d}|D ]X}|j        }	||	z   |k     s|j        r ||           ||	z  }*|\  }
}}t	          |
||z
            }
 | | |
|                      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              3   $   K   | ]}|j         V  d S rR   )rP   )rs   rZ   s     rF   ru   z-Segment.adjust_line_length.<locals>.<genexpr>K  s%      BB''-BBBBBBrE   r^   Nr   )sumr~   rP   rK   r   )rb   rn   r   rJ   r   line_lengthr   r~   rZ   segment_lengthrI   r   r   s                rF   r   zSegment.adjust_line_length8  s   & BBTBBBBB  #33sf{.B'CU#K#K"LL76!!H_FK 	 	!(!4/&88GO8F7OOO>1KK-4*D-(v/CDDDF33t]33444AAAwHrE   c                 H    t           t          fd|D                       S )zGet 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   8   K   | ]} |j                   V  d S rR   )rI   )rs   rZ   	_cell_lens     rF   ru   z*Segment.get_line_length.<locals>.<genexpr>p  s/      ??w99W\**??????rE   )r   r   )rb   rn   r   s     @rF   get_line_lengthzSegment.get_line_lengthe  s-     	????$??????rE   linesc                 r    | j         |rt          fd|D                       nd}|t          |          fS )zGet 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   .   K   | ]} |          V  d S rR   rD   )rs   rn   r   s     rF   ru   z$Segment.get_shape.<locals>.<genexpr>}  s-      @@$--@@@@@@rE   r   )r   maxr`   )rb   r   	max_widthr   s      @rF   	get_shapezSegment.get_shaper  sJ     -DIPC@@@@%@@@@@@q	3u::&&rE   widthheight	new_linesc                 <  	 |pt          |          }|r | dz  dz             gn | dz            g}| j        	|d|         }	fd|D             |dd<   t          |          |k     r)|                    |g|t          |          z
  z             |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.
        r^   rm   Nc                 ,    g | ]} |           S ))rJ   rD   )rs   rn   r   rJ   r   s     rF   
<listcomp>z%Segment.set_shape.<locals>.<listcomp>  s9     
 
 
=AtU%888
 
 
rE   )r`   r   extend)
rb   r   r   r   rJ   r   _heightblankshaped_linesr   s
     ` `    @rF   	set_shapezSegment.set_shape  s    * &CJJ 1:XSSut#U++,,C%KQV@W@W?X 	 !3XgX
 
 
 
 
 
EJ
 
 
QQQ |w&&7S5F5F+F GHHHrE   rb   c                     |t          |          z
  }|s
|dd         S |d|         }|r | d|z  dz   |          n | d|z  |          }||gg|z  z   }|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`   rb   r   r   r   rJ   r   extra_linesr   s           rF   	align_topzSegment.align_top  s    * s5zz) 	8Ogvg2;XC%K$&...S5[RWAXAX%	K//rE   c                     |t          |          z
  }|s
|dd         S |d|         }|r | d|z  dz   |          n | d|z  |          }|gg|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^   rm   r   r   s           rF   align_bottomzSegment.align_bottom  s    * s5zz) 	8Ogvg2;XC%K$&...S5[RWAXAX	K'%/rE   c                     |t          |          z
  }|s
|dd         S |d|         }|r | d|z  dz   |          n | d|z  |          }|dz  }||z
  }	|gg|z  |z   |gg|	z  z   }|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^   rm   r!   r   )
rb   r   r   r   rJ   r   r   r   	top_linesbottom_liness
             rF   align_middlezSegment.align_middle  s    * s5zz) 	8Ogvg2;XC%K$&...S5[RWAXAX1$	"Y.	I%-%	L0HHrE   c              #     K   t          |          }	 t          |          }n# t          $ r Y dS w xY wt          }|D ]>}|j        |j        k    r&|j        s ||j        |j        z   |j                  }8|V  |}?|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StopIterationrH   rJ   rK   rI   )rb   ro   iter_segmentslast_segmentrc   rZ   s         rF   simplifyzSegment.simplify  s       X	..LL 	 	 	FF	 $ 	' 	'G!W]227?2'x %4l6H    #"""&s   # 
11c              #      K   |D ]@}|j         s|j        |V  |\  }}} | ||r|                    d          nd          V  AdS )zRemove all links from an iterable of styles.

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

        Yields:
            Segment: Segments with link removed.
        N)rK   rJ   update_link)rb   ro   rZ   rI   rJ   _controls         rF   strip_linkszSegment.strip_links  s         	L 	LG L'-"7(/%eXc$5 J 1 1$ 7 7 7dKKKKKK	L 	LrE   c              #   :   K   |D ]\  }}} | |d|          V  dS )zRemove all styles from an iterable of segments.

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

        Yields:
            Segment: Segments with styles replace with None
        NrD   )rb   ro   rI   rO   rK   s        rF   strip_styleszSegment.strip_styles)  sE       &. 	+ 	+!D&'#dD'******	+ 	+rE   c              #      K   i }|D ]J\  }}}|r3|                     |          }||j        }|||<    | |||          V  ; | |d|          V  KdS )zRemove all color from an iterable of segments.

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

        Yields:
            Segment: Segments with colorless style.
        N)getwithout_color)rb   ro   cacherI   rJ   rK   colorless_styles          rF   remove_colorzSegment.remove_color6  s       %'$, 	/ 	/ D% /"'))E"2"2"*&+&9O#2E%Lc$999999c$g......	/ 	/rE   cutsc              #     K   g }|j         }t          |          }	 t          |d          }|dk    rg S |dk    rng V  $d}|j        }|j        }	t
          }
|D ]}|\  }}}|r|r|n| |
|          z   }||k     r ||           |}n||k    rK ||            |	            V   |             |}t          |d          }|dk    r|r |	            V   dS nm|                    ||z
            \  }}|\  }}} ||            |	            V   |             |}t          |d          }|dk    r|r |	            V   dS | |	            V  dS )zDivides 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.
        Tr   N)r~   r   r   clearcopyr   rk   )rb   ro   r   split_segmentsadd_segment	iter_cutsr[   re   segments_clearsegments_copyr   rZ   rI   rO   rK   end_posrf   s                    rF   dividezSegment.divideL  s      +-$+JJ		y"%%Cbyy	axxHHH	 '-&+#	 #	 #	G$+!D&' !!(C##cIIdOO.CS==K(((!Cc>>K((('-//)))"N$$$!Cy"--Cbyy) 2"/-//111 '.&9&9#)&D&DOFG,3)D&'K''''-//)))"N$$$C9b))"99% .+moo---FFC  !F moorE   )rL   rH   )NNF)NTT)NT)NNF)-r0   r1   r2   r3   str__annotations__rJ   r   r   rK   r   ControlCodepropertyr_   rP   r   rT   rV   rW   rY   classmethodr   r   ri   rk   rn   r
   ry   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rD   rE   rF   rH   rH   ?   s        
 
 III!E8E?!!!/3GXh{+,3330S 0 0 0 X0v    $     (D ( ( ( X( Yy$69 $63 $65AU;V $6 $6 $6  [$6L,s ,u-A'B , , , ,,    [  "&&*	& &9%& & UO	&
 
)	& & & [&P ?D@ @	*@8<@	)	@ @ @ [@$ 8I#6 8DO;T    [8 
 "&"&,I ,I9%,I ,I 	,I
 ,I  ,I 
$y/	",I ,I ,I [,I\ 
 "&* *9o* * 	*
 * 
i* * * [*X 
@4	? 
@s 
@ 
@ 
@ [
@ 'd4	?3 'c3h ' ' ' [' 
 !%!%! !DO$! ! 	!
 ! ! 
d9o	! ! ! [!F    )_DO$  	
   
d9o	   [8    )_DO$  	
   
d9o	   [8    )_DO$  	
   
d9o	   [<  3 8K    [4 L8I#6 L8I;N L L L [L  
+HY$7 
+HY<O 
+ 
+ 
+ [
+ /HY$7 /HY<O / / / [/* B	*B2:3-B	$y/	"B B B [B B BrE   rH   c                   H    e Zd ZdZddee         deddfdZ	 	 	 	 	 	 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.
    Fro   r   rL   Nc                 <    t          |          | _        || _        d S rR   )listro   r   )rN   ro   r   s      rF   __init__zSegments.__init__  s    X"rE   consoler   optionsr   r   c              #      K   | j         r-t                                          }| j        D ]
}|V  |V  d S | j        E d {V  d S rR   )r   rH   rn   ro   )rN   r   r   rn   rZ   s        rF   __rich_console__zSegments.__rich_console__  sp       > 	%<<>>D=  



  }$$$$$$$$$rE   r   r   r   r   r   rL   r   )	r0   r1   r2   r3   r
   rH   rV   r   r   rD   rE   rF   r   r     s~         # #'!2 #t #PT # # # #	% 	%+;	%		% 	% 	% 	% 	% 	%rE   r   c                   P    e Zd Zddeee                  deddfdZ	 	 	 	 	 	 ddZdS )SegmentLinesFr   r   rL   Nc                 <    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   r   r   )rN   r   r   s      rF   r   zSegmentLines.__init__  s     %[[
"rE   r   r   r   r   r   c              #      K   | j         r1t                                          }| j        D ]}|E d {V  |V  d S | j        D ]
}|E d {V  d S rR   )r   rH   rn   r   )rN   r   r   r   rn   s        rF   r   zSegmentLines.__rich_console__  s       > 	 ||~~H
    
       rE   r   r   )	r0   r1   r2   r
   r   rH   rV   r   r   rD   rE   rF   r   r     sx        	# 	#htG}5 	#$ 	#SW 	# 	# 	# 	#
  
 +;
 	
  
  
  
  
  
 rE   r   __main__)r   )Syntax)Textzfrom 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)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):enumr   	functoolsr   	itertoolsr   loggingr   operatorr   typingr   r	   r
   r   r   r   r   r   r   r   cellsr   r   r   r   r   reprr   r   rJ   r   r   r   r   r   logr    r_   r   r   rH   r   r   r0   pip._vendor.rich.consolepip._vendor.rich.syntaxr   pip._vendor.rich.textr   codefrom_markuprI   ruleprintr   render	fragmentsrD   rE   rF   <module>r      s               ! ! ! ! ! !                                                 $ # # # # # # #       ?>>>>>>>>>>i    '   * 	+	+uS#X
&'	+sC
 " O	 O	 O	 O	 O	j O	 O	 O	d% % % % % % % %2               2 z000000......******D
 4<==DgiiGLL   MMg   MM4555MM&&xd;;;<<<MMOOOMMa   W^^D))**IMM)MMOOOMMVWWWMM$MM^    ; rE   