
    AHjL                        d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ dZdd	Z	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
ZddZy)    )annotationsN)Path)	AwaitableCallableIterablecast)
import_app)App)Pilotz.screenshot_cachec           
        	 t        j                  |d         }|d   }|j                  dd      }	|j                  dd      }
|	rg |	j                  d      ng }|
!|j                  |
j	                  dd             |j                  d	      }t        d
|       t        j                         }	 t        |j                  dd            }t        |j                  dd            }|j                  dd      }t        d||||||fdd      }t        j                  |       |J |S # t        j                  |       w xY w# t        $ r}ddl}|j                  |       Y d}~yd}~ww xY w)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                       D/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/_doc.py
format_svgr:      sT   &U6]31v7D)		&$'(.$&,,s#$BLLud34		'"x()iik	uyy"-.D%))Ir23GIIgr*E%&o#(	C HHSM
 HHSM
  !!%(	s1   B.E 1AD) E )E  E 	E+E&&E+c	                   | J t              } | J | j                  dfd}	NLt        t              }
|
j	                  d       |
 |	|       z  }|j                         r|j                         S dfd}t        t        | j                  d|            }j                  |       |J |S )a  

    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           	     b   t        j                         }g| j                  z   }|D ]:  }|J t        |d      5 }|j	                  |j                                d d d        < |j	                   d d
 d	 j                  d             |j                          d}|S # 1 sw Y   xY w)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_keyz*take_svg_screenshot.<locals>.get_cache_keyg   s    {{}Z#,,.
 	0D###dD! 0[K,,./0 0	0 	ugQugQugQ}o>EEgNO~~'(-		0 0s    B%%B.	T)exist_okc                n  K   | j                   }' |       }t        j                  |      r
| d {    | j                          d {     | j                    d {    r2| j                         d {    | j                  d       d {    	r0| j                          d {    | j                          d {    | j                          d {    | j                          d {    |j                        }|j                  |       y 7 7 7 7 7 7 {7 e7 O7 9w)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_pilotz'take_svg_screenshot.<locals>.auto_pilotz   s	    ii!&F""6*kkmekk5!!!++e$$$++c"""55777++-kkm11333##%(#C !$"73s   1D5D#D5D%D5#D'$D5>D)?D5D+D51D-2D5	D/
D5!D1"D59D3:*D5%D5'D5)D5+D5-D5/D51D53D5)headlessrY   size)rG   r
   returnstr)rV   r   r\   None)r	   r   r   SCREENSHOT_CACHEmkdirexists	read_textr   r]   run
write_text)rG   rL   r   r   r   r   rX   r   r   rM   screenshot_cachescreenshot_pathrY   r7   s    ````````     r9   r&   r&   ?   s    > {###"??}			 	 
 2 01-*]3-??!!#",,.. ( ! 	 	
C 
 2""3'??J    c                   ddl }ddlm} |j                  dd      }	t	        |j                  dd            }
t	        |j                  dd	            } ||j                         d
d
d||
      } |d
      }i }	 t        | |       d|v r|j                  |d          |j                  |	      }|S # t        $ r |j                          Y Gw xY w)r   r   N)Consoler   Richr   r   r   r   T	truecolor)filerecordforce_terminalcolor_systemwidthheight)stderroutput)r   )iorich.consoleri   r   r%   StringIOexecr(   r*   r"   
export_svg)r+   r,   r-   r.   r/   r0   r1   rt   ri   r   r6   r   consoleerror_consoleglobals
output_svgs                   r9   richr}      s     $IIgv&Euyy"%&D%))Ir*+G[[] G 4(MG(VW
 7gh'(##%#0J  (%%'(s   ;B3 3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]rX   z0Callable[[Pilot], Awaitable[None] | None] | Noner   boolr\   r]   )
__future__r   r?   rP   r#   r   pathlibr   typingr   r   r   r   textual._import_appr	   textual.appr
   textual.pilotr   r_   r:   r&   r}   r~   rg   r9   <module>r      s    "   	   6 6 *  & 
)Z %-CG#]	]] ] 	]
 ] #] A] ] 	]@ rg   