+
    j,iD                       R t ^ RIHt ^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^RIHtHt ]
'       d   ^ RIHt ^ RIHt . ROt ! R R4      t ]! RRR7      t  ! R R4      t! ! R R4      t"R# )a%  
An :class:`~.KeyProcessor` receives callbacks for the keystrokes parsed from
the input in the :class:`~prompt_toolkit.inputstream.InputStream` instance.

The `KeyProcessor` will according to the implemented keybindings call the
correct callbacks when new key presses are feed through `feed`.
)annotationsN)Tasksleep)deque)TYPE_CHECKINGAny	Generator)get_app)EditingMode)vi_navigation_mode)Keys)Event)BindingKeyBindingsBase)Application)BufferKeyProcessorKeyPressKeyPressEventc                  B    ] tR t^$tRtR
R R lltR R ltR R ltR	tR# )r   z
:param key: A `Keys` instance or text (one character).
:param data: The received string on stdin. (Often vt100 escape codes.)
Nc               $    V ^8  d   QhRRRRRR/# )   keyz
Keys | strdata
str | NonereturnNone )formats   "J/usr/lib/python3/dist-packages/prompt_toolkit/key_binding/key_processor.py__annotate__KeyPress.__annotate__*   s!     
 
J 
j 
D 
    c                	    \        V\        4      '       g   \        V4      ^8X  g   Q hVf&   \        V\        4      '       d   VP                  pMTpWn        W n        R# )   N)
isinstancer   lenvaluer   r   )selfr   r   s   &&&r   __init__KeyPress.__init__*   sI    #t$$CA55<#t$$yy	r"   c                   V ^8  d   QhRR/# r   r   strr   )r   s   "r   r    r!   6   s     R R# Rr"   c                	l    V P                   P                   R V P                  : RV P                  : R2# )z(key=z, data=))	__class____name__r   r   r(   s   &r   __repr__KeyPress.__repr__6   s.    ..))*%|7499-qQQr"   c                    V ^8  d   QhRRRR/# )r   otherobjectr   boolr   )r   s   "r   r    r!   9   s     A AF At Ar"   c                	    \        V\        4      '       g   R # V P                  VP                  8H  ;'       d    V P                  VP                  8H  # F)r%   r   r   r   )r(   r6   s   &&r   __eq__KeyPress.__eq__9   s:    %**xx599$@@ejj)@@r"   )r   r   N)	r1   
__module____qualname____firstlineno____doc__r)   r3   r;   __static_attributes__r   r"   r   r   r   $   s    

RA Ar"   ?_Flush)r   c                      ] tR t^FtRtR R ltR R ltR R ltR R	 ltR
 R lt	R R R llt
R R R lltR R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )!r   a  
Statemachine that receives :class:`KeyPress` instances and according to the
key bindings in the given :class:`KeyBindings`, calls the matching handlers.

