
    2>                        S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
r
SSK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r0 rS rS r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r\" S5      S 5       r \" S 5      S! 5       r!\" S"5      S# 5       r"\" S$5      S% 5       r#\" S&5      S' 5       r$\" S(5      S) 5       r%\" S*5      S+ 5       r&\" S,5      S- 5       r'\" S.5      S/ 5       r(\" S05      S1 5       r)\" S25      S3 5       r*\" S45      S5 5       r+\" S65      S7 5       r,\" S85      S9 5       r-\" S:5      S; 5       r.\" S<5      S= 5       r/\" S>5      S? 5       r0\" S@5      SA 5       r1\" SB5      SnSC j5       r2\" SD5      SE 5       r3\" SF5      SG 5       r4\" SH5      SI 5       r5\" SJ5      SK 5       r6\" SL5      SM 5       r7\" SN5      SO 5       r8\" SP5      SQ 5       r9\" SR5      SS 5       r:\" ST5      SU 5       r;\" SV5      SW 5       r<\" SX5      SY 5       r=\" SZ5      S[ 5       r=\" S\5      S] 5       r=\" S^5      S_ 5       r>\" S`5      Sa 5       r?\" Sb5      Sc 5       r@\" Sd5      Se 5       rA\" Sf5      Sg 5       rB\" Sh5      Si 5       rC\" Sj5      Sk 5       rD\" Sl5      Sm 5       rEg)oz
Key bindings which are also known by GNU readline by the given names.

See: http://www.delorie.com/gnu/docs/readline/rlman_13.html
    )unicode_literals)IncrementalSearchDirectionSEARCH_BUFFER)	PasteMode)rangeN   )generate_completions!display_completions_like_readline)Document)EditingMode)KeyPress)Keys)get_by_namec                 V   ^  [        T [        R                  5      (       d   eU 4S jnU$ )z7
Store handler in the `_readline_commands` dictionary.
c                 >   > [        U 5      (       d   eU [        T'   U $ N)callable_readline_commands)handlernames    Elib/third_party/prompt_toolkit/key_binding/bindings/named_commands.py	decoratorregister.<locals>.decorator   s$        #*4     )
isinstancesix	text_type)r   r   s   ` r   registerr      s)     dCMM****
 r   c                 N     [         U    $ ! [         a    [        SU -  5      ef = f)zD
Return the handler for the (Readline) command with the given name.
zUnknown readline command: %r)r   KeyError)r   s    r   r   r   '   s2    >!$'' >5<==>s    $zbeginning-of-linec                 t    U R                   nU=R                  UR                  R                  SS9-  sl        g)z'Move to the start of the current line. F)after_whitespaceN)current_buffercursor_positiondocumentget_start_of_line_positioneventbuffs     r   beginning_of_liner*   5   s3     DDMMDDV[D\\r   zend-of-linec                 v    U R                   nU=R                  UR                  R                  5       -  sl        g)zMove to the end of the line. N)r#   r$   r%   get_end_of_line_positionr'   s     r   end_of_liner-   <   s-     DDMMBBDDr   zforward-charc                     U R                   nU=R                  UR                  R                  U R                  S9-  sl        g)zMove forward a character. countN)r#   r$   r%   get_cursor_right_positionargr'   s     r   forward_charr3   C   s6     DDMMCC%))CTTr   zbackward-charc                     U R                   nU=R                  UR                  R                  U R                  S9-  sl        g)zMove back a character. r/   N)r#   r$   r%   get_cursor_left_positionr2   r'   s     r   backward_charr6   J   s6     DDMMBBBSSr   zforward-wordc                     U R                   nUR                  R                  U R                  S9nU(       a  U=R                  U-  sl        gg)zU
Move forward to the end of the next word. Words are composed of letters and
digits.
r/   N)r#   r%   find_next_word_endingr2   r$   r(   r)   poss      r   forward_wordr;   Q   sC     D
--
-
-EII
-
>C
# r   zbackward-wordc                     U R                   nUR                  R                  U R                  S9nU(       a  U=R                  U-  sl        gg)zc
Move back to the start of the current or previous word. Words are composed
of letters and digits.
r/   N)r#   r%   find_previous_word_beginningr2   r$   r9   s      r   backward_wordr>   ^   sC     D
--
4
4599
4
EC
# r   zclear-screenc                 L    U R                   R                  R                  5         g)zB
Clear the screen and redraw everything at the top of the screen.
N)clirendererclearr(   s    r   clear_screenrD   k   s    
 
IIr   zredraw-current-linec                     g)z`
Refresh the current line.
(Readline defines this command, but prompt-toolkit doesn't have it.)
N rC   s    r   redraw_current_linerG   s   s     	r   zaccept-linec                 h    U R                   nUR                  R                  U R                  U5        g)z3Accept the line regardless of where the cursor is. N)r#   accept_actionvalidate_and_handler@   )r(   bs     r   accept_linerL      s'     	AOO''		15r   zprevious-historyc                 J    U R                   R                  U R                  S9  g)zFMove `back' through the history list, fetching the previous command.  r/   N)r#   history_backwardr2   rC   s    r   previous_historyrO      s     
))		):r   znext-historyc                 J    U R                   R                  U R                  S9  g)zDMove `forward' through the history list, fetching the next command. r/   N)r#   history_forwardr2   rC   s    r   next_historyrR      s     
((uyy(9r   zbeginning-of-historyc                 :    U R                   R                  S5        g)z'Move to the first line in the history. r   N)r#   go_to_historyrC   s    r   beginning_of_historyrU      s     
&&q)r   zend-of-historyc                     U R                   R                  SS-  S9  U R                   nUR                  [        UR                  5      S-
  5        g)zO
Move to the end of the input history, i.e., the line currently being entered.

   d   r/   r   N)r#   rQ   rT   len_working_linesr'   s     r   end_of_historyr[      sH    
 
((r3w(7Ds4../!34r   zreverse-search-historyc                     [         R                  U R                  R                  l        U R                  R                  [        5        g)z
Search backward starting at the current line and moving `up' through
the history as necessary. This is an incremental search.
N)r   BACKWARDr@   current_search_state	direction
push_focusr   rC   s    r   reverse_search_historyra      s/     0J/R/REII"",	II'r   zend-of-filec                 8    U R                   R                  5         g)z
Exit.
N)r@   exitrC   s    r   end_of_filerd      s    
 
