
    ,h`                        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 e1jf                  d      Z4 e!       Z e jk                  d       e jm                  d       e jm                  d       e jm                   e/e2dd              e jm                          e jm                  d!        e7e jq                  e4            Z9e jm                  e9       e jm                          e jm                  d"       e jm                  e4       e jm                  d#       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    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y)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     N/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/rich/segment.pyr    r    #   sY    NDODEKKIKNONMrE   r    c                   v   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d/d       Ze	 	 d0ded    dee   dee   ded    fd       Ze	 d1ded    deded    fd       Zeded    deed       fd       Ze	 	 	 d2ded    dedee   dededeed       fd       Ze	 	 d3d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	 	 	 d4deed       d!ed"ee   dee   d#edeed       fd$       Z#e	 d1d%e$d    deed       d!ed"eded#edeed       fd&       Z%e	 d1d%e$d    deed       d!ed"eded#edeed       fd'       Z&e	 d1d%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d.       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                 ,    | \  }}}|rdS 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q/$/rE   c              #      K   | j                    | j                  | j                  | j                   y y | j                   | j                   y wN)rI   rK   rJ   rN   s    rF   __rich_repr__zSegment.__rich_repr__[   sH     ii<<zz%jj  & **,,s   AAc                 ,    t        | j                        S )z#Check if the segment contains text.)boolrI   rS   s    rF   __bool__zSegment.__bool__d   s    DII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        |
      }||z
  }|s ||
||       |||	d ||      fS |dk(  r1 |||	         dk(  r# ||d|	 dz   ||       |d||	dz   d z   ||      fS |dk(  r4 |||	dz
           dk(  r# ||d|	dz
   dz   ||       |d||	d z   ||      fS ||k  r|	dz  }	n|	dz  }	)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.
         Nr!    r   )rH   rP   r   intlenr   )clsrZ   r[   rI   rJ   rK   _SegmentrP   	cell_sizeposbeforecell_posout_bys                rF   _split_cellszSegment._split_cellsm   ss     'eW))+HR888+	3$D	12$3ZF'H^FVUG4T#$Z8  |	$s) 4 9T$3Z#-ug>S4a	?2E7C  |	$sQw- 8A =T)C!G_s2E7CS4:-ug>  #~qq- rE   c                     | \  }}}|dk\  sJ t        |      r=|t        |      k\  r| t        d||      fS t        |d| ||      t        ||d ||      fS | j                  | |      S )ax  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.

        Args:
            cut (int): Offset within the segment to cut.

        Returns:
            Tuple[Segment, Segment]: Two segments.
        r   r]   N)r   ra   rH   ri   )rN   r[   rI   rJ   rK   s        rF   split_cellszSegment.split_cells   s      $eWax!$'c$iWR888Tc
E73ST
E73 
   s++rE   c                      | d      S )zMake a new line segment.
rD   )rb   s    rF   linezSegment.line   s     4yrE   segments
post_stylec                 `     |}|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   N   K   | ]  \  }}} ||rd n |      |        y wrR   rD   ).0rI   rO   rK   applyrb   s       rF   	<genexpr>z&Segment.apply_style.<locals>.<genexpr>   s0      )D&' D'$uV}gFs   "%c              3   P   K   | ]  \  }}} ||rd n|r|z   n|        y wrR   rD   )rs   rI   rO   rK   rb   rp   s       rF   ru   z&Segment.apply_style.<locals>.<genexpr>   sB       *D&'  # 5;fz1s   #&)__add__)rb   ro   rJ   rp   result_segmentsrt   s   `  ` @rF   apply_stylezSegment.apply_style   sC    & #MME-<O  .=O rE   rY   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)4h??rE   c              #     K   g }|j                   }|D ]k  }d|j                  v rS|j                  sG|\  }}}|s&|j                  d      \  }}	}|r | | ||             |	r| g }|j                   }|r=d ||       m |r| yyw)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||#GOO!(eQ,0NN4,@)E8Ts5%01"
!!%  w	  J s   6B	<B	6B	lengthpadinclude_new_linesc              #     K   g }|j                   }| j                  } | d      }	|D ]  }
d|
j                  v rt|
j                  sh|
\  }}}|s&|j	                  d      \  }}}|r | | ||             |r3 |||||      }|r|j                  |	       | |j                          |r^ ||
        |r |||||       yy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   )rJ   r   N)r~   adjust_line_lengthrI   rK   r   clear)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  s     * ! 33t9 	 Gw||#GOO)0&mQ,0NN4,@)E8Ts5-89'9 &3( -(//0@A**

  w!	 " $T6CHH s   A