::

    p = KeyProcessor(key_bindings)

    # Send keys into the processor.
    p.feed(KeyPress(Keys.ControlX, ''))
    p.feed(KeyPress(Keys.ControlC, '')

    # Process all the keys in the queue.
    p.process_keys()

    # Now the ControlX-ControlC callback will be called if this sequence is
    # registered in the key bindings.

:param key_bindings: `KeyBindingsBase` instance.
c                    V ^8  d   QhRRRR/# )r   key_bindingsr   r   r   r   )r   s   "r   r    KeyProcessor.__annotate__\   s      _  r"   c                	    Wn         \        V 4      V n        \        V 4      V n        R V n        V P                  4        R # r=   )	_bindingsr   before_key_pressafter_key_press_flush_wait_taskreset)r(   rG   s   &&r   r)   KeyProcessor.__init__\   s0    % %d$T{37

r"   c                   V ^8  d   QhRR/# r   r   r   r   )r   s   "r   r    rH   f   s     + +t +r"   c                	    . V n         R V n        \        4       V n        . V n        R V n        V P                  4       V n        V P                  P                  R 4       R # r=   )	_previous_key_sequence_previous_handlerr   input_queue
key_bufferarg_process_process_coroutinesendr2   s   &r   rN   KeyProcessor.resetf   sT    68#15 -2G +-  $ #'--/$$T*r"   c                    V ^8  d   QhRRRR/# )r   key_presseslist[KeyPress]r   zlist[Binding]r   )r   s   "r   r    rH   y   s     U U U= Ur"   c                    \         ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      pV P                  P                  V4       Uu. uF  q3P                  4       '       g   K  VNK  	  up# u upi )z_
For a list of :class:`KeyPress` instances. Give the matching handlers
that would handle this.
c              3  8   "   T F  qP                   x  K  	  R # 5ir=   r   .0ks   & r   	<genexpr>,KeyProcessor._get_matches.<locals>.<genexpr>~        0KqUUK   )tuplerJ   get_bindings_for_keysfilter)r(   r]   keysbs   &&  r   _get_matchesKeyProcessor._get_matchesy   sU    
 u0K0uu0K00  >>??ETEaETTTs   
A/&A/c                    V ^8  d   QhRRRR/# )r   r]   r^   r   r8   r   )r   s   "r   r    rH      s     ) )n ) )r"   c                2   \         ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      pV P                  P                  V4       Uu0 uF  q3P                  kK  	  pp\        ;QJ d    R V 4       F  '       g   K   R# 	  R# ! R V 4       4      # u upi )zx
For a list of :class:`KeyPress` instances. Return True if there is any
handler that is bound to a suffix of this keys.
c              3  8   "   T F  qP                   x  K  	  R # 5ir=   ra   rb   s   & r   re   :KeyProcessor._is_prefix_of_longer_match.<locals>.<genexpr>   rg   rh   c              3  .   "   T F  q! 4       x  K  	  R # 5ir=   r   )rc   fs   & r   re   rs      s     (1133s   TF)ri   rJ   get_bindings_starting_with_keysrk   any)r(   r]   rl   rm   filterss   &&   r   _is_prefix_of_longer_match'KeyProcessor._is_prefix_of_longer_match   s    
 u0K0uu0K00 #nnLLTR
RHHR 	 

 s((ss(s(s((((
s   
Bc                   V ^8  d   QhRR/# )r   r   zGenerator[None, KeyPress, None]r   )r   s   "r   r    rH      s     9' 9'9 9'r"   c              #    "   V P                   pRp RpV'       d   RpM"Rx pV\        J d   RpMVP                  V4       V'       g   K:  V P                  V4      pV'       d   RpMV P	                  V4      pV Uu. uF  qwP                  4       '       g   K  VNK  	  ppV'       d   TpRpV'       g/   V'       d'   V P                  VR,          VR,          R7       VR K  V'       d   K  V'       d   K  RpRp	\        \        V4      ^ R4       FE  p
V P                  VRV
 4      pV'       g   K!  V P                  VR,          VRV
 R7       VRV
1 Rp	 M	  V	'       d   EKS  VR EKY  u upi 5i)z
Coroutine implementing the key match algorithm. Key strokes are sent
into this generator, and it calls the appropriate handlers.
FTN:NNN)key_sequence:Nr$   N)	rV   rD   appendrn   ry   eager_call_handlerranger&   )r(   bufferretryflushr   matchesis_prefix_of_longer_matchmeager_matchesfoundis   &          r   rX   KeyProcessor._process   sY    
 E&= EMM#& v++F305-040O0OPV0W- -4 AGqwwyG A +G05- 1W&&wr{&Kq	 3277 E!E #3v;26"&"3"3F2AJ"?"7 ..wr{PRQR.T &rr
$(E! 7 !5"2J5 !BsL   E/*E/E/$E/<E*E*E/4E/<+E/,E/66E/1-E/$E/c               $    V ^8  d   QhRRRRRR/# )r   	key_pressr   firstr8   r   r   r   )r   s   "r   r    rH      s!     
/ 
/h 
/t 
/ 
/r"   c                    V'       d   V P                   P                  V4       R# V P                   P                  V4       R# )z
Add a new :class:`KeyPress` to the input queue.
(Don't forget to call `process_keys` in order to process the queue.)

:param first: If true, insert before everything else.
N)rU   
appendleftr   )r(   r   r   s   &&&r   feedKeyProcessor.feed   s/     ''	2##I.r"   c               $    V ^8  d   QhRRRRRR/# )r   r]   r^   r   r8   r   r   r   )r   s   "r   r    rH      s"     1 1 1 1QU 1r"   c                    V'       d'   V P                   P                  \        V4      4       R# V P                   P                  V4       R# )z7
:param first: If true, insert before everything else.
N)rU   
extendleftreversedextend)r(   r]   r   s   &&&r   feed_multipleKeyProcessor.feed_multiple   s4     ''(=>##K0r"   c                   V ^8  d   QhRR/# rQ   r   )r   s   "r   r    rH      s     9" 9"d 9"r"   c                <  a a \        4       oR VV 3R llpR VV 3R llpRpV! 4       '       d   V! 4       pV\        J pVP                  \        P                  8H  pV'       g#   V'       g   S P
                  P                  4         S P                  P                  V4       T'       d   K  T'       d   K  S P                  P                  4        K  V'       g   S P                  4        R# R#   \         d#    S P                  4        S P                  4        h i ; i)z
Process all the keys in the `input_queue`.
(To be called after `feed`.)

Note: because of the `feed`/`process_keys` separation, it is
      possible to call `feed` from inside a key binding.
      This function keeps looping until the queue is empty.
c                   V ^8  d   QhRR/# r   r   r8   r   )r   s   "r   r    /KeyProcessor.process_keys.<locals>.__annotate__   s     		. 		.4 		.r"   c                    < S P                   '       dI   \        ;QJ d&    R  SP                   4       F  '       g   K   R# 	  R# ! R  SP                   4       4      # \        SP                  4      # )c              3  f   "   T F'  qP                   \        P                  8X  g   K#  Vx  K)  	  R # 5ir=   )r   r   CPRResponserb   s   & r   re   ?KeyProcessor.process_keys.<locals>.not_empty.<locals>.<genexpr>   s#     T&6%%4CSCS:S11&6s    1
1TF)is_donerw   rU   r8   )appr(   s   r   	not_empty,KeyProcessor.process_keys.<locals>.not_empty   sV     {{{ sTd&6&6TssTsTsTd&6&6TTTD,,--r"   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r    r      s     	2 	2( 	2r"   c                 &  < SP                   '       da   SP                   U u. uF%  q P                  \        P                  8X  g   K#  V NK'  	  up ^ ,          pSP                  P                  V4       V# SP                  P                  4       # u up i )    )r   rU   r   r   r   removepopleft)rd   cprr   r(   s     r   get_next+KeyProcessor.process_keys.<locals>.get_next   ss    {{{"&"2"2P"2Qeet?O?O6Oqq"2PQRS  '',
''//11	 Qs    BBFN)r	   rD   r   r   r   rK   firerY   rZ   	ExceptionrN   empty_queuerL   _start_timeout)r(   r   r   is_flushr   is_cprr   s   f     @r   process_keysKeyProcessor.process_keys   s     i		. 		.	2 	2 kk 
I F*H]]d&6&66FF%%**,'',,Y7 8FF$$))+ !    

  "s   C. .-Dc                   V ^8  d   QhRR/# )r   r   r^   r   )r   s   "r   r    rH      s     	 	^ 	r"   c                    \        V P                  4      pV P                  P                  4        V Uu. uF%  q"P                  \        P
                  8w  g   K#  VNK'  	  ppV# u upi )z6
Empty the input queue. Return the unprocessed input.
)listrU   clearr   r   r   )r(   r]   rd   s   &  r   r   KeyProcessor.empty_queue   sY     4++,  #.K+Q$:J:J1Jqq+K Ls    A#A#c               $    V ^8  d   QhRRRRRR/# )r   handlerr   r}   r^   r   r   r   )r   s   "r   r    rH   +  s!     1= 1=W 1=N 1=t 1=r"   c                	6   \        4       pVP                  P                  p\        VP                  P
                  4      pVP                  P                  pV P                  pR V n        \        \        P                  ! V 4      VVV P                  WP                  8H  R7      pVP                  V4      '       d%   VP                  P                  P!                  4        ^ RIHp	  VP'                  V4       V P)                  V4       V'       d   V P/                  V4       W n        Wn        VP1                  4       '       d   VP                  P                  '       d4   V'       d,   VP                  P2                  p
V
e   V
P5                  V4       VP                  P
                  '       dC   V'       d9   V F0  pVP                  ;P2                  VP6                  ,          un        K2  	  R # R # R # R #   T	 d    TP*                  P-                  4         ELi ; i)N)rW   r}   previous_key_sequence	is_repeat)EditReadOnlyBuffer)r	   emacs_stateis_recordingr8   vi_staterecording_registertemporary_navigation_moderW   r   weakrefrefrS   rT   save_beforer   current_buffersave_to_undo_stackprompt_toolkit.bufferr   call_fix_vi_cursor_positionoutputbell_leave_vi_temp_navigation_moderecord_in_macrocurrent_recordingr   r   )r(   r   r}   r   was_recording_emacswas_recording_viwas_temporary_navigation_moderW   eventr   	recordingrd   s   &&&         r   r   KeyProcessor._call_handler+  s   i!oo:: ? ?@(+(N(N%hhKK%"&"="="8"88
 u%%II$$779 	=	LL((/ )//6&2#!( ""$$+++0COO==	($$\2||...3C%ALL22aff<2 & 4D. % " 	 JJOO	s   %"G3 3!HHc                    V ^8  d   QhRRRR/# r   r   r   r   r   r   )r   s   "r   r    rH   ^  s     5 5] 5t 5r"   c                8   VP                   pVP                  pVP                  p\        4       '       df   VP                  P
                  '       dH   \        VP                  P                  4      ^ 8  d"   V;P                  ^,          un        WCn        R# R# R# R# )z
After every command, make sure that if we are in Vi navigation mode, we
never put the cursor after the last character of a line. (Unless it's
an empty line.)
N)	r   r   preferred_columnr   documentis_cursor_at_the_end_of_liner&   current_linecursor_position)r(   r   r   buffr   s   &&   r   r   $KeyProcessor._fix_vi_cursor_position^  s~     ii!!00   :::DMM../!3  A%  %5! 4 ; !r"   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r    rH   s  s     
? 
?M 
?d 
?r"   c                    VP                   pVP                  \        P                  8X  d>   VP                  P
                  f$   V P                  f   RVP                  n        R# R# R# R# )zn
If we're in Vi temporary navigation (normal) mode, return to
insert/replace mode after executing one action.
NF)r   editing_moder
   VIr   operator_funcrW   r   )r(   r   r   s   && r   r   +KeyProcessor._leave_vi_temp_navigation_modes  sR    
 ii{~~-||))1dhh6F9>6 7G1 .r"   c                   V ^8  d   QhRR/# rQ   r   )r   s   "r   r    rH     s     C C Cr"   c                   a aa \        4       pVP                  oSf   R# R VV V3R llpR V 3R lloS P                  '       d   S P                  P                  4        VP	                  V! 4       4      S n        R# )z