IINNr   zdelete-charc                     U R                   R                  U R                  S9nU(       d%  U R                  R                  R                  5         gg)z$Delete character before the cursor. r/   N)r#   deleter2   r@   outputbellr(   deleteds     r   delete_charrk      s?     ""))		):G		 r   zbackward-delete-charc                    U R                   S:  a%  U R                  R                  U R                   * S9nO#U R                  R                  U R                   S9nU(       d%  U R                  R
                  R                  5         gg)z(Delete the character behind the cursor. r   r/   N)r2   r#   rf   delete_before_cursorr@   rg   rh   ri   s     r   backward_delete_charrn      sk     yy1} &&--UYYJ-?&&;;%));L		 r   zself-insertc                 h    U R                   R                  U R                  U R                  -  5        g)zInsert yourself. N)r#   insert_textdatar2   rC   s    r   self_insertrr      s%     
$$UZZ%))%;<r   ztranspose-charsc                 6   U R                   nUR                  nUS:X  a  gU[        UR                  5      :X  d  UR                  U   S:X  a  UR	                  5         gU=R                  UR
                  R                  5       -  sl        UR	                  5         g)z
Emulate Emacs transpose-char behavior: at the beginning of the buffer,
do nothing.  At the end of a line or buffer, swap the characters before
the cursor.  Otherwise, move the cursor right, and then swap the
characters before the cursor.
r   N
)r#   r$   rY   textswap_characters_before_cursorr%   r1   )r(   rK   ps      r   transpose_charsrx      sy     	A	AAv	
c!&&k	QVVAY$.	'')	QZZAACC	'')r   zuppercase-wordc                     U R                   n[        U R                  5       HT  nUR                  R	                  5       nUR                  R
                  SU nUR                  UR                  5       SS9  MV     g)z,
