
    CjU(                        S SK Jr  S SKrS SK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JrJrJr  S SKJrJrJr  S SKJr  \(       a  S S	KJr   " S
 S\5      rg)    )annotationsN)ABCabstractmethod)contextmanager)Path)TYPE_CHECKINGAnyBinaryIOIteratorLiteralTextIO)eventslogmessages)MouseUp)Appc                     \ rS rSrSrSSSS.         S S jjr\S!S j5       r\S!S	 j5       r\S!S
 j5       r	\S!S j5       r
S"S jrS"S jr\S#S j5       rS$S jr\S$S j5       r\S$S j5       r\S$S j5       rS$S jrS$S jr " S S\R,                  5      r\S%S j5       rS$S jrS&S'S jjrSSSSS.               S(S jjr        S)S jr        S*S jrSrg)+Driver   zA base class for drivers.FTN)debugmousesizec                   Xl         X l        X0l        X@l        [        R
                  " 5       U l        / U l        SU l        SU l	         SU l
        g)zInitialize a driver.

Args:
    app: The App instance.
    debug: Enable debug mode.
    mouse: Enable mouse support,
    size: Initial size of the terminal or `None` to detect.
NT)_app_debug_mouse_sizeasyncioget_running_loop_loop_down_buttons_last_move_event_auto_restartcursor_origin)selfappr   r   r   s        `/home/rurouni/.local/share/pipx/venvs/strix-agent/lib/python3.13/site-packages/textual/driver.py__init__Driver.__init__   sK      	
--/
(*9=!F59    c                    g)z%Is the driver 'headless' (no output)?F r%   s    r'   is_headlessDriver.is_headless/        r*   c                    g)z)Is the driver 'inline' (not full-screen)?Fr,   r-   s    r'   	is_inlineDriver.is_inline4   r0   r*   c                    g)z,Is the driver 'web' (running via a browser)?Fr,   r-   s    r'   is_webDriver.is_web9   r0   r*   c                    g)zCan this driver be suspended?Fr,   r-   s    r'   can_suspendDriver.can_suspend>   r0   r*   c                t    [         R                  " U R                  R                  U5      U R                  S9  g)zASend a message to the target app.

Args:
    message: A message.
)loopN)r   run_coroutine_threadsafer   _post_messager    )r%   messages     r'   send_messageDriver.send_messageC   s*     	((II##G,4::	
r*   c                   UR                  U R                  5        U R                  c  SnSnOU R                  u  p#[        U[        R
                  5      (       aT  U=R                  U-  sl        U=R                  U-  sl        U=R                  U-  sl        U=R                  U-  sl	        [        U[        R                  5      (       a8  UR                  (       a%  U R                  R                  UR                  5        GO[        U[        R                  5      (       aR  UR                  (       a?  UR                  U R                  ;   a%  U R                  R                  UR                  5        GO8[        U[        R                   5      (       Ga  U R                  (       Ga   UR                  (       d  U R"                  b  [%        [&        R)                  U R                  5      R+                  5       5      nU R                  R-                  5         U R"                  nU H  nU R/                  [        UR0                  UR2                  UR4                  SSUUR6                  UR8                  UR:                  UR<                  UR>                  UR@                  S95        M     Xl        U R/                  U5        g)zfPerform additional processing on a message, prior to sending.

Args:
    event: A message to process.
Nr   )xydelta_xdelta_ybuttonshiftmetactrlscreen_xscreen_ystyle)!
set_senderr   r$   
isinstancer   
MouseEvent_x_y	_screen_x	_screen_y	MouseDownrF   r!   appendr   remove	MouseMover"   listdictfromkeyskeysclearr?   widgetrB   rC   rG   rH   rI   rJ   rK   rL   )r%   r>   offset_xoffset_ybuttons
move_eventrF   s          r'   process_messageDriver.process_messageM   s    	499%%HH!%!3!3Hgv0011JJ("JJJ("J))gv//00~~""))'..900~~'..D4F4F"F""))'..9!1!122"""))5 t}}T-?-?@EEGH""((*!22
%F%%#NN(ll(ll$%$%#)")--!(!(%/%8%8%/%8%8")-- &" %,!'"r*   c                    g)z<Write data to the output device.

Args:
    data: Raw data.
Nr,   )r%   datas     r'   writeDriver.write       r*   c                    g)zFlush any buffered data.Nr,   r-   s    r'   flushDriver.flush   rh   r*   c                    g)zStart application mode.Nr,   r-   s    r'   start_application_modeDriver.start_application_mode   rh   r*   c                    g)zDisable further input.Nr,   r-   s    r'   disable_inputDriver.disable_input   rh   r*   c                    g)z%Stop application mode, restore state.Nr,   r-   s    r'   stop_application_modeDriver.stop_application_mode   rh   r*   c                D    U R                  5         U R                  5         g)zjSuspend application mode.

Used to suspend application mode and allow uninhibited access to the
terminal.
N)rs   closer-   s    r'   suspend_application_modeDriver.suspend_application_mode   s     	""$

r*   c                $    U R                  5         g)zbResume application mode.

Used to resume application mode after it has been previously
suspended.
N)rm   r-   s    r'   resume_application_modeDriver.resume_application_mode   s     	##%r*   c                      \ rS rSrSrSrg)Driver.SignalResume   z?Event sent to the app when a resume signal should be published.r,   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r,   r*   r'   SignalResumer}      s    Mr*   r   c              #  ^   #    U R                   nSU l          Sv   Xl         g! Xl         f = f7f)zA context manager used to tell the driver to not auto-restart.

For drivers that support the application being suspended by the
operating system, this context manager is used to mark a body of
code as one that will manage its own stop and start.
FN)r#   )r%   auto_restarts     r'   no_automatic_restartDriver.no_automatic_restart   s.      ))"	.!-s   -" -*-c                    g)zPerform any final cleanup.Nr,   r-   s    r'   rv   Driver.close   rh   r*   c                .    SSK nUR                  U5        g)a   Open a URL in the default web browser.

Args:
    url: The URL to open.
    new_tab: Whether to open the URL in a new tab.
        This is only relevant when running via the WebDriver,
        and is ignored when called while running through the terminal.
r   N)
webbrowseropen)r%   urlnew_tabr   s       r'   open_urlDriver.open_url   s     	r*   download)open_methodencoding	mime_typenamec                  ^ ^^^^ SUUUUU 4S jjn[        U[        5      (       a  Sn	OSn	[        R                  " XU	4S9n
U
R	                  5         g)a  Save the file `path_or_file` to `save_path`.

If running via web through Textual Web or Textual Serve,
this will initiate a download in the web browser.

Args:
    binary: The binary file to save.
    delivery_key: The unique key that was used to deliver the file.
    save_path: The location to save the file to.
    open_method: *web only* Whether to open the file in the browser or
        to prompt the user to download it. When running via a standard
        (non-web) terminal, this is ignored.
    encoding: *web only* The text encoding to use when saving the file.
        This will be passed to Python's `open()` built-in function.
        When running via web, this will be used to set the charset
        in the `Content-Type` header.
    mime_type: *web only* The MIME type of the file. This will be used to
        set the `Content-Type` header in the HTTP response.
    name: A user-defined name which will be returned in [`DeliveryComplete`][textual.events.DeliveryComplete]
        and [`DeliveryFailed`][textual.events.DeliveryFailed].

c                f  >  [        TUT
=(       d    SS9 nU R                  nUR                  nSn U" U5      nU(       d  TR                  T	TTS9  O
U" U5        M+  S S S 5        U R                  (       d  U R                  5         g g ! , (       d  f       N1= f! [         ae  n[
        R                  " SU 35        SS Kn[
        R                  " [        UR                  5       5      5        TR                  T	UTS9   S nANS nAff = f! U R                  (       d  U R                  5         f f = f)Nzutf-8)r   i   )	save_pathr   zFailed to deliver file: r   )	exceptionr   )r   readrf   _delivery_complete	Exceptionr   error	tracebackstr
format_exc_delivery_failedclosedrv   )binarymodedestination_filer   rf   
chunk_sizere   r   r   delivery_keyr   r   r   r%   s            r'   save_file_thread/Driver.deliver_binary.<locals>.save_file_thread   s   #th.A'%!;;D,22E!*J#J/# 33 ,	 4  "d 0 }}LLN %1   P 		4UG<= 		#i22456%%le$%OP }}LLN %sN   B AB	B 	
BB D B 
D	$AD?D D		D $D0wbw)targetargsN)r   BinaryIO | TextIOr   r   returnNone)rN   r
   	threadingThreadstart)r%   r   r   r   r   r   r   r   r   r   threads   ` `` ` `   r'   deliver_binaryDriver.deliver_binary   sE    D	# 	#: fh''DD!!)9Or*   c           	         U R                   R                  U R                   R                  [        R                  " XUS95        g)zcCalled when a file has been delivered successfully.