Start auto flush timeout. Similar to Vim's `timeoutlen` option.

Start a background coroutine with a timer. When this timeout expires
and no key was pressed in the meantime, we flush all data in the queue
and call the appropriate key binding handlers.
Nc                   V ^8  d   QhRR/# rQ   r   )r   s   "r   r    1KeyProcessor._start_timeout.<locals>.__annotate__  s     	 	D 	r"   c                    <"   \        S4      G Rj  xL
  \        SP                  4      ^ 8  d
   S ! 4        R# R#  L)5i)zWait for timeout.N)r   r&   rV   )
flush_keysr(   timeouts   r   wait)KeyProcessor._start_timeout.<locals>.wait  s5      .  4??#a' ( !s   ><*>c                   V ^8  d   QhRR/# rQ   r   )r   s   "r   r    r     s     	  	 D 	 r"   c                 R   < S P                  \        4       S P                  4        R# )zFlush keys.N)r   rD   r   r2   s   r   r   /KeyProcessor._start_timeout.<locals>.flush_keys  s    IIfr"   )r	   
timeoutlenrM   cancelcreate_background_task)r(   r   r   r   r   s   f  @@r   r   KeyProcessor._start_timeout  sf     i..?	 		  	     !!((* # : :46 Br"   c                   V ^8  d   QhRR/# rQ   r   )r   s   "r   r    rH     s      T r"   c                |    V P                  \        \        P                  R7      RR7       V P	                  4        R# )z7
Send SIGINT. Immediately call the SIGINT key handler.
ra   T)r   N)r   r   r   SIGINTr   r2   s   &r   send_sigintKeyProcessor.send_sigint  s)     			(t{{+4	8r"   )
rJ   rM   rT   rS   rY   rL   rW   rK   rU   rV   Nr:   )r1   r>   r?   r@   rA   r)   rN   rn   ry   rX   r   r   r   r   r   r   r   r   r   rB   r   r"   r   r   r   F   sX    *+&U)$9'v
/19"v	1=f5*
?CB r"   c                      ] tR tRtRtR R ltR R lt]R R l4       t]R	 R
 l4       t	]R R l4       t
]R R l4       t]R R l4       t]R R l4       tR R lt]R R l4       tRtR# )r   i  aX  
Key press event, delivered to key bindings.

