
    <6hձ                        U d dl Z d dlmZ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 ddlmZ dd	lmZ dd
lmZ ddlmZ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' ddl(m)Z) ddl*m+Z+m,Z, e	rddl-m.Z.m/Z/m0Z0m1Z1 dZ2de3d<   dZ4de3d<    e jj                  d      Z6ee7df   Z8ee7gee,   f   Z9 G d de      Z: G d de%      Z;e<dk(  rd d l=m.Z.  e;d!      Z>e>j                  d"gd#       e>j                  d$gd%        e.       Z-e-j                  d&       e-j                  e>d'(       e-j                          e-j                  d)       e-j                  e>d*d+,       e-j                          e-j                  d-       e-j                  e>d.d/,       e-j                          e-j                  d0       e-j                  e>d1d2,       e-j                          yy)3    N)partialreduce)gcd)
itemgetter)
TYPE_CHECKINGAnyCallableDictIterableList
NamedTupleOptionalTupleUnion   )	loop_last)	pick_bool)divide_line)AlignMethod)cell_lenset_cell_size)Lines)strip_control_codes)EmojiVariant)JupyterMixin)Measurement)Segment)Style	StyleType)ConsoleConsoleOptionsJustifyMethodOverflowMethoddefaultr"   DEFAULT_JUSTIFYfoldr#   DEFAULT_OVERFLOWz\s+$Textc                       e Zd ZU dZeed<   	 eed<   	 eeef   ed<   	 defdZ	de
fdZdeded ed    f   fd	Zdedd fd
Zdedd fdZy)Spanz A marked up region in some text.startendstylereturnc                 V    d| j                    d| j                   d| j                  dS )NzSpan(z, ))r+   r,   r-   selfs    Z/var/www/panel.atabookie.online/venv/lib/python3.12/site-packages/pip/_vendor/rich/text.py__repr__zSpan.__repr__7   s)    tzzl"TXXJba@@    c                 4    | j                   | j                  kD  S N)r,   r+   r1   s    r3   __bool__zSpan.__bool__:   s    xx$**$$r5   offsetc                     || j                   k  r| dfS || j                  k\  r| dfS | \  }}}t        |t        ||      |      }t        |j                  ||      }||fS )z)Split a span in to 2 from a given offset.N)r+   r,   r*   min)r2   r9   r+   r,   r-   span1span2s          r3   splitz
Span.split=   sm     DJJ:TXX: sEUCV,e4UYYU+e|r5   c                 4    | \  }}}t        ||z   ||z   |      S )zMove start and end by a given offset.

        Args:
            offset (int): Number of characters to add to start and end.

        Returns:
            TextSpan: A new TextSpan with adjusted position.
        )r*   r2   r9   r+   r,   r-   s        r3   movez	Span.moveJ   s'     !sEEFNC&L%88r5   c                 J    | \  }}}||k\  r| S t        |t        ||      |      S )zCrop the span at the given offset.

        Args:
            offset (int): A value between start and end.

        Returns:
            Span: A new (possibly smaller) span.
        )r*   r;   r@   s        r3   
right_cropzSpan.right_cropV   s2     !sES=KE3vs+U33r5   N)__name__
__module____qualname____doc__int__annotations__r   strr   r4   boolr8   r   r   r>   rA   rC    r5   r3   r*   r*   -   s    *J	He)A# A%$ %C E&(62B*B$C 
93 
96 
94 4 4r5   r*   c                      e Zd ZdZg dZ	 	 d}dddddddded	eeef   d
ed   ded   dee	   dedee
   deee      ddfdZde
fdZde	fdZdefdZdefdZdedd fdZdede	fdZdede	fdZdee
ef   dd fdZede
fd       Zedefd       Zedd ddddd!ded	eeef   d"e	d#ee   d
ed   ded   dedd fd$       Zeddddddd%ded	eeef   d
ed   ded   dee	   dedee
   dd fd&       Ze	 d~ddd'ded	e d
ed   ded   dd f
d(       Z!edddddddd)d*eed e"ee f   f   d	eeef   d
ed   ded   dee	   dede
d+ee#eef      dd fd,       Z$edefd-       Z%e%jL                  d.eddfd/       Z%edee   fd0       Z'e'jL                  dee   ddfd1       Z'd~d2edd fd3Z(dd4Z)	 	 dd	eeef   d5e
dee
   ddfd6Z*	 	 dd	eeef   d5e
dee
   ddfd7Z+	 dd+e#eef   d5e
dee
   ddfd8Z,dd+ee#eef      d9edd fd:Z-d;eddfd<Z.d=d>d?e
defd@Z/	 dddAdBed	eee0e f      dCede
fdDZ1d dEdFe2e   d	eeef   dGe	de
fdHZ3ddIZ4dJe
ddfdKZ5dLe
ddfdMZ6d=d>dNdOde2e7   fdPZ8d=d>dNdOde9fdQZ:d~d=d>dede2dR   fdSZ;dTe2d    dd fdUZ<ddee
   ddfdVZ=ddWdXdYe