Uppercase the current (or following) word.
NT	overwrite)r#   r   r2   r%   r8   text_after_cursorrp   upperr(   r)   ir:   wordss        r   uppercase_wordr      c    
 D599mm113//5$7 r   zdowncase-wordc                     U R                   n[        U R                  5       HT  nUR                  R	                  5       nUR                  R
                  SU nUR                  UR                  5       SS9  MV     g)z,
Lowercase the current (or following) word.
NTrz   )r#   r   r2   r%   r8   r|   rp   lowerr~   s        r   downcase_wordr      r   r   zcapitalize-wordc                     U R                   n[        U R                  5       HT  nUR                  R	                  5       nUR                  R
                  SU nUR                  UR                  5       SS9  MV     g)z-
Capitalize the current (or following) word.
NTrz   )r#   r   r2   r%   r8   r|   rp   titler~   s        r   capitalize_wordr     r   r   zquoted-insertc                 &    SU R                   l        g)zo
Add the next character typed to the line verbatim. This is how to insert
key sequences like C-q, for example.
TN)r@   quoted_insertrC   s    r   r   r     s     #EIIr   z	kill-linec                 ~   U R                   nU R                  S:  a)  UR                  UR                  R	                  5       * S9nOSUR                  R
                  S:X  a  UR                  S5      nO'UR                  UR                  R                  5       S9nU R                  R                  R                  U5        g)z
Kill the text from the cursor to the end of the line.

If we are at the end of the line, this should remove the newline.
(That way, it is possible to delete multiple lines by executing this
command multiple times.)
r   r/   rt   r   N)r#   r2   rm   r%   r&   current_charrf   r,   r@   	clipboardset_textr(   r)   rj   s      r   	kill_liner     s     Dyy1}++4==3[3[3]2]+^==%%-kk!nGkk(N(N(PkQG	II  )r   z	kill-wordc                     U R                   nUR                  R                  U R                  S9nU(       a5  UR	                  US9nU R
                  R                  R                  U5        gg)z
Kill from point to the end of the current word, or if between words, to the
end of the next word. Word boundaries are the same as forward-word.
r/   N)r#   r%   r8   r2   rf   r@   r   r   )r(   r)   r:   rj   s       r   	kill_wordr   0  sZ     D
--
-
-EII
-
>C
++C+(		$$W- r   zunix-word-ruboutc                    U R                   nUR                  R                  U R                  US9nUc  UR                  * nU(       aw  UR                  U* S9nU R                  (       a0  X@R                  R                  R                  5       R                  -  nU R                  R                  R                  U5        gU R                  R                  R                  5         g)z]
Kill the word behind point, using whitespace as a word boundary.
Usually bound to ControlW.
)r0   WORDNr/   )r#   r%   find_start_of_previous_wordr2   r$   rm   	is_repeatr@   r   get_dataru   r   rg   rh   )r(   r   r)   r:   rj   s        r   unix_word_ruboutr   >  s     D
--
3
3%))$
3
OC
{ $$$
++3$+7 ??yy**335:::G		$$W- 			r   zbackward-kill-wordc                     [        U SS9  g)zz
Kills the word before point, using "not a letter nor a digit" as a word boundary.
Usually bound to M-Del or M-Backspace.
F)r   N)r   rC   s    r   backward_kill_wordr   [  s     U'r   zdelete-horizontal-spacec                 H   U R                   nUR                  R                  nUR                  R                  n[	        U5      [	        UR                  S5      5      -
  n[	        U5      [	        UR                  S5      5      -
  nUR                  US9  UR                  US9  g)z)Delete all spaces and tabs around point. z	 r/   N)	r#   r%   text_before_cursorr|   rY   rstriplstriprm   rf   )r(   r)   r   r|   delete_beforedelete_afters         r   delete_horizontal_spacer   d  s     D9977*+c2D2K2KE2R.SSM()C0A0H0H0O,PPLM2KKlK#r   zunix-line-discardc                 >   U R                   nUR                  R                  S:X  a*  UR                  R                  S:  a  UR	                  SS9  gUR	                  UR                  R                  5       * S9nU R                  R                  R                  U5        g)zE