:param key_processor_ref: Weak reference to the `KeyProcessor`.
:param arg: Repetition argument.
:param key_sequence: List of `KeyPress` instances.
:param previouskey_sequence: Previous list of `KeyPress` instances.
:param is_repeat: True when the previous event was delivered to the same handler.
c               0    V ^8  d   QhRRRRRRRRRR	R
R/# )r   key_processor_refz#weakref.ReferenceType[KeyProcessor]rW   r   r}   r^   r   r   r8   r   r   r   )r   s   "r   r    KeyPressEvent.__annotate__  sF      >  %	
  .  
r"   c                	`    Wn         W0n        W@n        WPn        W n        \        4       V n        R # r=   )_key_processor_refr}   r   r   _argr	   _app)r(   r  rW   r}   r   r   s   &&&&&&r   r)   KeyPressEvent.__init__  s+     #4(%:" #	I	r"   c                   V ^8  d   QhRR/# r,   r   )r   s   "r   r    r    s     t t# tr"   c                	\    R V P                   : RV P                  : RV P                  : R2# )zKeyPressEvent(arg=z, key_sequence=z, is_repeat=r/   )rW   r}   r   r2   s   &r   r3   KeyPressEvent.__repr__  s2    #DHH<t?P?P>SS_`d`n`n_qqrssr"   c                   V ^8  d   QhRR/# r,   r   )r   s   "r   r    r    s     * *c *r"   c                	<    V P                   R,          P                  # )r$   r~   )r}   r   r2   s   &r   r   KeyPressEvent.data  s      $)))r"   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r    r    s      | r"   c                	D    V P                  4       pVf   \        R4      hV# )Nz.KeyProcessor was lost. This should not happen.)r  r   )r(   	processors   & r   key_processorKeyPressEvent.key_processor  s(    ++-	LMMr"   c                   V ^8  d   QhRR/# r   r   zApplication[Any]r   )r   s   "r   r    r    s      % r"   c                    V P                   # )z#
The current `Application` object.
)r  r2   s   &r   r   KeyPressEvent.app  s    
 yyr"   c                   V ^8  d   QhRR/# )r   r   r   r   )r   s   "r   r    r    s     ' ' 'r"   c                .    V P                   P                  # )z
