
    Cj.6                    B   % S SK Jr  S SKJrJr  S SKJr  S SKJr  S SK	J
r
JrJr  S SKrS SKJrJrJr  S SKJr  S S	KJrJr  S S
KJr  S SKJr  S SKJr  S SKJ r   S SK!J"r"  S SK#J$r$  S SK%J&r&  S SK'J(r(  S SK)J*r*  S SK+Jr  \
(       a  S SK,J-r-  S SK.J/r/  S(S jr0\" SS9 " S S5      5       r1 " S S\5      r2 " S S\35      r4Sr5S\6S '   S)S*S" jjr7 " S# S!\5      r8\Rr                  Rt                   " S$ S%\85      5       r;\Rr                  Rt                   " S& S'\85      5       r<g)+    )annotations)ABCabstractmethod)	dataclass)islice)TYPE_CHECKINGCallableProtocolN)ConsoleConsoleOptionsRenderableType)Measurement)is_renderable	rich_cast)Segment)Style)Text)
active_app)RulesMap)Spacing)measure)	Selection)Strip)	TypeAlias)Widgetc                H    [        U [        5      =(       d    [        U S5      $ )zFCheck if the given object is a Visual or supports the Visual protocol.
textualize)
isinstanceVisualhasattr)objs    `/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/visual.py	is_visualr#      s    c6"@gc<&@@    T)frozenc                  `    \ rS rSr% SrS\S'    S\S'    SrS\S	'    SrS
\S'    SrS
\S'   Sr	g)RenderOptions#   z4Additional options passed to `Visual.render_strips`.zCallable[[str | Style], Style]	get_styler   rulesNzSelection | None	selectionStyle | Noneselection_style
post_style )
__name__
__module____qualname____firstlineno____doc____annotations__r+   r-   r.   __static_attributes__r/   r$   r"   r'   r'   #   s>    >--"O!"&I&%$(O\("#J#.r$   r'   c                  "    \ rS rSrSrSS jrSrg)SupportsVisual4   z0An object that supports the textualize protocol.c                    g)zConvert the result of a Widget.render() call into a Visual, using the Visual protocol.

Args:
    widget: The widget that generated the render.
    obj: The result of the render.

Returns:
    A Visual instance, or `None` if it wasn't possible.

Nr/   )selfwidgetr!   s      r"   	visualizeSupportsVisual.visualize7       r$   r/   N)r<   r   r!   objectreturnzVisual | None)r0   r1   r2   r3   r4   r=   r6   r/   r$   r"   r8   r8   4   s
    :