ded   dZe	ddfd[Z>dd\Z?dd]e
d^eddfd_Z@dd]e
d^eddfd`ZAdd]e
d^eddfdaZBddbeCdce
d^eddfddZD	 dded ef   d	eeedef      dd fdfZEddgZFdhe2e"eee    f      dd fdiZGddjZH	 ddWdWdkdledme	dne	deIfdoZJdpe2e
   deIfdqZKddre
ddfdsZLdddddtd=d>dce
d
ed   ded   de
dee	   deIfduZMdce
deIfdvZNde
fdwZO	 ddxdydzd{ee
   d^ed	e dd fd|ZPy)r(   a  Text with color / style.

    Args:
        text (str, optional): Default unstyled text. Defaults to "".
        style (Union[str, Style], optional): Base style for text. Defaults to "".
        justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
        overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
        no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None.
        end (str, optional): Character to end text with. Defaults to "\\n".
        tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to 8.
        spans (List[Span], optional). A list of predefined style spans. Defaults to None.
    )	_textr-   justifyoverflowno_wrapr,   tab_size_spans_length N
   )rO   rP   rQ   r,   rR   spanstextr-   rO   r"   rP   r#   rQ   r,   rR   rX   r.   c                    t        |      }	|	g| _        || _        || _        || _        || _        || _        || _        |xs g | _        t        |	      | _
        y r7   )r   rN   r-   rO   rP   rQ   r,   rR   rS   lenrT   )
r2   rY   r-   rO   rP   rQ   r,   rR   rX   sanitized_texts
             r3   __init__zText.__init__   sY     -T2$%

294< "'+2/r5   c                     | j                   S r7   )rT   r1   s    r3   __len__zText.__len__   s    ||r5   c                 ,    t        | j                        S r7   )rK   rT   r1   s    r3   r8   zText.__bool__   s    DLL!!r5   c                     | j                   S r7   plainr1   s    r3   __str__zText.__str__   s    zzr5   c                 <    d| j                   d| j                  dS )Nz<text  >)rc   rS   r1   s    r3   r4   zText.__repr__   s    

~Qt{{oQ77r5   otherc                     t        |t        t        f      r#| j                         }|j	                  |       |S t
        S r7   )
isinstancerJ   r(   copyappendNotImplemented)r2   rh   results      r3   __add__zText.__add__   s2    ec4[)YY[FMM% Mr5   c                     t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r7   )rj   r(   rm   rc   rS   r2   rh   s     r3   __eq__zText.__eq__   s7    %&!!zzU[[(HT[[ELL-HHr5   c                     t        |t              r|| j                  v S t        |t              r|j                  | j                  v S y)NF)rj   rJ   rc   r(   rq   s     r3   __contains__zText.__contains__   s;    eS!DJJ&&t$;;$**,,r5   slicec                      dt         ddf fd}t        |t               r ||      S |j                  t         j                              \  }}}|dk(  r j                  ||g      }|d   S t        d      )Nr9   r.   r(   c                     t         }t        j                  |    j                  D cg c]  \  }}}|| cxkD  r|k\  rn n
 |dd|        c}}}d      }|S c c}}}w )Nr   r   rU   )rX   r,   )r*   r(   rc   rS   )r9   _Spanr+   r,   r-   rY   r2   s         r3   get_text_atz%Text.__getitem__.<locals>.get_text_at   sl    E

6" .2[[ )sEV,u, !Q&
 D Ks   #Ar   z%slices with step!=1 are not supported)rH   rj   indicesr[   rc   divide	TypeError)r2   ru   ry   r+   stopstepliness   `      r3   __getitem__zText.__getitem__   sz    	 	 	 eS!u%% %c$**o >E4qyUDM2Qx   GHHr5   c                 ,    t        | j                        S )z5Get the number of cells required to render this text.)r   rc   r1   s    r3   r   zText.cell_len   s     

##r5   c                    ddl m} g }| j                  }dd| j                  fgd | j                  D        d | j                  D        t        |      d| j                  f}|j                  t        dd             d}|j                  }|D ]5  \  }}}	||kD  r | ||||              |}|	s" ||rd	|	 d
nd|	 d
       7 dj                  |      }
|
S )z~Get console markup to render this Text.

        Returns:
            str: A string potentially creating markup tags.
        r   )escaper   Fc              3   N   K   | ]  }|j                   d |j                  f  ywFN)r+   r-   .0spans     r3   	<genexpr>zText.markup.<locals>.<genexpr>   s     F$tzz5$**-F   #%c              3   N   K   | ]  }|j                   d |j                  f  ywTN)r,   r-   r   s     r3   r   zText.markup.<locals>.<genexpr>   s     Cttxxtzz*Cr   Tkeyz[/][rU   )
markupr   rc   r-   rS   r[   sortr   rl   join)r2   r   outputrc   markup_spanspositionrl   r9   closingr-   r   s              r3   r   zText.markup   s     	#

tzz"
F$++F
 Dt{{C
 Ztzz*	
 	jA./&2 	C"FGU veHV456!E7!}qq\B	C r5   T)r-   emojiemoji_variantrO   rP   r,   r   r   c                T    ddl m}  |||||      }	||	_        ||	_        ||	_        |	S )a,  Create Text instance from markup.

        Args:
            text (str): A string containing console markup.
            emoji (bool, optional): Also render emoji code. Defaults to True.
            justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
            overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
            end (str, optional): Character to end text with. Defaults to "\\n".

        Returns:
            Text: A Text instance with markup rendered.
        r   )render)r   r   )r   r   rO   rP   r,   )
clsrY   r-   r   r   rO   rP   r,   r   rendered_texts
             r3   from_markupzText.from_markup   s5    0 	#tU%}U '!)r5   r-   rO   rP   rQ   r,   rR   c          	          ddl m} t        d||||||      }	 |       }