Kill backward from the cursor to the beginning of the current line.
r   r   r/   N)	r#   r%   cursor_position_colr$   rm   r&   r@   r   r   r   s      r   unix_line_discardr   r  s    
 D}}((A-$--2O2ORS2S!!!*++4==3[3[3]2]+^		$$W-r   yankc                     U R                   R                  U R                  R                  R	                  5       U R
                  [        R                  S9  g)z
Paste before cursor.
)r0   
paste_modeN)r#   paste_clipboard_datar@   r   r   r2   r   EMACSrC   s    r   r   r     s@    
 
--		$$&eiiIOO . Ur   zyank-nth-argc                 x    U R                   (       a  U R                  OSnU R                  R                  U5        g)z
Insert the first argument of the previous command. With an argument, insert
the nth word from the previous command (start counting at 0).
N)arg_presentr2   r#   yank_nth_argr(   ns     r   r   r     s+     ''TA	%%a(r   zyank-last-argc                 x    U R                   (       a  U R                  OSnU R                  R                  U5        g)zZ
Like `yank_nth_arg`, but if no argument has been given, yank the last word
of each line.
N)r   r2   r#   yank_last_argr   s     r   r   r     s+     ''TA	&&q)r   zyank-popc                     U R                   nUR                  nU R                  R                  nUbC  X!l        UR                  5         UR                  UR                  5       [        R                  S9  gg)zT
Rotate the kill ring, and yank the new top. Only works following yank or
yank-pop.
N)r   )
r#   document_before_paster@   r   r%   rotater   r   r   r   )r(   r)   doc_before_paster   s       r   yank_popr     sk     D11		##I#(!! Y__ 	" 	> $r   completec                     [        U 5        g)zAttempt to perform completion. N)r
   rC   s    r   r   r     s     &e,r   zmenu-completec                     [        U 5        g)zv
Generate completions, or go to the next completion. (This is the default
way of completing input in prompt_toolkit.)
N)r	   rC   s    r   menu_completer     s     r   zmenu-complete-backwardc                 8    U R                   R                  5         g)z8Move backward through the list of possible completions. N)r#   complete_previousrC   s    r   menu_complete_backwardr     s     
**,r   zstart-kbd-macroc                 L    U R                   R                  R                  5         g)zD
Begin saving the characters typed into the current keyboard macro.
N)r@   input_processorstart_macrorC   s    r   start_kbd_macror     s    
 