Delivers a DeliveryComplete event to the app.
)keypathr   N)r   call_from_threadpost_messager   DeliveryComplete)r%   r   r   r   s       r'   r   Driver._delivery_complete  s3     			""II""##4P	
r*   c           	         U R                   R                  U R                   R                  [        R                  " XUS95        g)zPCalled when a file delivery fails.

Delivers a DeliveryFailed event to the app.
)r   r   r   N)r   r   r   r   DeliveryFailed)r%   r   r   r   s       r'   r   Driver._delivery_failed#  s3     			""II""!!ldS	
r*   )	r   r#   r   r!   r"   r    r   r   r$   )
r&   zApp[Any]r   boolr   r   r   ztuple[int, int] | Noner   r   )r   r   )r>   zmessages.Messager   r   )re   r   r   r   )r   r   )r   zIterator[None])T)r   r   r   r   r   r   )r   r   r   r   r   r   r   zLiteral['browser', 'download']r   
str | Noner   r   r   r   r   r   )r   r   r   zPath | Noner   r   r   r   )r   r   r   BaseExceptionr   r   r   r   ) r   r   r   r   r   r(   propertyr.   r2   r5   r8   r?   rb   r   rf   rj   rm   rp   rs   rw   rz   r   Eventr   r   r   rv   r   r   r   r   r   r,   r*   r'   r   r      s   # '+:: 	:
 : %: 
:6        
7#r  ' & & % % 4 4&Nv|| N . .)& 7A# $E!E 	E
 E 4E E E E 
EN



,7

?I

	





,9

AK

	

r*   r   )
__future__r   r   r   abcr   r   
contextlibr   pathlibr   typingr   r	   r
   r   r   r   textualr   r   r   textual.eventsr   textual.appr   r   r,   r*   r'   <module>r      s:    "   # %  J J ) ) "\
S \
r*   