|	j                  d |
j	                  |      D              }|S )a  Create a Text object from a string containing ANSI escape codes.

        Args:
            text (str): A string containing escape codes.
            style (Union[str, Style], optional): Base style for text. Defaults to "".
            justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
            overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
            no_wrap (bool, optional): Disable text wrapping, or None for default. Defaults to None.
            end (str, optional): Character to end text with. Defaults to "\\n".
            tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to 8.
        r   )AnsiDecoderrV   )rO   rP   rQ   r,   rR   r-   c              3       K   | ]  }|  y wr7   rL   r   lines     r3   r   z!Text.from_ansi.<locals>.<genexpr>5  s     CdTCs   )ansir   r(   r   decode)r   rY   r-   rO   rP   rQ   r,   rR   r   joinerdecoderrn   s               r3   	from_ansizText.from_ansi  sQ    . 	&
 -CgnnT.BCCr5   rO   rP   c                >     | |||      }|j                  |       |S )aa  Construct a Text instance with a pre-applied styled. A style applied in this way won't be used
        to pad the text when it is justified.

        Args:
            text (str): A string containing console markup.
            style (Union[str, Style]): Style to apply to the text. Defaults to "".
            justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
            overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.

        Returns:
            Text: A text instance with a style applied to the entire string.
        r   )stylize)r   rY   r-   rO   rP   styled_texts         r3   styledzText.styled8  s&    * $(CE"r5   )r-   rO   rP   rQ   r,   rR   metapartsr   c                     | ||||||      }	|	j                   }
t        }|D ]"  }t        ||t        f      r	 |
|        |
|  $ |r|	j	                  |       |	S )aR  Construct a text instance by combining a sequence of strings with optional styles.
        The positional arguments should be either strings, or a tuple of string + style.

        Args:
            style (Union[str, Style], optional): Base style for text. Defaults to "".
            justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
            overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
            end (str, optional): Character to end text with. Defaults to "\\n".
            tab_size (int): Number of spaces per tab, or ``None`` to use ``console.tab_size``. Defaults to 8.
            meta (Dict[str, Any], optional). Meta data to apply to text, or None for no meta data. Default to None

        Returns:
            Text: A new text instance.
        r   )rl   r(   rj   rJ   
apply_meta)r   r-   rO   rP   rQ   r,   rR   r   r   rY   rl   _Textparts                r3   assemblezText.assembleQ  sq    4 
  	D$-t		
 OOD!r5   c                     t        | j                        dk7  r)dj                  | j                        g| j                  dd | j                  d   S )z Get the text as a single string.r   rU   Nr   )r[   rN   r   r1   s    r3   rc   z
Text.plain~  s?     tzz?aWWTZZ01DJJqMzz!}r5   new_textc                     || j                   k7  rXt        |      }|g| j                  dd | j                  }t	        |      | _        || j                  kD  r| j                          yyy)zSet the text to a new value.N)rc   r   rN   rT   r[   _trim_spans)r2   r   r\   
old_lengths       r3   rc   z
Text.plain  sa     tzz!0:N+,DJJqMJ~.DLDLL(  " ) "r5   c                     | j                   S )z.Get a reference to the internal list of spans.rS   r1   s    r3   rX   z
Text.spans  s     {{r5   c                     |dd | _         y)z
Set spans.Nr   )r2   rX   s     r3   rX   z
Text.spans  s     Ahr5   rc   c           	          t        || j                  | j                  | j                  | j                  | j
                  | j                        }|S )zOReturn a new Text instance with copied meta data (but not the string or spans).r   )r(   r-   rO   rP   rQ   r,   rR   )r2   rc   	copy_selfs      r3   
