
    ^h\                        S SK Jr  S SKr\R                  S:X  d   eS SKJr  S SKJr  S SKJ	r	  S SK
Jr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JrJr  S/r " S S\\5      rg)    )annotationsNwin32)contextmanager)windll)HANDLE)CallableContextManagerIterator)create_win32_event   )KeyPressDummyContext   )	PipeInput)Vt100Parser)_Win32InputBaseattach_win32_inputdetach_win32_inputWin32PipeInputc                     ^  \ rS rSrSrSrSU 4S jjr\\SS j5       5       r	\
SS j5       rSS jr\
SS j5       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S jrSS jrSS jrSS jrSrU =r$ ) r      a  
This is an input pipe that works on Windows.
Text or bytes can be feed into the pipe, and key strokes can be read from
the pipe. This is useful if we want to send the input programmatically into
the application. Mostly useful for unit testing.

Notice that even though it's Windows, we use vt100 escape sequences over
the pipe.

Usage::

    input = Win32PipeInput()
    input.send_text('inputdata')
r   c                   >^  [         TT ]  5         [        5       T l        ST l        / T l        [        U 4S j5      T l        T R                  =R                  S-  sl	        T R                  R                  T l	        g )NFc                :   > TR                   R                  U 5      $ N)_bufferappend)keyselfs    Y/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/input/win32_pipe.py<lambda>)Win32PipeInput.__init__.<locals>.<lambda>6   s    DLL4G4G4L    r   )
super__init__r   _event_closedr   r   vt100_parser	__class___id)r   r&   r)   s   ` r    r%   Win32PipeInput.__init__)   s`     )* (*'(LM 	a>>%%r#   c              #     #    [        5       n [        US9v   [        R                  R	                  U5        g ! [        R                  R	                  U5        f = f7f)Nr&   )r   r   r   kernel32CloseHandle)clsevents     r    createWin32PipeInput.create<   sC      #$	/ ..OO''.FOO''.s   A9  A!AAc                    U R                   $ r   )r'   r   s    r    closedWin32PipeInput.closedE   s    ||r#   c                    [         e)z5
The windows pipe doesn't depend on the file handle.
)NotImplementedErrorr5   s    r    filenoWin32PipeInput.filenoI   s
     "!r#   c                    U R                   $ )z<The handle used for registering this pipe in the event loop.r-   r5   s    r    handleWin32PipeInput.handleO   s     {{r#   c                    [        X5      $ )zR
Return a context manager that makes this input active in the current
event loop.
)r   )r   input_ready_callbacks     r    attachWin32PipeInput.attachT   s    
 "$==r#   c                    [        U 5      $ )zc
Return a context manager that makes sure that this input is not active
in the current event loop.
)r   r5   s    r    detachWin32PipeInput.detach[   s    
 "$''r#   c                    U R                   n/ U l         U R                  (       d)  [        R                  R	                  U R
                  5        U$ )zRead list of KeyPress.)r   r'   r   r.   
ResetEventr&   r   results     r    	read_keysWin32PipeInput.read_keysb   s8      ||OO&&t{{3r#   c                `    U R                   R                  5         U R                  n/ U l        U$ )zK
Flush pending keys and return them.
(Used for flushing the 'escape' key.)
)r(   flushr   rH   s     r    
flush_keysWin32PipeInput.flush_keysp   s-     	! r#   c                F    U R                  UR                  SS5      5        g)zSend bytes to the input.zutf-8ignoreN)	send_textdecode)r   datas     r    
send_bytesWin32PipeInput.send_bytes~   s    t{{7H56r#   c                    U R                   (       a  [        S5      eU R                  R                  U5        [        R
                  R                  U R                  5        g)zSend text to the input.z$Attempt to write into a closed pipe.N)r'   
ValueErrorr(   feedr   r.   SetEventr&   )r   texts     r    rR   Win32PipeInput.send_text   sC    <<CDD 	t$ 	  -r#   c                    [        5       $ r   r   r5   s    r    raw_modeWin32PipeInput.raw_mode   
    ~r#   c                    [        5       $ r   r   r5   s    r    cooked_modeWin32PipeInput.cooked_mode   r`   r#   c                d    SU l         [        R                  R                  U R                  5        g)zClose write-end of the pipe.TN)r'   r   r.   rZ   r&   r5   s    r    closeWin32PipeInput.close   s      -r#   c                     SU R                    3$ )z0
This needs to be unique for every `PipeInput`.
zpipe-input-)r*   r5   s    r    typeahead_hashWin32PipeInput.typeahead_hash   s     TXXJ''r#   )r   r'   r&   r*   r(   )r&   r   returnNone)rj   zIterator[Win32PipeInput])rj   bool)rj   int)rj   r   )r@   zCallable[[], None]rj   ContextManager[None])rj   rn   )rj   zlist[KeyPress])rT   bytesrj   rk   )r[   strrj   rk   )rj   rk   )rj   rp   )__name__
__module____qualname____firstlineno____doc__r*   r%   classmethodr   r2   propertyr6   r:   r=   rA   rD   rJ   rN   rU   rR   r^   rb   re   rh   __static_attributes____classcell__)r)   s   @r    r   r      s     C&& /  /  "  >(7	..
( (r#   )
__future__r   sysplatform
contextlibr   ctypesr   ctypes.wintypesr   typingr   r	   r
   prompt_toolkit.eventloop.win32r   key_bindingr   utilsr   baser   r(   r   r   r   r   r   __all__r    r#   r    <module>r      sY    " 

||w  %  " 5 5 = "    % J J
E(_i E(r#   