CAC+Crn   c                 ^   t        d |D              }||k  r|r| | d||z
  z  |      gz   }|S |dd }|S ||kD  rmg }|j                  }d}|D ]V  }|j                  }	||	z   |k  s|j                  r ||       ||	z  }1|\  }
}}t	        |
||z
        }
 | | |
|              |S  |S |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   4   K   | ]  }|j                     y wrR   )rP   )rs   rZ   s     rF   ru   z-Segment.adjust_line_length.<locals>.<genexpr>X  s     B''--Bs   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_lengthE  s    & BTBB 3sf{.B'CU#K"LL& #  7" ! 6!H__FK 	!(!4!4/&8GOO7O>1K-4*D-(v/CDD3t]34 	  AwHrE   c                 8    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   <   K   | ]  \  }}}|r
 |        y wrR   rD   )rs   rI   rJ   rK   	_cell_lens       rF   ru   z*Segment.get_line_length.<locals>.<genexpr>}  s     S';tUG79T?Ss   )r   r   )rb   rn   r   s     @rF   get_line_lengthzSegment.get_line_lengthr  s     	StSSSrE   linesc                 f    | 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   | ]  } |        y wrR   rD   )rs   rn   r   s     rF   ru   z$Segment.get_shape.<locals>.<genexpr>  s     @$-@s   r   )r   maxra   )rb   r   	max_widthr   s      @rF   	get_shapezSegment.get_shape  s3     --DIC@%@@q	3u:&&rE   widthheight	new_linesc                 $   |xs t        |      }|r | d|z  dz   |      gn | d|z  |      g}| j                  }|d| }	|D 
cg c]  }
 ||
||       c}
|	dd t        |	      |k  r!|	j                  |g|t        |	      z
  z         |	S c c}
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_   rm   N)rJ   )ra   r   extend)rb   r   r   r   rJ   r   _heightblankr   shaped_linesrn   s              rF   	set_shapezSegment.set_shape  s    * &CJ 1:Sut#U+,C%KQV@W?X 	 !33XgEJ
=AtU%8
Q |w&7S5F+F GH
s   B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   ra   rb   r   r   r   rJ   r   extra_linesr   s           rF   	align_topzSegment.align_top  sf    * s5z)8Ogv2;C%K$&.S5[RWAX%	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  sf    * s5z)8Ogv2;C%K$&.S5[RWAX	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    * s5z)8Ogv2;C%K$&.S5[RWAX1$	"Y.	I%-%	L0HHrE   c              #   &  K   t        |      }	 t        |      }t        }|D ]X  }|j                  |j                  k(  r7|j
                  s+ ||j                  |j                  z   |j                        }S| |}Z | y# t        $ r Y yw xY w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StopIterationrH   rJ   rK   rI   )rb   ro   iter_segmentslast_segmentrc   rZ   s         rF   simplifyzSegment.simplify
  s      X	.L $ 	'G!!W]]27??' %%4l6H6H  #"&	'   		s(   BB A(B	BBBBc              #      K   |D ]C  }|j                   s|j                  |  |\  }}} | ||r|j                  d      nd       E yw)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%  sV        	LG'--"7(/%eX$5 1 1$ 7dKK	Ls   A