blank_copyzText.blank_copy  sA    **LL]]LL]]
	 r5   c           	          t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                        }| j                  |j                  dd |S )zReturn a copy of this instance.r   N)	r(   rc   r-   rO   rP   rQ   r,   rR   rS   )r2   r   s     r3   rk   z	Text.copy  sY    JJ**LL]]LL]]
	 #kk	r5   r+   c           	          |r_t        |       }|dk  r||z   }||}|dk  r||z   }||k\  s||k  ry| j                  j                  t        |t	        ||      |             yy)az  Apply a style to the text, or a portion of the text.

        Args:
            style (Union[str, Style]): Style instance or style definition to apply.
            start (int): Start offset (negative indexing is supported). Defaults to 0.
            end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.
        r   N)r[   rS   rl   r*   r;   r2   r-   r+   r,   lengths        r3   r   zText.stylize  sq     YFqy{Qwsl#,KKtE3vs+;UCD r5   c           
          |r`t        |       }|dk  r||z   }||}|dk  r||z   }||k\  s||k  ry| j                  j                  dt        |t	        ||      |             yy)a  Apply a style to the text, or a portion of the text. Styles will be applied before other styles already present.

        Args:
            style (Union[str, Style]): Style instance or style definition to apply.
            start (int): Start offset (negative indexing is supported). Defaults to 0.
            end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.
        r   N)r[   rS   insertr*   r;   r   s        r3   stylize_beforezText.stylize_before  ss     YFqy{Qwsl#,KKq$uc&#.>"FG r5   c                 V    t        j                  |      }| j                  |||       y)ah  Apply meta data to the text, or a portion of the text.

        Args:
            meta (Dict[str, Any]): A dict of meta information.
            start (int): Start offset (negative indexing is supported). Defaults to 0.
            end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None.

        )r+   r,   N)r   	from_metar   )r2   r   r+   r,   r-   s        r3   r   zText.apply_meta  s$     %U%S1r5   handlersc                     |i n|}|j                  |j                         D ci c]  \  }}d| | c}}       | j                  t        j                  |             | S c c}}w )a  Apply event handlers (used by Textual project).

        Example:
            >>> from rich.text import Text
            >>> text = Text("hello world")
            >>> text.on(click="view.toggle('world')")

        Args:
            meta (Dict[str, Any]): Mapping of meta information.
            **handlers: Keyword args are prefixed with "@" to defined handlers.

        Returns:
            Text: Self is returned to method may be chained.
        @)updateitemsr   r   r   )r2   r   r   r   values        r3   onzText.on  s\     \rt8HI*#uqY%IJU__T*+ Js   A#
suffixc                 p    | j                   j                  |      r| j                  t        |             yy)zaRemove a suffix if it exists.

        Args:
            suffix (str): Suffix to remove.
        N)rc   endswithrC   r[   )r2   r   s     r3   remove_suffixzText.remove_suffix  s+     ::v&OOCK( 'r5   consoler    r9   c                     |dk  rt        |       |z   }|j                  } || j                        j                         }| j                  D ]"  \  }}}||cxkD  r|k\  sn | ||d      z  }$ |S )a
  Get the style of a character at give offset.

        Args:
            console (~Console): Console where text will be rendered.
            offset (int): Offset in to text (negative indexing supported)

        Returns:
            Style: A Style instance.
        r   rU   r$   )r[   	get_styler-   rk   rS   )r2   r   r9   r   r-   r+   r,   
span_styles           r3   get_style_at_offsetzText.get_style_at_offset  sz     A:Y'F%%	$**%**,&*kk 	;"E3
V$u$:r::	; r5   )style_prefixre_highlightr   c          
         d}| j                   j                  }t        }| j                  }t	        j
                  ||      D ]  }|j                  }	|r9 |	       \  }
}t        |      r |||
|       n|}|||
kD  r | ||
||             |dz  }|j                         j                         D ]-  } |	|      \  }
}|
dk7  s||
kD  s | ||
|| |              /  |S )a  Highlight text with a regular expression, where group names are
        translated to styles.

        Args:
            re_highlight (str): A regular expression.
            style (Union[GetStyleCallable, StyleType]): Optional style to apply to whole match, or a callable
                which accepts the matched text and returns a style. Defaults to None.
            style_prefix (str, optional): Optional prefix to add to style group names.

        Returns:
            int: Number of regex matches
        r   r   )
rS   rl   r*   rc   refinditerr   callable	groupdictkeys)r2   r   r-   r   countappend_spanrx   rc   matchget_spanr+   r,   match_stylenames                 r3   highlight_regexzText.highlight_regex(  s    & kk((

[[u5 	LEzzH%Z
s9A%eE%$45e*sU{eS+ >?QJE)..0 L%d^
sB;3;eS\N4&2I JKL	L r5   )case_sensitivewordsr   c                6   dj                  d |D              }| j                  j                  }d}t        }t	        j
                  || j                  |rdnt        j                        D ]+  }|j                  d      \  }	}
 | ||	|
|             |dz  }- |S )aD  Highlight words with a style.

        Args:
            words (Iterable[str]): Worlds to highlight.
            style (Union[str, Style]): Style to apply.
            case_sensitive (bool, optional): Enable case sensitive matchings. Defaults to True.

        Returns:
            int: Number of words highlighted.
        |c              3   F   K   | ]  }t        j                  |        y wr7   )r   r   r   words     r3   r   z'Text.highlight_words.<locals>.<genexpr>_  s     >BIIdO>s   !r   flagsr   )	r   rS   rl   r*   r   r   rc   
IGNORECASEr   )r2   r   r-   r   re_wordsadd_spanr   rx   r   r+   r,   s              r3   highlight_wordszText.highlight_wordsN  s    " 88>>>;;%%[[djj^
 	E AJE3U5#u-.QJE	 r5   c                 B    | j                   j                         | _         y)z"Strip whitespace from end of text.N)rc   rstripr1   s    r3   r   zText.rstripk  s    ZZ&&(
r5   sizec                     t        |       }||kD  r]||z
  }t        j                  | j                        }|6t        |j	                  d            }| j                  t        ||             yyy)zRemove whitespace beyond a certain width at the end of the text.

        Args:
            size (int): The desired size of the text.
        Nr   )r[   _re_whitespacesearchrc   grouprC   r;   )r2   r   text_lengthexcesswhitespace_matchwhitespace_counts         r3   
rstrip_endzText.rstrip_endo  so     $i 4'F-44TZZ@+#&'7'='=a'@#A $4f => , r5   
new_lengthc                     t        |       }||k7  r/||k  r| j                  ||z
         y| j                  ||z
         yy)z<Set new length of the text, clipping or padding is required.N)r[   	pad_rightrC   )r2   r  r   s      r3   
set_lengthzText.set_length}  sB    TZ
"zF23 34	  r5   optionsr!   c              #     K   |j                   xs | j                   xs d}| j                  xs |j                  xs t        }| j                  xs |j                  xs t        }| j                  ||j                  |||xs dt        | j                  |j                  d            }t        d      j                  |      }|j                  || j                        E d {    y 7 w)NrW   FrO   rP   rR   rQ   rV   r,   )rR   rO   r%   rP   r'   wrap	max_widthr   rQ   r(   r   r   r,   )r2   r   r  rR   rO   rP   r   	all_liness           r3   __rich_console__zText.__rich_console__  s       ((>DMM>Q,,D'//D_==HG$4$4H8H		]dllGOOUC  
 JOOE*	##G#:::s   C!C+#C)$C+c                     | j                   }|j                         }|rt        d |D              nd}|j                         }|rt        d |D              n|}t	        ||      S )Nc              3   2   K   | ]  }t        |        y wr7   r   r   s     r3   r   z(Text.__rich_measure__.<locals>.<genexpr>  s     >Xd^>   r   c              3   2   K   | ]  }t        |        y wr7   r  r   s     r3   r   z(Text.__rich_measure__.<locals>.<genexpr>  s     141r  )rc   
splitlinesmaxr>   r   )r2   r   r  rY   r   max_text_widthr   min_text_widths           r3   __rich_measure__zText.__rich_measure__  s^     zz!BG>>>Q

5:C1511 	 >>::r5   r   c              #   V  K   t         }| j                  }| j                  st        |       |r
 ||       yt        |j                  t        j                               }t        t        | j                  d            }|D ci c]  \  }}| ||j                         c}} || j                        d<   dgd |D        d |D        t        |      ddf}	|	j                  t        dd      	       g j                  }
j                  }i j                  t
        j                   d
t
        ffd}t#        |	|	dd       D ]9  \  \  }}}\  }}}|r	 ||       n |
|       ||kD  s' ||||  |              ; |r ||       yyc c}}w w)a  Render the text as Segments.

        Args:
            console (Console): Console instance.
            end (Optional[str], optional): Optional end character.

        Returns:
            Iterable[Segment]: Result of render that may be written to the console.
        Nr   r   r   )r   Fr   c              3   @   K   | ]  \  }}|j                   d |f  ywr   )r+   r   indexr   s      r3   r   zText.render.<locals>.<genexpr>  s     M[UDtzz5%(M   c              3   @   K   | ]  \  }}|j                   d |f  ywr   r  r  s      r3   r   zText.render.<locals>.<genexpr>  s     J+%txxu%Jr  Tr   r.   c                  t    t        fdt              D              }  |       }||S  |       }|| <   |S )z#Construct current style from stack.c              3   (   K   | ]	  }|     y wr7   rL   )r   	_style_id	style_maps     r3   r   z9Text.render.<locals>.get_current_style.<locals>.<genexpr>  s     OI9Y/Os   )tuplesorted)stylescached_stylecurrent_stylecombinestackstyle_cachestyle_cache_getr#  s      r3   get_current_stylez&Text.render.<locals>.get_current_style  sF    OOOF*62L'###FOM"/K  r5   )r   rc   rS   r   r   r   nulllist	enumerater-   r[   r   r   rl   removegetr)  zip)r2   r   r,   _SegmentrY   r   enumerated_spansr  r   rX   stack_append	stack_popr-  r9   leavingstyle_idnext_offset_r)  r*  r+  r,  r#  s                     @@@@@r3   r   zText.render  s     zz{{$-sm#G--uzz|D		$++q 9:EUVkeTUIdjj11V	 ,	! 
M<LM
 K9IJ
 Ya 	
 	

z!Q'
(||LL	68%//--	!5 	! 	! ADE5QRQS9@U 	N<'VWh)<+q!(#X&V#tF;79J9LMM	N 3- I Ws   BF)F#*CF) )F)r   c           
         	  j                         }dt        d   f fd}|j                  j                  }|j                  j
                  }|j                  j                  }d	t         |       D ]p  } ||j                         |j                  r& | 		t        |      z   |j                                |	fd|j                  D               	t        |      z  	r 	|_	        |S )zJoin text together with this instance as the separator.

        Args:
            lines (Iterable[Text]): An iterable of Text instances to join.

        Returns:
            Text: A new text instance containing join text.
        r.   r(   c               3   |   K   j                   rt              D ]  \  } }| | r  y E d {    y 7 wr7   )rc   r   )lastr   r   r2   s     r3   	iter_textzText.join.<locals>.iter_text  s>     zz"+E"2 #JD$J"
#
 !  s   $<<:<r   c              3   F   K   | ]  \  }}} |z   |z   |        y wr7   rL   )r   r+   r,   r-   rx   r9   s       r3   r   zText.join.<locals>.<genexpr>  s0      %E3 funfslE:   !)
r   r   rN   extendrS   rl   r*   r-   r[   rT   )
r2   r   r   r?  extend_textr   extend_spansrY   rx   r9   s
   ``      @@r3   r   z	Text.join  s     ??$	!8F+ 	! nn++oo,,--K 	 D

#zzE&&3t9*<djjIJ )-  c$iF	  "r5   c                 p   d| j                   vryd}|| j                  }|J | j                         }|j                  }| j                  }| j                  dd      D ]  }|j                  dd      }|D ]v  }|j                   j                  d      rQ|j                   dd dz   g|_         ||       |t        |      z  }||d	z
  |z  z
  d	z
  }	|	s] |d|	z  |       ||	z  }o ||       x  |j                   g| _        t        | j                         | _	        |j                  | j                  dd y)
ztConverts tabs to spaces.

        Args:
            tab_size (int, optional): Size of tabs. Defaults to 8.

        	Nr   rV   T)include_separatorr   rf   r   )rc   rR   r   rl   r-   r>   r   rN   r[   rT   rS   )
r2   rR   posrn   rl   _styler   r   r   spacess
             r3   expand_tabszText.expand_tabs  s6    tzz!}}H###"JJttJ< 	!DJJttJ<E 
!::&&t,"&**Sb/C"7!8DJ4L3t9$C%#'X)=>BFsV|V4v4L
!	! ll^
4::Ar5   F)rP   padr  rL  c                z   |xs | j                   xs t        }|dk7  rt        | j                        }||kD  rB|dk(  r"t	        | j                  |dz
        dz   | _        nt	        | j                  |      | _        |r?||k  r9||z
  }| j                   d|z   g| _        t        | j                        | _        yyyy)au  Truncate text if it is longer that a given width.

        Args:
            max_width (int): Maximum number of characters in text.
            overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None, to use self.overflow.
            pad (bool, optional): Pad with spaces if the length is less than max_width. Defaults to False.
        ignoreellipsisr   u   …rf   N)rP   r'   r   rc   r   rN   r[   rT   )r2   r  rP   rL  	_overflowr   rJ  s          r3   truncatezText.truncate)  s     AA1A	 djj)F	!
*!.tzz9q=!IE!QDJ!.tzz9!EDJv	)"V+!%S6\N;<
"4:: *s !r5   c           
      2   t        | j                        }t        }| j                  D cg c]T  }|j                  |k  rC|j
                  |k  r|n1 ||j                  t        ||j
                        |j                        V c}| j                  dd yc c}w )z=Remove or modify any spans that are over the end of the text.N)r[   rc   r*   rS   r+   r,   r;   r-   )r2   
max_offsetrx   r   s       r3   r   zText._trim_spansD  s    _
 
 zzJ&	 88j( 4::s:txx'@$**MN
A 
s   ABr   	characterc           
          t        |      dk(  sJ d       |r`||z  }| | j                   | | _        t        }| j                  D cg c]  \  }}} |||z   ||z   |       c}}}| j                  dd yyc c}}}w )zxPad left and right with a given number of characters.

        Args:
            count (int): Width of padding.
        r   &Character must be a string of length 1Nr[   rc   r*   rS   )r2   r   rT  pad_charactersrx   r+   r,   r-   s           r3   rL  zText.padR  s     9~"L$LL"&.N*+DJJ<7GHDJE *. %E3 eemS5[%8DKKN	 s   
A9c           
          t        |      dk(  sJ d       |r\||z   | j                   | _        t        }| j                  D cg c]  \  }}} |||z   ||z   |       c}}}| j                  dd yyc c}}}w )zPad the left with a given character.

        Args:
            count (int): Number of characters to pad.
            character (str, optional): Character to pad with. Defaults to " ".
        r   rV  NrW  )r2   r   rT  rx   r+   r,   r-   s          r3   pad_leftzText.pad_leftb  s     9~"L$LL"%-.tzzl;DJE *. %E3 eemS5[%8DKKN s   A5c                 d    t        |      dk(  sJ d       |r| j                   ||z   | _        yy)zPad the right with a given character.

        Args:
            count (int): Number of characters to pad.
            character (str, optional): Character to pad with. Defaults to " ".
        r   rV  N)r[   rc   )r2   r   rT  s      r3   r  zText.pad_rightr  s>     9~"L$LL" JJ<	E(9':;DJ r5   alignwidthc                    | j                  |       |t        | j                        z
  }|r]|dk(  r| j                  ||       y|dk(  r-|dz  }| j	                  ||       | j                  ||z
  |       y| j	                  ||       yy)zAlign text to a given width.

        Args:
            align (AlignMethod): One of "left", "center", or "right".
            width (int): Desired width.
            character (str, optional): Character to pad with. Defaults to " ".
        leftcenter   N)rQ  r   rc   r  rZ  )r2   r\  r]  rT  excess_spacer_  s         r3   r\  z