The current buffer.
)r   r   r2   s   &r   r   KeyPressEvent.current_buffer  s    
 xx&&&r"   c                   V ^8  d   QhRR/# )r   r   intr   )r   s   "r   r    r    s      S r"   c                    V P                   R8X  d   R# \        V P                   ;'       g    ^4      p\        V4      R8  d   ^pV# )z
Repetition argument.
-i@B r~   )r  r  )r(   results   & r   rW   KeyPressEvent.arg  sA    
 99ITYY^^!$ v;'!Fr"   c                   V ^8  d   QhRR/# r   r   )r   s   "r   r    r    s     % %T %r"   c                    V P                   RJ# )z6
True if repetition argument was explicitly provided.
N)r  r2   s   &r   arg_presentKeyPressEvent.arg_present  s    
 yy$$r"   c                    V ^8  d   QhRRRR/# )r   r   r-   r   r   r   )r   s   "r   r    r    s     ( ( ( (r"   c                    VR9   g   Q hV P                   pVR8X  d   Ve
   VR8X  g   Q hTpMVf   TpMV V 2pW0P                  n        R# )zJ
Add digit to the input argument.

:param data: the typed digit as string
z-0123456789r  N)r  r  rW   )r(   r   currentr  s   &&  r   append_to_arg_count!KeyPressEvent.append_to_arg_count  s\     }$$$))3;?gn44F_Fy'F!'r"   c                   V ^8  d   QhRR/# r  r   )r   s   "r   r    r    s      % r"   c                    V P                   # )zFor backward-compatibility.)r   r2   s   &r   cliKeyPressEvent.cli  s     xxr"   )r  r  r  r   r}   r   N)r1   r>   r?   r@   rA   r)   r3   propertyr   r  r   r   rW   r#  r(  r,  rB   r   r"   r   r   r     s    $t * *     ' '   % %(&  r"   )r   r   r   )#rA   
__future__r   r   asyncior   r   collectionsr   typingr   r   r   "prompt_toolkit.application.currentr	   prompt_toolkit.enumsr
   prompt_toolkit.filters.appr   prompt_toolkit.keysr   prompt_toolkit.utilsr   rG   r   r   prompt_toolkit.applicationr   r   r   __all__r   rD   r   r   r   r"   r   <module>r:     sx    #    0 0 6 , 9 $ & 26,A A6 
#H	%_ _Df fr"   