Ac              #   :   K   |D ]  \  }}} | |d|        yw)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_styles6  s-      &. 	+!D&'dD'**	+s   c              #      K   i }|D ]E  \  }}}|r1|j                  |      }||j                  }|||<    | |||       : | |d|       G yw)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_colorC  sl      %'$, 	/ D%"'))E"2"*&+&9&9O#2E%L$99$g..	/s   AAcutsc              #   V  K   g }|j                   }t        |      }	 t        |d      }|dk(  ry|dk7  rng  d}|j                  }|j                  }	t
        }
|D ]  }|\  }}}|s|r|n
| |
|      z   }||k  r ||       |}+||k(  r9 ||        |	         |        |}t        |d      }|dk(  r|r	 |	         yi|j                  ||z
        \  }}|\  }}} ||        |	         |        |}t        |d      }|dk(  r|r	 |	         y|r  |	        yw)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.
        r^   Nr   )r~   r   r   r   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.divideY  sp     +-$++J	y"%CbyaxH  '--&++#	 #	G$+!D&'!(#cIdO.CS=(!Cc>('/)"$!Cy"-Cby)"//1 '.&9&9#)&DOFG,3)D&'''/)"$C9b)"9%+o-C #	J os   A%D)(B4D)D))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   
 I!E8E?!/3GXh{+,30S 0 0v $  (D ( ( y-9 -3 -5AU;V -  -^,s ,u-A'B ,4    "&&*	&9%& & UO	&
 
)	& &P ?D@	*@8<@	)	@ @$ 8I#6 8DO;T  8 
 "&"&,I9%,I ,I 	,I
 ,I  ,I 
$y/	",I ,I\ 
 "&*9o* * 	*
 * 
i* *X 
T4	? 
Ts 
T 
T '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  
+HY$7 
+HY<O 
+ 
+ /HY$7 /HY<O / /* B	*B2:3-B	$y/	"B BrE   rH   c                   @    e Zd ZdZddee   deddfdZ	 	 	 	 	 	 d	dZy)
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.
    ro   r   rL   Nc                 2    t        |      | _        || _        y rR   )listro   r   )rN   ro   r   s      rF   __init__zSegments.__init__  s    X"rE   c              #      K   | j                   r.t        j                         }| j                  D ]
  }| |  y | j                  E d {    y 7 wrR   )r   rH   rn   ro   )rN   consoleoptionsrn   rZ   s        rF   __rich_console__zSegments.__rich_console__  sF      >><<>D== 
 }}$$s   A
AAAr   r   r   r   r   rL   r   )	r0   r1   r2   r3   r
   rH   rV   r   r   rD   rE   rF   r   r     sD    #'!2 #t #PT #	% 	%+;	%		%rE   r   c                   B    e Zd Zddeee      deddfdZ	 	 	 	 	 	 ddZy)	SegmentLinesr   r   rL   Nc                 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   )rN   r   r   s      rF   r   zSegmentLines.__init__  s     %[
"rE   c              #      K   | j                   r4t        j                         }| j                  D ]  }|E d {    |  y | j                  D ]  }|E d {     y 7 '7 	wrR   )r   rH   rn   r   )rN   r   r   r   rn   s        rF   r   zSegmentLines.__rich_console__  s`      >>||~H

  

       s!   5A#AA#A!A#!A#r   r   )	r0   r1   r2   r
   r   rH   rV   r   r   rD   rE   rF   r   r     sC    	#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_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   rJ   r   r   r   r   r   logr    r`   r   r   rH   r   r   r0   rich.consolerich.syntaxr   	rich.textr   codefrom_markuprI   ruleprintr   render	fragmentsrD   rE   rF   <module>r      s     !      $ >>' * 	+	+uS#X
&'	+sC
 " \	j \	 \	~% %2   2 z$"D
 4<=DiGLL MMg MM45MM&xd;<MMOMM] W^^D)*IMM)MMOMMVWMM$MM^; rE   