II))+r   zend-kbd-macroc                 L    U R                   R                  R                  5         g)z[
Stop saving the characters typed into the current keyboard macro and save
the definition.
N)r@   r   	end_macrorC   s    r   r   r     s     
II'')r   zcall-last-kbd-macroc                 L    U R                   R                  R                  5         g)zw
Re-execute the last keyboard macro defined, by making the characters in the
macro appear as if typed at the keyboard.
N)r@   r   
call_macrorC   s    r   r   r     s     
II((*r   zprint-last-kbd-macroc                 H   ^  U 4S jnT R                   R                  U5        g)zPrint the last keboard macro. c                  j   > TR                   R                  R                   H  n [        U 5        M     g r   )r@   r   macroprint)kr(   s    r   print_macro)print_last_kbd_macro.<locals>.print_macro  s$    **00A!H 1r   N)r@   run_in_terminal)r(   r   s   ` r   print_last_kbd_macror     s     
IIk*r   undoc                 8    U R                   R                  5         g)zIncremental undo. N)r#   r   rC   s    r   r   r     s     
r   zinsert-commentc           	         U R                   nU R                  S:w  a  S nOS n[        SR                  [	        X!R
                  R                  5       5      5      SS9Ul        UR                  R                  U R                  U5        g)zx
Without numeric argument, comment all lines.
With numeric argument, uncomment all lines.
In any case accept the input.
r   c                 <    U R                  S5      (       a  U SS  $ U $ )N#r   )
startswithlines    r   changeinsert_comment.<locals>.change  s!    #s3348==r   c                     SU -   $ )Nr   rF   r   s    r   r   r     s    :r   rt   r   )ru   r$   N)r#   r2   r   joinmapru   
splitlinesr%   rI   rJ   r@   )r(   r)   r   s      r   insert_commentr     sq     D yyA~	>	 YYs699#7#7#9:;DM
 	**599d;r   zvi-editing-modec                 B    [         R                  U R                  l        g)zSwitch to Vi editing mode. N)r   VIr@   editing_moderC   s    r   vi_editing_moder     s     )^^EIIr   zemacs-editing-modec                 B    [         R                  U R                  l        g)zSwitch to Emacs editing mode. N)r   r   r@   r   rC   s    r   emacs_editing_moder     s     )..EIIr   zprefix-metac                 |    U R                   R                  R                  [        [        R
                  5      5        g)z
Metafy the next character typed. This is for keyboards without a meta key.

Sometimes people also want to bind other keys to Meta, e.g. 'jj'::

    registry.add_key_binding('j', 'j', filter=ViInsertMode())(prefix_meta)
N)r@   r   feedr   r   EscaperC   s    r   prefix_metar     s%     
II""8DKK#89r   zoperate-and-get-nextc                    ^^ U R                   mTR                  S-   mTR                  R                  U R                  T5        UU4S jnU R                  R
                  R                  U5        g)zz
Accept the current line for execution and fetch the next line relative to
the current line from the history for editing.
r   c                  H   > T[        T R                  5      :  a  TT l        g g r   )rY   rZ   working_index)r)   	new_indexs   r   set_working_index/operate_and_get_next.<locals>.set_working_index3  s#    s4..//!*D 0r   N)r#   r   rI   rJ   r@   pre_run_callablesappend)r(   r   r)   r   s     @@r   operate_and_get_nextr   %  s\     D""Q&I 	**599d;+ 
II&&'89r   zedit-and-execute-commandc                     U R                   nUR                  U R                  5        UR                  R	                  U R                  U5        g)zF
Invoke an editor on the current command line, and accept the result.
N)r#   open_in_editorr@   rI   rJ   r'   s     r   edit_and_executer   :  s;    
 D		"**599d;r   )T)F__doc__
__future__r   prompt_toolkit.enumsr   r   prompt_toolkit.selectionr   	six.movesr   r   
completionr	   r
   prompt_toolkit.documentr   r   *prompt_toolkit.key_binding.input_processorr   prompt_toolkit.keysr   __all__r   r   r   r*   r-   r3   r6   r;   r>   rD   rG   rL   rO   rR   rU   r[   ra   rd   rk   rn   rr   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rF   r   r   <module>r      s  
 ( J .  
 O , , ? $  
> 

] ] 
-E E 
.U U 
/T T 
.	$ 	$ 
/	$ 	$ 
.  

 	 !	 
-6 6 

; ;
 
.: :
 

 !* "*
 

5 5 

"#( $( 
-  
-    

 !
  "
  
-= =
 

* *$ 

	8 	8 
/	8 	8 

	8 	8 
/# # 
+* *& 
+
. 
. 

   8 

(  ( 

#$
$ %
$ 


. 
. 
&U U 
.) ) 
/* * 
*> >& 
*- -
 
/    

"#- $- 

, , 
/* * 

 + !+ 

 !+ "+ 
&   
 

< <0 

, ,
 

/  /
 
-: : 

 !: ":( 

$%< &<r   