
    ^h)                    h   % S SK Jr  S SKr\R                  S:w  d   eS SKrS SKrS SKrS SKrS SKJ	r	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SKJr  / SQr " S S\5      r0 rS\S'   \R8                        SS j5       r\R8                  SS j5       r " S S5      r " S S\5      r g)    )annotationsNwin32)AbstractEventLoopget_running_loop)CallableContextManager	GeneratorTextIO   )KeyPress   )Input)PosixStdinReader)Vt100Parser)
Vt100Inputraw_modecooked_modec                      \ rS rSr% Sr\" 5       rS\S'   SS jrSS jr	SS jr
SS j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rg)r      zn
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                  ^   UR                  5         UR                  5       nUR                  5       nU(       dt  U[        R                  ;  a`  Sn[        R                  R                  XT-  5        [        R                  R                  5         [        R                  R                  U5        UT l        UR                  5       T l        / T l        [        T R                  UR                   S9T l        [%        U 4S j5      T l        g ! [        R                   aG  nS[        R                  ;   a  [        R                  " S5      Ue[        R                  " S5      UeS nAff = f)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                :   > TR                   R                  U 5      $ N)_bufferappend)	key_pressselfs    T/home/james-whalen/.local/lib/python3.13/site-packages/prompt_toolkit/input/vt100.py<lambda>%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__Vt100Input.__init__$   s   		QLLN \\^"J$B$BB?CJJSX&JJ**..r2 
 ||~'),T\\ENNS'<
? && 	Q+--R --.HIqP	Qs   D	 	E$AEE$c                    [        X5      $ )zR
Return a context manager that makes this input active in the current
event loop.
)_attached_input)r   input_ready_callbacks     r   attachVt100Input.attachM   s    
 t::r"   c                    [        U 5      $ )zc
Return a context manager that makes sure that this input is not active
in the current event loop.
)_detached_inputr   s    r   detachVt100Input.detachT   s    
 t$$r"   c                    U R                   R                  5       nU R                  R                  U5        U R                  n/ U l        U$ )zRead list of KeyPress.)r/   readr0   feedr   )r   dataresults      r   	read_keysVt100Input.read_keys[   sE       %%' 	t$ 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.)
)r0   r+   r   )r   rD   s     r   
flush_keysVt100Input.flush_keysh   s-     	! r"   c                .    U R                   R                  $ r   )r/   closedr=   s    r   rK   Vt100Input.closedv   s      '''r"   c                H    [        U R                  R                  5       5      $ r   )r   r-   r#   r=   s    r   r   Vt100Input.raw_modez   s    

))+,,r"   c                H    [        U R                  R                  5       5      $ r   )r   r-   r#   r=   s    r   r   Vt100Input.cooked_mode}   s    4::,,.//r"   c                6    U R                   R                  5       $ r   )r-   r#   r=   s    r   r#   Vt100Input.fileno   s    zz  ""r"   c                     SU R                    3$ )Nzfd-)r.   r=   s    r   typeahead_hashVt100Input.typeahead_hash   s    T\\N##r"   )r   r.   r-   r/   r0   N)r-   r
   returnNone)r8   Callable[[], None]rV   ContextManager[None])rV   rY   )rV   zlist[KeyPress])rV   bool)rV   int)rV   str)__name__
__module____qualname____firstlineno____doc__setr   __annotations__r4   r9   r>   rE   rH   propertyrK   r   r   r#   rT   __static_attributes__ r"   r   r   r      sX     %(E)'
R;% ( (-0#$r"   r   z>dict[tuple[AbstractEventLoop, int], Callable[[], None] | None]_current_callbacksc              #     ^ ^^^#    [        5       mT R                  5       m[        R                  TT45      nSUUU U4S jjn TR	                  TU5        T[        TT4'    Sv   TR                  T5        U(       a  TR	                  TU5        U[        TT4'   g[        TT4	 g! [
         a    [        ef = f! TR                  T5        U(       a  TR	                  TU5        U[        TT4'   f [        TT4	 f = f7f)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                 X   > TR                   (       a  TR                  T5        T " 5         g)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)rK   remove_reader)callbackr2   inputloops   r   callback_wrapper)_attached_input.<locals>.callback_wrapper   s     <<r"
r"   NrV   rW   )r   r#   rg   get
add_readerPermissionErrorEOFErrorrj   )rl   rk   previousrn   r2   rm   s   ``  @@r   r7   r7      s      D	B!%%tRj1H 
,- $,tRx 	-2OOB)+3tRx("48,+    	2OOB)+3tRx("48,s7   =C>B& C>"B: &A C>&B77C>:AC;;C>c              #  P  #    [        5       nU R                  5       n[        R                  X45      nU(       a  UR	                  U5        S [        X4'    S v   U(       a  UR                  X#5        U[        X4'   g g ! U(       a  UR                  X#5        U[        X4'   f f = f7fr   )r   r#   rg   rq   rj   rr   )rl   rm   r2   ru   s       r   r<   r<      s     D	B!%%tj1H2'+48$4OOB)+3tx( 8OOB)+3tx( s   AB&A> $B&>%B##B&c                  ^    \ rS rSrSrS
S jrSS jr\SS j5       r\SS j5       r	SS jr
Srg	)r      z
::

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

We ignore errors when executing `tcgetattr` fails.
c                    Xl         U    [        R                  " U5      U l        g ! [        R                   a
    S U l         g f = fr   )r#   termios	tcgetattrattrs_beforeerror)r   r#   s     r   r4   raw_mode.__init__   s=    	% ' 1 1& 9D}} 	% $D	%s   & AAc                    [         R                  " U R                  5      nU R                  U[        R
                     5      U[        R
                  '   U R                  U[        R                     5      U[        R                  '   SU[        R                     [         R                  '   [         R                  " U R                  [         R                  U5        g ! [         R                   a     g f = f)Nr   )rz   r{   r#   _patch_lflagttyLFLAG_patch_iflagIFLAGCCVMIN	tcsetattrTCSANOWr}   )r   newattrs     r   	__enter__raw_mode.__enter__   s    	E''4G "&!2!273993E!FGCII!%!2!273993E!FGCII -.GCFFOGLL)dkk7??GD }} 		s    C C43C4c                    U[         R                  [         R                  -  [         R                  -  [         R                  -  ) -  $ r   rz   ECHOICANONIEXTENISIGclsattrss     r   r   raw_mode._patch_lflag  s/    6G',,VWWWr"   c                    U[         R                  [         R                  -  [         R                  -  [         R                  -  [         R
                  -  ) -  $ r   )rz   IXONIXOFFICRNLINLCRIGNCRr   s     r   r   raw_mode._patch_iflag  sS     LLmm MM	
 mm mm	
 
 	
r"   c                    U R                   b<   [        R                  " U R                  [        R                  U R                   5        g g ! [        R
                   a     g f = fr   )r|   rz   r   r#   r   r}   )r   as     r   __exit__raw_mode.__exit__  sP    (!!$++w@Q@QR ) == s   :A A"!A")r|   r#   N)r#   r[   rV   rW   rp   r   r[   rV   r[   )r   objectrV   rW   )r]   r^   r_   r`   ra   r4   r   classmethodr   r   r   re   rf   r"   r   r   r      sA    .%E& X X 
 
r"   r   c                  @    \ rS rSrSr\SS j5       r\SS j5       rSrg)r   i"  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                    U[         R                  [         R                  -  [         R                  -  [         R                  -  -  $ r   r   r   s     r   r   cooked_mode._patch_lflag+  s,    w~~5FUVVr"   c                (    U[         R                  -  $ r   )rz   r   r   s     r   r   cooked_mode._patch_iflag/  s     w}}$$r"   rf   Nr   )	r]   r^   r_   r`   ra   r   r   r   re   rf   r"   r   r   r   "  s1     W W % %r"   r   )rl   r   rk   rX   rV   Generator[None, None, None])rl   r   rV   r   )!
__future__r   r&   platform
contextlibr$   rz   r   asyncior   r   typingr   r   r	   r
   key_bindingr   baser   posix_utilsr   r0   r   __all__r   rg   rc   contextmanagerr7   r<   r   r   rf   r"   r   <module>r      s    " 

||w   	  
 7 > > "  ) %j$ j$^    
 .-.-!3.- .- .-b 4 4"L Ld%( %r"   