Text.align}  s     	ex

33|Y7("#q(dI.|d2I>lI6 r5   r   c           	      L   t        |t        t        f      st        d      t	        |      rtt        |t              r~t        |      }| j                  j                  |       t	        |       }t	        |      |)| j                  j                  t        ||z   |             | xj                  z  c_
        | S t        |t              rt        |t        d      | j                  |j                  9| j                  j                   t	        |      z   |j                               | j                  j                  |j                         | j                  j                  fd|j                  D               | xj                  t	        |      z  c_
        | S )zAdd text with an optional style.

        Args:
            text (Union[Text, str]): A str or Text to append.
            style (str, optional): A style name. Defaults to None.

        Returns:
            Text: Returns self for chaining.
        z(Only str or Text can be appended to Textz2style must not be set when appending Text instancec              3   F   K   | ]  \  }}} |z   |z   |        y wr7   rL   r   r+   r,   r-   rx   r   s       r3   r   zText.append.<locals>.<genexpr>  s2      #)sE %+-s[/@%H#rA  )rj   rJ   r(   r|   r[   r   rN   rl   rS   r*   rT   
ValueErrorr-   rc   rB  )r2   rY   r-   r\   r9   rx   r   s        @@r3   rl   zText.append  sU    $d,FGGt9$$!4T!:

