
    f)                    b   U d dl mZ d dlZej                  dk7  sJ d dlZd dlZd dlZd dlZd dlm	Z	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dlmZ g dZ G d de      Zi Zded<   ej8                  	 	 	 	 	 	 dd       Zej8                  dd       Z G d d      Z G d de      Z y)    )annotationsNwin32)AbstractEventLoopget_running_loop)CallableContextManager	GeneratorTextIO   )KeyPress   )Input)PosixStdinReader)Vt100Parser)
Vt100Inputraw_modecooked_modec                      e Zd ZU dZ e       Zded<   ddZddZddZ	ddZ
ddZedd	       Zdd
ZddZddZddZy)r   zz
    Vt100 input for Posix systems.
    (This uses a posix file descriptor that can be registered in the event loop.)
    zset[int]_fds_not_a_terminalc                    	 |j                          |j                         }|j                         }|ss|t        j                  vrad}t        j                  j                  ||z         t        j                  j                          t        j                  j                  |       | _        |j                          _        g  _        t         j                  |j                          _        t%         fd       _        y # t        j                  $ rC}dt        j                  v rt        j                  d      |t        j                  d      |d }~ww xY w)Nzidlelib.runz<Stdin is not a terminal. Running from Idle is not supported.zStdin is not a terminal.z*Warning: Input is not a terminal (fd=%r).
)encodingc                :    j                   j                  |       S N)_bufferappend)	key_pressselfs    U/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/input/vt100.py<lambda>z%Vt100Input.__init__.<locals>.<lambda>J   s    dll11)<     )filenoioUnsupportedOperationsysmodulesisattyr   r   stderrwriteflushaddstdin_filenor   r   r   stdin_readerr   vt100_parser)r   r+   er&   fdmsgs   `     r   __init__zVt100Input.__init__$   s   		QLLN \\^"J$B$BB?CJJS2X&JJ**..r2 
 ||~'),T\\ENNS'<
? && 	Q+--R --.HIqP	Qs   D E>EEc                    t        | |      S )zj
        Return a context manager that makes this input active in the current
        event loop.
        )_attached_input)r   input_ready_callbacks     r   attachzVt100Input.attachM   s    
 t%9::r    c                    t        |       S )z{
        Return a context manager that makes sure that this input is not active
        in the current event loop.
        )_detached_inputr   s    r   detachzVt100Input.detachT   s    
 t$$r    c                    | j                   j                         }| j                  j                  |       | j                  }g | _        |S )zRead list of KeyPress.)r-   readr.   feedr   )r   dataresults      r   	read_keyszVt100Input.read_keys[   sE       %%' 	t$ r    c                `    | j                   j                          | j                  }g | _        |S )zc
        Flush pending keys and return them.
        (Used for flushing the 'escape' key.)
        )r.   r)   r   )r   r?   s     r   
