
    3                         S SK Jr  S SK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Jr  S SKJr  S SKJrJr  S	S
KJr  SSKJr  SrS rS rS rS rS rS rg)    )unicode_literals)DEFAULT_BUFFER)HasSelection	ConditionEmacsInsertModeViInsertMode)Keys)Point)MouseEventType
MouseEvent)HeightIsUnknownError)suspend_to_background_supported
is_windows   )get_by_name   )Registry)load_basic_bindingsload_abort_and_exit_bindingsload_basic_system_bindingsload_auto_suggestion_bindingsc                 $    U R                   (       + $ )zUCallable that returns True when the previous event was delivered to
another handler. )	is_repeatevents    <lib/third_party/prompt_toolkit/key_binding/bindings/basic.pyif_no_repeatr      s         c            M         [        5       n [        5       [        5       -  nU R                  n[	        5       nU" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                   5      U" [
        R"                  5      U" [
        R$                  5      U" [
        R&                  5      U" [
        R(                  5      U" [
        R*                  5      U" [
        R,                  5      U" [
        R.                  5      U" [
        R0                  5      U" [
        R2                  5      U" [
        R4                  5      U" [
        R6                  5      U" [
        R8                  5      U" [
        R:                  5      U" [
        R<                  5      U" [
        R>                  5      U" [
        R@                  5      U" [
        RB                  5      U" [
        RD                  5      U" [
        RF                  5      U" [
        RH                  5      U" [
        RJ                  5      U" [
        RL                  5      U" [
        RN                  5      U" [
        RP                  5      U" [
        RR                  5      U" [
        RT                  5      U" [
        RV                  5      U" [
        RX                  5      U" [
        RZ                  5      U" [
        R\                  5      U" [
        R^                  5      U" [
        R`                  5      U" [
        Rb                  5      U" [
        Rd                  5      U" [
        Rf                  5      U" [
        Rh                  5      U" [
        Rj                  5      U" [
        Rl                  5      U" [
        Rn                  5      U" [
        Rp                  5      U" [
        Rr                  5      U" [
        Rt                  5      U" [
        Rv                  5      U" [
        Rx                  5      U" [
        Rz                  5      U" [
        R|                  5      U" [
        R~                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      U" [
        R                  5      S 5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       5       nU" [
        R                  5      " [        S5      5        U" [
        R                  5      " [        S5      5        U" [
        Rz                  5      " [        S5      5        U" [
        Rx                  5      " [        S5      5        U" [
        R                  5      " [        S5      5        U" [
        R                  5      " [        S5      5        U" [
        R"                  5      " [        S5      5        U" [
        R                   US	9" [        S
5      5        U" [
        R4                  US	9" [        S5      5        U" [
        R                  U[        S9" [        S5      5        U" [
        Rr                  U[        S9" [        S5      5        U" [
        R                  U[        S9" [        S5      5        U" [
        R                  U[        S9" [        S5      5        U" [
        R                  U[        S9" [        S5      5        U" [
        R2                  US	9" [        S5      5        U" [
        R8                  US	9" [        S5      5        U" [
        R                  US	9" [        S5      5        U" [
        R                  US	9" [        S5      5        U" [
        R                  U) S	9" [        S5      5        U" [
        R                  U) S	9" [        S5      5        [        S 5      nU" [
        R                  XQ-  S	9" [        S5      5        [        S 5      n[        S 5      nU" [
        R                  Xa-  S	9S 5       nU" [
        R                  U) U-  S	9S 5       nU" [
        Rt                  5      S 5       nU" [
        Rv                  5      S 5       nU" [
        R                  US	9S 5       nU" [
        R>                  5      S 5       nU" [
        R                  5      S 5       nU" [
        R                  5      S 5       nU" [
        R                  [        S 5      S S!9S" 5       nU $ )#Nc                     g)a  
First, for any of these keys, Don't do anything by default. Also don't
catch them in the 'Any' handler which will insert them as data.

If people want to insert these characters as a literal, they can always
do by doing a quoted insert. (ControlQ in emacs mode, ControlV in Vi
mode.)
N r   s    r   _load_basic_bindings.<locals>._#   s    h 	r   zbeginning-of-linezend-of-linezbackward-charzforward-charzprevious-historyznext-historyzclear-screenfilterz	kill-linezunix-line-discard)r%   save_beforezbackward-delete-charzdelete-charzself-insertztranspose-charszunix-word-ruboutzmenu-completezmenu-complete-backwardc                 .    U R                   R                  $ N)current_buffertextclis    r   <lambda>%load_basic_bindings.<locals>.<lambda>   s    s/A/A/F/Fr   c                 6    U R                   R                  5       $ r(   )r)   is_multiliner+   s    r   r-   r.      s    ););)H)H)Jr   c                 B    U R                   R                  R                  $ r(   )r)   accept_actionis_returnabler+   s    r   r-   r.      s    #*<*<*J*J*X*Xr   c                 h    U R                   R                  U R                  R                  (       + S9  g)z%Newline (in case of multiline input. )copy_marginN)r)   newliner,   in_paste_moder   s    r   r"   r#      s(     	$$UYY5L5L1L$Mr   c                 h    U R                   nUR                  R                  U R                  U5        g)zEnter, accept input. N)r)   r2   validate_and_handler,   )r   buffs     r   r"   r#      s)     ##..uyy$?r   c                 J    U R                   R                  U R                  S9  g N)count)r)   auto_upargr   s    r   r"   r#      s    $$599$5r   c                 J    U R                   R                  U R                  S9  g r<   )r)   	auto_downr?   r   s    r   r"   r#      s    &&UYY&7r   c                     U R                   R                  5       nU R                  R                  R	                  U5        g r(   )r)   cut_selectionr,   	clipboardset_datar   datas     r   r"   r#      s.    ##113		$$T*r   c                 N    U R                   R                  U R                  5        g)a2  
By default, control-Z should literally insert Ctrl-Z.
(Ansi Ctrl-Z, code 26 in MSDOS means End-Of-File.
In a Python REPL for instance, it's possible to type
Control-Z followed by enter to quit.)

When the system bindings are loaded and suspend-to-background is
supported, that will override this binding.
N)r)   insert_textrG   r   s    r   r"   r#      s     	((4r   c                     [        [        U R                  SS R                  S5      5      u  pU R                  R
                  R                  U5        g)z3
Handle incoming Cursor-Position-Request response.
r   ;N)mapintrG   splitr,   rendererreport_absolute_cursor_row)r   rowcols      r   r"   r#      sB     sEJJq,22378 			55c:r   c                     U R                   nUR                  SS5      nUR                  SS5      nU R                  R                  U5        g)zPasting from clipboard. z

N)rG   replacer)   rI   rF   s     r   r"   r#      sC     zz
 ||FD)||D$'((.r   c                     U R                   $ r(   )quoted_insertr+   s    r   r-   r.      s
    33D3Dr   T)r%   eagerc                 n    U R                   R                  U R                  SS9  SU R                  l        g)z
Handle quoted insert.
F)	overwriteN)r)   rI   rG   r,   rY   r   s    r   r"   r#      s-    
 	((u(E"'		r   )Wr   r   r   add_bindingr   r	   ControlAControlBControlCControlDControlEControlFControlGControlHControlIControlJControlKControlLControlMControlNControlOControlPControlQControlRControlSControlTControlUControlVControlWControlXControlYControlZF1F2F3F4F5F6F7F8F9F10F11F12F13F14F15F16F17F18F19F20ControlSpaceControlBackslashControlSquareCloseControlCircumflexControlUnderscore	BackspaceUpDownRightLeftShiftUp	ShiftDown
ShiftRight	ShiftLeftHomeEndDeleteShiftDeleteControlDeletePageUpPageDownBackTabTabControlLeftControlRight	ControlUpControlDownInsertIgnorer   r   Anyr   CPRResponseBracketedPaste)registryinsert_modehandlehas_selectionr"   text_before_cursorr0   r3   s           r   r   r      s   zH.?#44K!!F NMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDMMDGG_DGG_DGG_DGG_DGG_DGG_DGG_DGG_DGG_DHHDHHDHHDHHDHHDHHDHHDHHDHHDHHDHHDD!!"D##$D""#D""#DNNDGG_DIIDJJDIIDLLDNNDOODNNDIIDHHDKKDDDKKDMMDLLDHHDDDNNDDKKDKK	                          $ $ % #                                               V	 499k"567
488[/0
499k/23
4::{>23
4>>;'9:;
4[89
4==+n56
4==-k+.FG
4==-k:M.NO
4==,G*+-
4>>+<H*+-
4;;{EM"$
4K\JM"$
488K\BM"$
4==-k:K.LM
4==-k:L.MN
4==-k/.JK
4<<,[9Q-RS
4;;/<N0OP
4===.1+n2MN ##FG
4==!3!AB;}C]^JKLXYMDMM,"<=N >N DMM<--"?@@ A@ DGG_6 6 DII8 8 DKK.+ /+ DMM
5 
5 D	; 	; D 
/ !
/ DHHY'DETR( S( Or   c                      [        5       n U R                  [        R                  5      S 5       nU R                  [        R                  5      S 5       nU $ )z`
Key bindings, required for mouse support.
(Mouse events enter through the key binding system.)
c           
         U R                   S   S:X  a  [        [        U R                   SS 5      u  pn[        R                  [        R
                  [        R                  [        R                  S.R                  U5      nUS:  a  US-  nUS:  a  US-  nUS-  nUS-  nOU R                   SS nUSS S	:X  a  S
nUSS nOSn[        [        USS R                  S5      5      u  pnUS   nU(       aP  [        R                  [        R
                  [        R                  [        R                  S.R                  X45      nON[        R                  [        R
                  [        R                  [        R                  S.R                  U5      nUS-  nUS-  nU R                  R                  R                  (       ax  Ubt   X0R                  R                  R                  -  nU R                  R                  R                   R                   X#4   nU" U R                  [#        [%        X#S9US95        ggg! [         a     gf = f)z#
Handling of incoming mouse event.
r   M   N)    #   `   a   i   r   r   <TFrK   rL   ))r   r   )r   m)@   r   )A   r   xyposition
event_type)rG   rM   ordr   
MOUSE_DOWNMOUSE_UP	SCROLL_UPSCROLL_DOWNgetrN   rO   r,   rP   height_is_knownrows_above_layoutr   mouse_handlersr   r
   )r   mouse_eventr   r   rG   sgrr   handlers           r   r"   load_mouse_bindings.<locals>._   s#    ::a=C #CAB 8KA"--"++",,"..	
 c+  F{AJAF{AJAGAGA
 ::ab>DBQx3ABx !$Ccr)= >KARA ,77,55-77-99	
 #{&'  '11&//&00&22	
 c+&  	
Q	Q 99--+2IYY''999
 ii((77FFqsKGEIIz51?5@ B C 3J-
 ( s   "H< <
I	I	c           
         [        5       (       d   eU R                  R                  S5      u  pn[        U5      n[        U5      nU R                  R
                  R                  R                  5       nUR                  R                  U R                  R
                  R                  R                  -
  nX5-  nU R                  R
                  R                  R                  X#4   nU" U R                  [        [        X#S9US95        g)z'
Handling of mouse events for Windows.
rL   r   r   N)r   rG   rO   rN   r,   rP   outputget_win32_screen_buffer_infodwCursorPositionY_cursor_posr   r   r   r
   )r   r   r   r   screen_buffer_inforows_above_cursorr   s          r   r"   r   <  s    
 ||| !::++C0
qFF #YY//66SSU.??AAEIIDVDVDbDbDdDdd	 ))$$33BB13G		:uq1;= 	>r   )r   r]   r	   Vt100MouseEventWindowsMouseEvent)r   r"   s     r   load_mouse_bindingsr      s_    
 zH$../GC 0GCR $001> 2>* Or   c                      [        5       n U R                  nU" [        R                  5      S 5       n[        S 5       nU" [        R
                  US9" [        S5      5        U $ )z6
Basic bindings for abort (Ctrl-C) and exit (Ctrl-D).
c                 8    U R                   R                  5         g)z'Abort when Control-C has been pressed. N)r,   abortr   s    r   r"   'load_abort_and_exit_bindings.<locals>._\  s     			r   c                 l    U R                   [        :H  =(       a    U R                  R                  (       + $ )zMCtrl-D binding is only active when the default buffer is selected
and empty. )current_buffer_namer   r)   r*   r+   s    r   ctrl_d_condition6load_abort_and_exit_bindings.<locals>.ctrl_d_conditiona  s.     ''>9 ,&&+++	-r   r$   zend-of-file)r   r]   r	   r`   r   ra   r   )r   r   r"   r   s       r   r   r   U  se     zH!!FDMM  - - 4==!12;}3MNOr   c                  z    [        5       n [        S 5      nU R                  [        R                  US9S 5       nU $ )z5
Basic system bindings (For both Emacs and Vi mode.)
c                     [        5       $ r(   )r   r+   s    r   r-   ,load_basic_system_bindings.<locals>.<lambda>t  s    35r   r$   c                 8    U R                   R                  5         g)z 
Suspend process to background.
N)r,   suspend_to_backgroundr   s    r   r"   %load_basic_system_bindings.<locals>._v  s    
 			'')r   )r   r   r]   r	   rw   )r   suspend_supportedr"   s      r   r   r   m  sJ     zH!57 $--0AB* C* Or   c                      [        5       n U R                  n[        S 5      nU" [        R                  US9U" [        R
                  US9U" [        R                  US9S 5       5       5       nU $ )z2
Key bindings for accepting auto suggestion text.
c                     U R                   R                  S L=(       a     U R                   R                  R                  $ r(   )r)   
suggestiondocumentis_cursor_at_the_endr+   s    r   r-   /load_auto_suggestion_bindings.<locals>.<lambda>  s5    ))5 =''<<=r   r$   c                 z    U R                   nUR                  nU(       a  UR                  UR                  5        gg)zAccept suggestion. N)r)   r   rI   r*   )r   br   s      r   r"   (load_auto_suggestion_bindings.<locals>._  s0    
   \\
MM*//* r   )r   r]   r   r	   rc   rb   r   )r   r   suggestion_availabler"   s       r   r   r     su     zH!!F$	=>
 DMM"67DMM"67DJJ34+ 5 8 8+ Or   N) 
__future__r   prompt_toolkit.enumsr   prompt_toolkit.filtersr   r   r   r   prompt_toolkit.keysr	   prompt_toolkit.layout.screenr
   prompt_toolkit.mouse_eventsr   r   prompt_toolkit.rendererr   prompt_toolkit.utilsr   r   named_commandsr   r   r   __all__r   r   r   r   r   r   r!   r   r   <module>r      sO    ' / Y Y $ . B 8 L ' K\gT0&r   