r$   r8   c                      \ rS rSrSrSrg)VisualErrorD   z"An error with the visual protocol.r/   N)r0   r1   r2   r3   r4   r6   r/   r$   r"   rC   rC   D   s    ,r$   rC   z(RenderableType | SupportsVisual | Visualr   
VisualTyper   c                >   Sn[        U[        5      (       a  U$ [        USS5      nUc  SSKJn  [        U[
        5      (       a   U(       a  UR                  U5      $ U" U5      $ [        U5      (       aM  [        U[        5      (       a#  UR                  XR                  R                  S9$ [        U [        U5      5      $ [        SUR                  R                   < S35      eU" 5       n[        U[        5      (       d  [        U5      (       a  [        X5      $ U$ )	a  Get a visual instance from an object.

If the object does not support the Visual protocol and is a Rich renderable, it
will be wrapped in a [RichVisual][textual.visual.RichVisual].

Args:
    widget: The parent widget.
    obj: An object.
    markup: Enable markup.

Raises:
    VisualError: If there is no Visual could be returned to render `obj`.

Returns:
    A Visual instance to render the object, or `None` if there is no associated visual.
Tr=   Nr   )Content)consolezunable to display z? type; must be a str, Rich renderable, or Textual Visual object)r   r   getattrtextual.contentrG   strfrom_markupr   r   from_rich_textapprH   
RichVisualr   rC   	__class__r0   )r<   r!   markup_rich_traceback_omitr=   rG   visuals          r"   r=   r=   K   s    "  #v
[$/I+c3/57&&s+G73<G#t$$--c::;M;M-NN fin55 $S]]%;%;$>>}~  [Fff%%-*?*?&))Mr$   c                      \ rS rSrSr\          SS j5       r\SS j5       rSS jr\SS j5       r	\
SSS	S
.                 SS jj5       rSrg	)r   {   z`A Textual 'Visual' object.

Analogous to a Rich renderable, but with support for transparency.

c                    g)a  Render the Visual into an iterable of strips.

Args:
    width: Width of desired render.
    height: Height of desired render or `None` for any height.
    style: The base style to render on top of.
    options: Additional render options.

Returns:
    An list of Strips.
Nr/   )r;   widthheightstyleoptionss        r"   render_stripsVisual.render_strips   r?   r$   c                    g)a  Get optimal width of the Visual to display its content.

The exact definition of "optimal width" is dependant on the Visual, but
will typically be wide enough to display output without cropping or wrapping,
and without superfluous space.

Args:
    rules: A mapping of style rules, such as the Widgets `styles` object.
    container_width: The width of the container, used by Rich Renderables.
        May be ignored for Textual Visuals.

Returns:
    A width in cells.

Nr/   r;   r*   container_widths      r"   get_optimal_widthVisual.get_optimal_width   r?   r$   c                    g)a+  Get a minimal width (the smallest width before data loss occurs).

Args:
    rules: A mapping of style rules, such as the Widgets `styles` object.
    container_width: The width of the container, used by Rich Renderables.
        May be ignored for Textual Visuals.

Returns:
    A width in cells.

   r/   )r;   r*   s     r"   get_minimal_widthVisual.get_minimal_width   s     r$   c                    g)zGet the height of the Visual if rendered at the given width.

Args:
    rules: A mapping of style rules, such as the Widgets `styles` object.
    width: Width of visual in cells.

Returns:
    A height in lines.
Nr/   r;   r*   rW   s      r"   
get_heightVisual.get_height   r?   r$   TFN)apply_selectionpadr.   c                  UR                   n	U	b0  [        R                  " UR                  R	                  S5      5      n
OSn
UR                  UUU[        UR                  UR                  U(       a  U	OSU
5      5      nUR                  (       aX  UR                  (       dG  UR                  R                  (       d,  UR                  nU Vs/ s H  oR                  U5      PM     nnUc  [        U5      nU[        SS9-   R                  nU(       a   U Vs/ s H  oR!                  X>5      PM     nnUR                  R"                  nUS:w  a)  Uu  nn[%        [&        R(                  " UUUUUU5      5      nU$ s  snf s  snf )a  High level function to render a visual to strips.

Args:
    widget: Widget that produced the visual.
    visual: A Visual instance.
    width: Desired width (in cells).
    height: Desired height (in lines) or `None` for no limit.
    style: A (Visual) Style instance.
    apply_selection: Automatically apply selection styles?
    pad: Pad to desired width?
    post_style: Optional Style to apply to strips after rendering.

Returns:
    A list of Strips containing the render.
Nzscreen--selectionF)reverse)lefttop)text_selectionr   from_stylesscreenget_component_stylesr[   r'   
_get_stylestyles
auto_linksis_container
_selecting
link_style_apply_link_stylelen
rich_styleextend_cell_lengthcontent_alignlistr   align)clsr<   rS   rW   rX   rY   rj   rk   r.   r+   r-   stripsry   stripr|   r~   align_horizontalalign_verticals                     r"   	to_stripsVisual.to_strips   sc   : ))	 #//223FGO #O%%!!,	$		

 ''MM,,**JGMNve--j9vFN>[FeE22>>
OUVve..uAvFV33O+/<,n$"	F ) O Ws   E:E?r/   
rW   intrX   
int | NonerY   r   rZ   r'   rA   list[Strip]r*   r   r_   r   rA   r   )r*   r   rA   r   r*   r   rW   r   rA   r   )r<   r   rS   r   rW   r   rX   r   rY   r   rj   boolrk   r   r.   r,   rA   r   )r0   r1   r2   r3   r4   r   r[   r`   rd   rh   classmethodr   r6   r/   r$   r"   r   r   {   s     ",5:ER	   " 	 	  !%#'II I 	I
 I I I I !I 
I Ir$   c                  h    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	          SS jr
S	rg
)rO   i  z#A Visual to wrap a Rich renderable.c                *    Xl         X l        SU l        g)zN

Args:
    widget: The associated Widget.
    renderable: A Rich renderable.
N)_widget_renderable_measurement)r;   r<   
renderables      r"   __init__RichVisual.__init__  s     %04r$   c              #  D   #    U R                   v   U R                  v   g 7fN)r   r   r;   s    r"   __rich_repr__RichVisual.__rich_repr__  s     ll    c           	         U R                   cT  [        R                  " UUU R                  R	                  U R
                  [        R                  " 5       5      5      U l         U R                   $ r   )r   r   getr   post_renderr   	RichStylenull)r;   rH   rZ   s      r"   _measureRichVisual._measure  sT    $ +(()9)99>>;KL!D
    r$   c                l    [         R                  " 5       R                  n[        X0R                  X"S9nU$ )N)r_   )r   r   rH   r   r   )r;   r*   r_   rH   rW   s        r"   r`   RichVisual.get_optimal_width'  s0    .."**%%
 r$   c           	        [         R                  " 5       nUR                  nU R                  n[	        U[
        5      (       aM  [        [        UR                  5      R                  UUUR                  UR                  =(       d    SS95      nU$ UR                  nUR                  U5      R                  SS9nUR                  XX5      n	[        U	 V
Vs/ s H  u  n
  oR!                  S5      PM     snn
5      nU$ s  snn
f )N   )no_wraptab_sizeF)	highlight
)r   r   rH   r   r   r   r{   plainwrapr   r   console_optionsupdate_widthupdaterendersumcount)r;   r*   rW   rN   rH   r   rX   r   rZ   segmentstext_s               r"   rh   RichVisual.get_height.  s    nn++%%
j$''Z%%&++&..'005A	 , F  "11O%2259@@5@QG~~j:HXFXztQ**T*XFGF Gs   C=
c           	        [         R                  " 5       nUR                  nUR                  R	                  SUUS9nUR
                  nU R                  R                  U R                  U5      n	UR                  XR                  U5      5      n
[        [        R                  " XSSS9SU5       Vs/ s H  n[        U5      PM     nnU$ s  snf )-  Render the Visual into an iterable of strips. Part of the Visual protocol.

Args:
    width: Width of desired render.
    height: Height of desired render or `None` for any height.
    style: The base style to render on top of.
    options: Additional render options.

Returns:
    An list of Strips.
F)r   rW   rX   )include_new_linesrk   N)r   r   rH   r   r   r|   r   r   r   r   r   r   r   split_and_crop_linesr   )r;   rW   rX   rY   rZ   rN   rH   r   r|   r   r   liner   s                r"   r[   RichVisual.render_stripsD  s     nn++--44 5 

 %%
\\--d.>.>
K
>>*.J.J5.QR ,,u% 	
 $K 	 	
 	
s   2C)r   r   r   N)r<   r   r   r   rA   NonerA   zrich.repr.Result)rH   r   rZ   r   rA   r   r   r   r   )r0   r1   r2   r3   r4   r   r   r   r`   rh   r[   r6   r/   r$   r"   rO   rO     sK    -	5!,##",#5:#ER#	#r$   rO   c                  ^    \ rS rSrSrS
S jrSS jrSS jrSS jr          SS jr	Sr
g	)Paddingij  zA Visual to pad another visual.c                    Xl         X l        g)zc

Args:
    Visual: A Visual.
    spacing: A Spacing object containing desired padding dimensions.
N_visual_spacing)r;   rS   spacings      r"   r   Padding.__init__n  s     r$   c              #  D   #    U R                   v   U R                  v   g 7fr   r   r   s    r"   r   Padding.__rich_repr__x  s     llmmr   c                f    U R                   R                  X5      U R                  R                  -   $ r   )r   r`   r   rW   r^   s      r"   r`   Padding.get_optimal_width|  s(    LL**5BT]]EXEXX	
r$   c                    U R                   R                  XU R                  R                  -
  5      U R                  R                  -   $ r   )r   rh   r   rW   rX   rg   s      r"   rh   Padding.get_height  s:    LL##E4==3F3F+FGmm""#	
r$   c           
        U R                   nU R                   u  pgpXU-   -
  n
U
S::  a  / $ U R                  R                  U
Uc  SOX%R                  -
  UU5      nU(       a{  UR                  nU(       a  [
        R                  " X5      /U-  O/ nU(       a  [
        R                  " X5      /U-  O/ n/ UQU Vs/ s H  nUR                  XX|5      PM     snQUQnU$ s  snf )r   r   N)r   r   r[   rX   r|   r   blankcrop_pad)r;   rW   rX   rY   rZ   paddingro   rightbottomrn   render_widthr   r|   top_paddingbottom_paddingr   s                   r"   r[   Padding.render_strips  s     --#'== Fu-1I++ND(?	
 ))JDG5;;u9:S@RKJPekk%<=FVXN "(!' NN<uI!'  F s   :C)r   r   N)rS   r   r   r   rA   r   r   r   r   r   )r0   r1   r2   r3   r4   r   r   r`   rh   r[   r6   r/   r$   r"   r   r   j  sF    ) 


((",(5:(ER(	(r$   r   )r!   r@   rA   r   )T)r<   r   r!   r@   rQ   r   rA   r   )=
__future__r   abcr   r   dataclassesr   	itertoolsr   typingr   r	   r
   	rich.reprrichrich.consoler   r   r   rich.measurer   rich.protocolr   r   rich.segmentr   
rich.styler   r   	rich.textr   textual._contextr   textual.css.stylesr   textual.geometryr   textual.renderr   textual.selectionr   textual.stripr   textual.styletyping_extensionsr   textual.widgetr   r#   r'   r8   	ExceptionrC   rE   r5   r=   r   reprautorO   r   r/   r$   r"   <module>r      s    " # !  4 4  @ @ $ 2   )  ' ' $ " '  +%A
 $/ / / X  -) - C
I B-`MS M` [ [ [| Df D Dr$   