flush_keyszVt100Input.flush_keysh   s-     	! r    c                .    | j                   j                  S r   )r-   closedr9   s    r   rD   zVt100Input.closedv   s      '''r    c                H    t        | j                  j                               S r   )r   r+   r!   r9   s    r   r   zVt100Input.raw_modez   s    

))+,,r    c                H    t        | j                  j                               S r   )r   r+   r!   r9   s    r   r   zVt100Input.cooked_mode}   s    4::,,.//r    c                6    | j                   j                         S r   )r+   r!   r9   s    r   r!   zVt100Input.fileno   s    zz  ""r    c                     d| j                    S )Nzfd-)r,   r9   s    r   typeahead_hashzVt100Input.typeahead_hash   s    T\\N##r    N)r+   r
   returnNone)r5   Callable[[], None]rJ   ContextManager[None])rJ   rM   )rJ   zlist[KeyPress])rJ   bool)rJ   int)rJ   str)__name__
__module____qualname____doc__setr   __annotations__r2   r6   r:   r@   rB   propertyrD   r   r   r!   rI    r    r   r   r      sX     %(E)'
R;% ( (-0#$r    r   z>dict[tuple[AbstractEventLoop, int], Callable[[], None] | None]_current_callbacksc              #     K   t                j                         t        j                  f      }d fd}	 j	                  |       t        f<   	 d j                         |rj	                  |       |t        f<   yt        f= y# t
        $ r t        w xY w# j                         |rj	                  |       |t        f<   w t        f= w xY ww)z
    Context manager that makes this input active in the current event loop.

    :param input: :class:`~prompt_toolkit.input.Input` object.
    :param callback: Called when the input is ready to read.
    c                 N    j                   rj                                   y)a:  Wrapper around the callback that already removes the reader when
        the input is closed. Otherwise, we keep continuously calling this
        callback, until we leave the context manager (which can happen a bit
        later). This fixes issues when piping /dev/null into a prompt_toolkit
        application.N)rD   remove_reader)callbackr0   inputloops   r   callback_wrapperz)_attached_input.<locals>.callback_wrapper   s     <<r"
r    NrJ   rK   )r   r!   rY   get
add_readerPermissionErrorEOFErrorr\   )r^   r]   previousr`   r0   r_   s   ``  @@r   r4   r4      s      D	B!%%tRj1H 
,- $,tRx 	-2OOB)+3tRx("48,+    	2OOB)+3tRx("48,s5   ;C1B C1 B2 $;C1B//C12<C..C1c              #  >  K   t               }| j                         }t        j                  ||f      }|r|j	                  |       d t        ||f<   	 d  |r|j                  ||       |t        ||f<   y y # |r|j                  ||       |t        ||f<   w w xY wwr   )r   r!   rY   rb   r\   rc   )r^   r_   r0   rf   s       r   r8   r8      s     D	B!%%tRj1H2'+48$4OOB)+3tRx( 8OOB)+3tRx( s   ABA8 !B8"BBc                  L    e Zd ZdZddZd	dZed
d       Zed
d       ZddZ	y)r   z
    ::

        with raw_mode(stdin):
            ''' the pseudo-terminal stdin is now used in raw mode '''

    We ignore errors when executing `tcgetattr` fails.
    c                    || _         |  	 t        j                  |      | _        y # t        j                  $ r
 d | _        Y y w xY wr   )r!   termios	tcgetattrattrs_beforeerror)r   r!   s     r   r2   zraw_mode.__init__   s?    	% ' 1 1& 9D}} 	% $D	%s   & AAc                   	 t        j                  | j                        }| j                  |t        j
                           |t        j
                  <   | j                  |t        j                           |t        j                  <   d|t        j                     t         j                  <   t        j                  | j                  t         j                  |       y # t         j                  $ r Y y w xY w)Nr   )rj   rk   r!   _patch_lflagttyLFLAG_patch_iflagIFLAGCCVMIN	tcsetattrTCSANOWrm   )r   newattrs     r   	__enter__zraw_mode.__enter__   s    	E''4G "&!2!273993E!FGCII!%!2!273993E!FGCII -.GCFFOGLL)dkk7??GD }} 		s   C C10C1c                    |t         j                  t         j                  z  t         j                  z  t         j                  z   z  S r   rj   ECHOICANONIEXTENISIGclsattrss     r   ro   zraw_mode._patch_lflag  s/    6G',,VWWWr    c                    |t         j                  t         j                  z  t         j                  z  t         j                  z  t         j
                  z   z  S r   )rj   IXONIXOFFICRNLINLCRIGNCRr   s     r   rr   zraw_mode._patch_iflag  sS     LLmm MM	
 mm mm	
 
 	
r    c                    | j                   ;	 t        j                  | j                  t        j                  | j                          y y # t        j
                  $ r Y y w xY wr   )rl   rj   rv   r!   rw   rm   )r   as     r   __exit__zraw_mode.__exit__  sP    (!!$++w@Q@QR ) == s   9A	 	AAN)r!   rO   rJ   rK   ra   r   rO   rJ   rO   )r   objectrJ   rK   )
rQ   rR   rS   rT   r2   ry   classmethodro   rr   r   rX   r    r   r   r      sA    .%E& X X 
 
r    r   c                  4    e Zd ZdZedd       Zedd       Zy)r   z
    The opposite of ``raw_mode``, used when we need cooked mode inside a
    `raw_mode` block.  Used in `Application.run_in_terminal`.::

        with cooked_mode(stdin):
            ''' the pseudo-terminal stdin is now used in cooked mode. '''
    c                    |t         j                  t         j                  z  t         j                  z  t         j                  z  z  S r   r{   r   s     r   ro   zcooked_mode._patch_lflag+  s,    w~~5FUVVr    c                (    |t         j                  z  S r   )rj   r   r   s     r   rr   zcooked_mode._patch_iflag/  s     w}}$$r    Nr   )rQ   rR   rS   rT   r   ro   rr   rX   r    r   r   r   "  s1     W W % %r    r   )r^   r   r]   rL   rJ   Generator[None, None, None])r^   r   rJ   r   )!
__future__r   r$   platform
contextlibr"   rj   rp   asyncior   r   typingr   r   r	   r
   key_bindingr   baser   posix_utilsr   r.   r   __all__r   rY   rV   contextmanagerr4   r8   r   r   rX   r    r   <module>r      s    " 

||w   	  
 7 > > "  ) %j$ j$^    
 .-.-!3.- .- .-b 4 4"L Ld%( %r    