!!.1T!.1$KK&&tFF[4H%'PQ+$ # D$'$$L  #ll::)KK&&k;T+BDJJO 

!!$**-"" #-1[[#  D	)r5   c           	         t         | j                  |j                  9| j                  j	                   t        |      z   |j                               | j                  j	                  |j                         | j                  j                  fd|j                  D               | xj                  t        |      z  c_        | S )zAppend another Text instance. This method is more performant that Text.append, but
        only works for Text.

        Returns:
            Text: Returns self for chaining.
        c              3   F   K   | ]  \  }}} |z   |z   |        y wr7   rL   re  s       r3   r   z#Text.append_text.<locals>.<genexpr>  s2      
!sE %+%s['8%@
rA  )	r*   rT   r-   rS   rl   r[   rN   rc   rB  )r2   rY   rx   r   s     @@r3   append_textzText.append_text  s     ll::!KKu[+D	2I4::VW

$**% 
%)[[
 	
 	D	!r5   tokensc           
      
   | j                   j                  }| j                  j                  }t        }t	        |       }|D ]9  \  }} ||       | | |||t	        |      z   |             |t	        |      z  }; || _        | S )a(  Append iterable of str and style. Style may be a Style instance or a str style definition.

        Args:
            pairs (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style.

        Returns:
            Text: Returns self for chaining.
        )rN   rl   rS   r*   r[   rT   )r2   rj  ri  r   rx   r9   contentr-   s           r3   append_tokenszText.append_tokens  s     jj''kk((T$ 	#NGU  E&&3w<*?GHc'l"F		#
 r5   c                 N    | j                   j                  |j                          y)zCopy styles from another Text instance.

        Args:
            text (Text): A Text instance to copy styles from, must be the same length.
        N)rS   rB  )r2   rY   s     r3   copy_styleszText.copy_styles  s     	4;;'r5   )rG  allow_blank	separatorrG  rp  c                   sJ d       | j                   vrt        | j                         g      S |r@| j                  d t	        j
                  t	        j                              D              }n<dt        t           ffd}t        fd| j                   |             D              }|s!j                        r|j                          |S )a  Split rich text in to lines, preserving styles.

        Args:
            separator (str, optional): String to split on. Defaults to "\\n".
            include_separator (bool, optional): Include the separator in the lines. Defaults to False.
            allow_blank (bool, optional): Return a blank line if the text ends with a separator. Defaults to False.

        Returns:
            List[RichText]: A list of rich text, one per line of the original.
        zseparator must not be emptyc              3   <   K   | ]  }|j                           y wr7   r  )r   r   s     r3   r   zText.split.<locals>.<genexpr>  s        %		 s   r.   c               3      K   t        j                  t        j                              D ]  } | j                         \  }}| |  y wr7   )r   r   r   r   )r   r+   r,   rq  rY   s      r3   flatten_spansz!Text.split.<locals>.flatten_spans  sC     [[9)=tD E!&JE3KIs   AAc              3   B   K   | ]  }|j                   k7  s|  y wr7   rb   )r   r   rq  s     r3   r   zText.split.<locals>.<genexpr>  s!      yAXs   )rc   r   rk   r{   r   r   r   r   rH   r   pop)r2   rq  rG  rp  r   ru  rY   s    `    @r3   r>   z
Text.split  s    " 777yzzD $))+''KK  )+RYYy5I4)P  E
8C=   !%]_!= E t}}Y7IIKr5   offsetsc           	         t        |      }|st        | j                         g      S | j                  t	              }dg||}t        t        ||dd             }| j                  | j                  | j                  t        t        fd|D              }| j                  s|S |j                  D cg c]  }|j                  j                   }}t	        |      }	t        }
| j                  D ]  \  }}d}|	}||z   dz  }	 ||   \  }}||k  r|dz
  }n||kD  r|dz   }nn	||z   dz  }(||k  r|}n/|x}}|	}	 ||   \  }}||k  r|dz
  }n||kD  r|dz   }nn	||z   dz  }(t        ||dz         D ]D  }||   \  }}t        d||z
        }t!        ||z
  ||z
        }||kD  s2 ||    |
||             F  |S c c}w )zDivide text in to a number of lines at given offsets.

        Args:
            offsets (Iterable[int]): Offsets used to divide text.

        Returns:
            Lines: New RichText instances between offsets.
        r   r   Nc              3   B   K   | ]  \  }} ||          yw))r-   rO   rP   NrL   )r   r+   r,   r   rO   rP   r-   rY   s      r3   r   zText.divide.<locals>.<genexpr>2  s;      
 s U3!	 
s   ra  )r/  r   rk   rc   r[   r3  r-   rO   rP   r(   rS   _linesrl   r*   ranger  r;   )r2   rx  _offsetsr   divide_offsetsline_ranges	new_linesr   _line_appends
line_countrx   
span_startspan_endlower_boundupper_boundstart_line_no
line_startline_endend_line_noline_no	new_startnew_endr   rO   rP   r-   rY   s                         @@@@@r3   r{   zText.divide  sJ    =$))+''zz$i4h443~~ab/ABC

,,== 
 *
 
	 {{8A8H8HI++II%
+/;; %	M'J%K$K(;61<M'2='A$
H
*"/!"3K(*"/!"3K!,{!:q @  ("+,99k(+6{+C(J*,&1Ao!H,&1Ao#.#<"BK  !a@ M'27';$
H:
#:;	h3X
5JKY&*M'*5GU+KLMA%	MN W Js   G
amountc           
         t        | j                        |z
  }t        }| j                  D cg c]T  }|j                  |k  rC|j
                  |k  r|n1 ||j                  t        ||j
                        |j                        V c}| j                  dd | j                  d|  g| _        | xj                  |z  c_	        yc c}w )z7Remove a number of characters from the end of the text.N)
r[   rc   r*   rS   r+   r,   r;   r-   rN   rT   )r2   r  rS  rx   r   s        r3   rC   zText.right_cropk  s    _v-
 
 zzJ&	 88j( 4::s:txx'@$**MN
A jj6'*+

s   ACr
  c                6   |xs | j                   xs t        }|xs | j                  xs t        }t	        || j
                  d      xs |dk(  }t               }	| j                  d      D ]  }
d|
v r|
j                  |       |rt        |
g      }n+t        t        |
      ||dk(        }|
j                  |      }|D ]  }
|
j                  |        |r|j                  ||||       |D ]  }
|
j                  ||	        |	j                  |        |	S )
a  Word wrap the text.

        Args:
            console (Console): Console instance.
            width (int): Number of characters per line.
            emoji (bool, optional): Also render emoji code. Defaults to True.
            justify (str, optional): Justify method: "default", "left", "center", "full", "right". Defaults to "default".
            overflow (str, optional): Overflow method: "crop", "fold", or "ellipsis". Defaults to None.
            tab_size (int, optional): Default tab size. Defaults to 8.
            no_wrap (bool, optional): Disable wrapping, Defaults to False.

        Returns:
            Lines: Number of lines.
        FrN  Trp  rF  r&   )r&   r   )rP   )rO   r%   rP   r'   r   rQ   r   r>   rK  r   rJ   r{   r  rQ  rB  )r2   r   r]  rO   rP   rR   rQ   wrap_justifywrap_overflowr   r   r  rx  s                r3   r  z	Text.wrap{  s   0 A$,,A/ EDMME5EGT\\59QX=QJJ4J0 	$Dt|  *!4&M	%c$i]f=TU KK0	! '&'!!UL= "  " =em<=LL#!	$" r5   c                     t               }|j                  }| j                         D ]  }|j                  |        ||        |S )zFit the text in to given width by chopping in to lines.

        Args:
            width (int): Maximum characters in a line.

        Returns:
            Lines: Lines container.
        )r   rl   r>   r  )r2   r]  r   rl   r   s        r3   fitzText.fit  sC     wJJL 	DOOE"4L	 r5   c                 :   t        j                  d| j                  t         j                        D ch c]  }t	        |j                  d             }}	 t        t        |D cg c]
  }|dz  r	| c}      xs d}|S c c}w c c}w # t        $ r d}Y |S w xY w)zrAuto-detect indentation of code.

        Returns:
            int: Number of spaces used to indent code.
        
^( *)(.*)$r   r   ra  )	r   r   rc   	MULTILINEr[   r   r   r   r|   )r2   r   _indentationsindentindentations        r3   detect_indentationzText.detect_indentation  s     ]DJJbllS
 A
 

	s-RvPQzVRSXWX  
 S 	K	s/   !BB %
B
0B
4B B BBu   │z	dim green)rT  r-   indent_sizec                $   || j                         n|}| j                         }|j                          | d|dz
  z   }t        j                  d      }g }|j
                  }	d}
|j                  d      D ]  }|j                  |j                        }|r|j                  d      s|
dz  }
7|j                  d      }t        t        |      |      \  }}||z   d|z   }||j                  t        |      d z   |_        |j                  |dt        |             |
r"|j                  t        ||	      g|
z         d}
 |	|        |
r |j                  t        d
|	      g|
z         |j                  d      j!                  |      }|S )u  Adds indent guide lines to text.

        Args:
            indent_size (Optional[int]): Size of indentation, or None to auto detect. Defaults to None.
            character (str, optional): Character to use for indentation. Defaults to "│".
            style (Union[Style, str], optional): Style of indent guides.

        Returns:
            Text: New text with indentation guides.
        Nrf   r   r  r   Tr  ra  r-   rU   rV   )r  rk   rK  r   compilerl   r>   r   rc   r   divmodr[   r   rB  r(   r   r   )r2   r  rT  r-   _indent_sizerY   indent_line	re_indentr  add_lineblank_linesr   r   r  full_indentsremaining_space
new_indentr   s                     r3   with_indent_guideszText.with_indent_guides  s   $ 5@4Gt..0[yy{"C<!+;$<#=>JJ}-	 "	##JJ4J0 	DOODJJ/EAq [[^F,23v;,M)L/',67o8M7NOJ#djjZ1B&CCDJLL3z?3  $z"?!@;!NOTN	 d2U34{BC??4(--i8r5   )rU   rU   )rU   )r.   r(   )r   Nr7   )r.   N)rf   )rY   r(   r.   r(   )rY   r(   r.   N)rV   )r   )QrD   rE   rF   rG   	__slots__rJ   r   r   r   rK   rH   r   r*   r]   r_   r8   rd   r4   r   ro   objectrr   rt   ru   r   propertyr   r   classmethodr   r   r   r   r   r   r
   r   rc   setterrX   r   rk   r   r   r   r   r   r   GetStyleCallabler   r   r   r   r  r  r   r  r   r  r   r   rK  rQ  r   rL  rZ  r  r   r\  rl   ri  rm  ro  r   r>   r{   rC   r  r  r  r  rL   r5   r3   r(   r(   e   s   
I #%0
 .2/3"&"#&*00 S%Z 0
 /*0 +,0 $0 0 3-0 T
#0 
0. "$ " 8# 8S V IF It I
& T IsEz!2 Iv I4 $# $ $   : 
 $&04-1/3 S%Z 	
   - /* +,  
 > 
 $&-1/3"&"### S%Z 	#
 /*# +,# $# # 3-# 
# #J  
 .2/3 
 /* +, 
 0  $&-1/3"&)-*c65i#889* S%Z * /*	*
 +,* $* * * tCH~&* 
* *X s   \\#c #d # # tDz   \\4: $   V " !	ES%Z E E c]	E
 
E: !	HS%Z H H c]	H
 
H6 JN2cN2+.29A#2	2xS#X/ C F ()C )D )9 c e . ?C$
 $$ .	9:;$
 $ 
$V  $} S%Z 
  
:)?s ?t ?5S 5T 5; ;+;;	'	;&
; 
;+;
;	
;9 i 9 c 9 8I;N 9 v%(6* %v %N 'HSM  'T  'L 04// +,	/
 / 
/6
  t  c c D  	<s 	<s 	<T 	<7; 7s 7s 7T 7* PT*&#+&*/7c7l8K/L*	*X&uS(9*=%=>?	.( * #(!**  	*
 * 
*XNhsm N N` T * .2/3"&// /
 /*/ +,/ / $/ 
/b   C . &*. &.c]. 	.
 . 
.r5   __main__)r    a  
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Loremboldipsumitaliczjustify='left'redr  zjustify='center'greenr`  )r-   rO   zjustify='right'bluerightzjustify='full'magentafull)Br   	functoolsr   r   mathr   operatorr   typingr   r   r	   r
   r   r   r   r   r   r   _loopr   _pickr   _wrapr   r\  r   cellsr   r   
containersr   controlr   r   r   jupyterr   measurer   segmentr   r-   r   r   r   r    r!   r"   r#   r%   rI   r'   r  r   rJ   TextTyper  r*   r(   rD   pip._vendor.rich.consolerY   r   ruleprintrL   r5   r3   <module>r     s   	 %         *  (  !    #OO#, ,%+ " + G$fSE8I#667 54: 54pZ< Zz$ z0 	PD 	'F+'H-iGLL!"MM$eM$MMOLL#$MM$gxM8MMOLL"#MM$fgM6MMOLL!"MM$iM8MMO3 r5   