
    CjL                        S SK Jr  S SKrS SKrS SKrS SKrS SKJr  S SKJ	r	J
r
JrJr  S SKJr  S SKJr  S SKJr  SrSS	 jr         S                 SS
 jjrSS jrg)    )annotationsN)Path)	AwaitableCallableIterablecast)
import_app)App)Pilotz.screenshot_cachec                    [         R                  " US   5      nUS   nUR                  SS5      n	UR                  SS5      n
U	(       a  / U	R                  S5      QO/ nU
b!  UR                  U
R	                  SS5      5        UR                  S	5      n[        S
U< 35        [        R                  " 5       n [        UR                  SS5      5      n[        UR                  SS5      5      nUR                  SS5      n[        SUUUUX4SSS9n[        R                  " U5        Uc   eU$ ! [        R                  " U5        f = f! [         a  nSSKnUR                  U5         SnAgSnAff = f)4A superfences formatter to insert an SVG screenshot.pathr   pressNtype,z\t	titlezscreenshotting lines   columnsP   hover F)r   r   terminal_sizewait_for_animationsimplify)shlexsplitgetextendreplaceprintosgetcwdinttake_svg_screenshotchdir	Exception	tracebackprint_exception)sourcelanguage	css_classoptionsmdattrskwargscmdr   _press_typer   r   cwdrowsr   r   svgerrorr)   s                       ^/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/_doc.py
format_svgr:      sR   &U6]31v7D)		&$'(.$&,,s#$BLLud34		'"x()iik	uyy"-.D%))Ir23GIIgr*E%&o#(	C HHSM
 HHSM
  !!%(	s1   B7E :AD0 E 0EE 
E4E//E4c	           	       ^^^^^^^^ U c  Tc   e[        T5      n U c   eTc  U R                  mSUUUUU4S jjn	TbP  TcM  [        [        5      n
U
R	                  SS9  X" U 5      -  nUR                  5       (       a  UR                  5       $ SUUUUUU4S jjn[        [        U R                  SUTS95      nTb  Tc  WR                  U5        Uc   eU$ )av  

Args:
    app: An app instance. Must be supplied if app_path is not.
    app_path: A path to an app. Must be supplied if app is not.
    press: Key presses to run before taking screenshot. "_" is a short pause.
    hover: Hover over the given widget.
    title: The terminal title in the output image.
    terminal_size: A pair of integers (rows, columns), representing terminal size.
    run_before: An arbitrary callable that runs arbitrary code before taking the
        screenshot. Use this to simulate complex user interactions with the app
        that cannot be simulated by key presses.
    wait_for_animation: Wait for animation to complete before taking screenshot.
    simplify: Simplify the segments by combining contiguous segments with the same style.

Returns:
    An SVG string, showing the content of the terminal window at the time
        the screenshot was taken.
c           	     v  > [         R                  " 5       nT/U R                  -   nU H<  nUc   e[        US5       nUR	                  UR                  5       5        S S S 5        M>     UR	                  T ST ST
 ST	 3R                  S5      5        UR                  5        S3nU$ ! , (       d  f       M  = f)Nrb-zutf-8z.svg)hashlibmd5css_pathopenupdatereadencode	hexdigest)apphash
file_pathsr   source_file	cache_keyapp_pathr   r   r   r   s         r9   get_cache_key*take_svg_screenshot.<locals>.get_cache_keyg   s    {{}Z#,,.
D###dD![K,,./ "!  	ugQugQugQ}o>EEgNO~~'(-		 "!s    B))
B8	T)exist_okc                  >#    U R                   nTb-  T" U 5      n[        R                  " U5      (       a
  UI S h  vN   U R                  5       I S h  vN   U R                  " T6 I S h  vN   T(       a2  U R                  T5      I S h  vN   U R                  S5      I S h  vN   T	(       a0  U R                  5       I S h  vN   U R                  5       I S h  vN   U R                  5       I S h  vN   U R                  5       I S h  vN   UR                  TTS9nUR                  U5        g  N N N N N Nx Nb NL N67f)Ng      ?)r   r   )	rG   inspectisawaitablepauser   r   wait_for_scheduled_animationsexport_screenshotexit)
pilotrG   resultr7   r   r   
run_beforer   r   r   s
       r9   
auto_pilot'take_svg_screenshot.<locals>.auto_pilotz   s    ii!&F""6**kkmkk5!!!++e$$$++c"""55777++-kkm11333##%(#C !$"73s   8ED1ED3E*D5+E
D7E#D9$ED;ED=E2D?3E
E'E3E5E7E9E;E=E?EE)headlessrZ   size)rG   r
   returnstr)rW   r   r^   None)r	   r   r   SCREENSHOT_CACHEmkdirexists	read_textr   r_   run
write_text)rG   rL   r   r   r   r   rY   r   r   rM   screenshot_cachescreenshot_pathrZ   r7   s    ````````     r9   r&   r&   ?   s    > {###"??}			 	 
 2 01-*]3-??!!##",,.. ( ! 	 	
C 
 2""3'??J    c           	        SSK nSSKJn  UR                  SS5      n	[	        UR                  SS5      5      n
[	        UR                  SS	5      5      nU" UR                  5       S
S
SUU
S9nU" S
S9n0 n [        X5        SU;   a  UR                  US   5        UR                  U	S9nU$ ! [         a    UR                  5          NGf = f)r   r   N)Consoler   Richr   r   r   r   T	truecolor)filerecordforce_terminalcolor_systemwidthheight)stderroutput)r   )iorich.consolerk   r   r%   StringIOexecr(   r*   r"   
export_svg)r+   r,   r-   r.   r/   r0   r1   rv   rk   r   r6   r   consoleerror_consoleglobals
output_svgs                   r9   richr      s     $IIgv&Euyy"%&D%))Ir*+G[[] G 4(MG(V
 7gh'(##%#0J  (%%'(s   5B+ +CC)r^   r_   )	NN r   N)r   r   NTT)rG   z
App | NonerL   
str | Noner   zIterable[str]r   r_   r   r   r   ztuple[int, int]rY   z0Callable[[Pilot], Awaitable[None] | None] | Noner   boolr^   r_   )
__future__r   r?   rQ   r#   r   pathlibr   typingr   r   r   r   textual._import_appr	   textual.appr
   textual.pilotr   ra   r:   r&   r   r   ri   r9   <module>r      s    "   	   6 6 *  & 
)Z %-CG#]	]] ] 	]
 ] #] A] ] 	]@ ri   