ó
±xYc           @  sþ   d  d l  m Z d  d l 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 m Z d  d l m Z d  d l m Z m Z d	 d
 l m Z d d l m Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   unicode_literals(   t   DEFAULT_BUFFER(   t   HasSelectiont	   Conditiont   EmacsInsertModet   ViInsertMode(   t   Keys(   t   Point(   t   MouseEventTypet
   MouseEvent(   t   HeightIsUnknownError(   t   suspend_to_background_supportedt
   is_windowsi   (   t   get_by_namei   (   t   Registryu   load_basic_bindingsu   load_abort_and_exit_bindingsu   load_basic_system_bindingsu   load_auto_suggestion_bindingsc         C  s   |  j  S(   uZ    Callable that returns True when the previous event was delivered to
    another handler. (   t	   is_repeat(   t   event(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   if_no_repeat   s    c       L   C  s`  t  ƒ  }  t ƒ  t ƒ  B} |  j } t ƒ  } | t j ƒ | t j ƒ | t j ƒ | t j	 ƒ | t j
 ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j ƒ | t j  ƒ | t j! ƒ | t j" ƒ | t j# ƒ | t j$ ƒ | t j% ƒ | t j& ƒ | t j' ƒ | t j( ƒ | t j) ƒ | t j* ƒ | t j+ ƒ | t j, ƒ | t j- ƒ | t j. ƒ | t j/ ƒ | t j0 ƒ | t j1 ƒ | t j2 ƒ | t j3 ƒ | t j4 ƒ | t j5 ƒ | t j6 ƒ | t j7 ƒ | t j8 ƒ | t j9 ƒ | t j: ƒ | t j; ƒ | t j< ƒ | t j= ƒ | t j> ƒ | t j? ƒ | t j@ ƒ | t jA ƒ | t jB ƒ | t jC ƒ | t jD ƒ | t jE ƒ | t jF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ƒ d „  ƒ } | t jS d	 tT d  „  ƒ d! tW ƒd" „  ƒ } |  S(#   Nc         S  s   d S(   uM  
        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   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   _#   s    Tu   beginning-of-lineu   end-of-lineu   backward-charu   forward-charu   previous-historyu   next-historyu   clear-screent   filteru	   kill-lineu   unix-line-discardt   save_beforeu   backward-delete-charu   delete-charu   self-insertu   transpose-charsu   unix-word-ruboutu   menu-completeu   menu-complete-backwardc         S  s
   |  j  j S(   N(   t   current_buffert   text(   t   cli(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   <lambda>˜   s    c         S  s   |  j  j ƒ  S(   N(   R   t   is_multiline(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ›   s    c         S  s   |  j  j j S(   N(   R   t   accept_actiont   is_returnable(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   œ   s    c         S  s   |  j  j d |  j j ƒ d S(   u&    Newline (in case of multiline input. t   copy_marginN(   R   t   newlineR   t   in_paste_mode(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ž   s    c         S  s#   |  j  } | j j |  j | ƒ d S(   u    Enter, accept input. N(   R   R   t   validate_and_handleR   (   R   t   buff(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   £   s    	c         S  s   |  j  j d |  j ƒ d  S(   Nt   count(   R   t   auto_upt   arg(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   «   s    c         S  s   |  j  j d |  j ƒ d  S(   NR!   (   R   t	   auto_downR#   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ¯   s    c         S  s&   |  j  j ƒ  } |  j j j | ƒ d  S(   N(   R   t   cut_selectionR   t	   clipboardt   set_data(   R   t   data(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ³   s    c         S  s   |  j  j |  j ƒ d S(   uj  
        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   t   insert_textR(   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   º   s    c         S  s   t  S(   N(   t   False(   t   e(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   Ç   s    c         S  s?   t  t |  j d d !j d ƒ ƒ \ } } |  j j j | ƒ d S(   uC   
        Handle incoming Cursor-Position-Request response.
        i   iÿÿÿÿu   ;N(   t   mapt   intR(   t   splitR   t   renderert   report_absolute_cursor_row(   R   t   rowt   col(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   Ç   s    (c         S  sA   |  j  } | j d d ƒ } | j d d ƒ } |  j j | ƒ d S(   u    Pasting from clipboard. u   
u   
u   N(   R(   t   replaceR   R)   (   R   R(   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   Ó   s    	c         S  s   |  j  S(   N(   t   quoted_insert(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   à   s    t   eagerc         S  s)   |  j  j |  j d t ƒt |  j _ d S(   u'   
        Handle quoted insert.
        t	   overwriteN(   R   R)   R(   R*   R   R4   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   à   s    (X   R   R   R   t   add_bindingR   R   t   ControlAt   ControlBt   ControlCt   ControlDt   ControlEt   ControlFt   ControlGt   ControlHt   ControlIt   ControlJt   ControlKt   ControlLt   ControlMt   ControlNt   ControlOt   ControlPt   ControlQt   ControlRt   ControlSt   ControlTt   ControlUt   ControlVt   ControlWt   ControlXt   ControlYt   ControlZt   F1t   F2t   F3t   F4t   F5t   F6t   F7t   F8t   F9t   F10t   F11t   F12t   F13t   F14t   F15t   F16t   F17t   F18t   F19t   F20t   ControlSpacet   ControlBackslasht   ControlSquareCloset   ControlCircumflext   ControlUnderscoret	   Backspacet   Upt   Downt   Rightt   Leftt   ShiftUpt	   ShiftDownt
   ShiftRightt	   ShiftLeftt   Homet   Endt   Deletet   ShiftDeletet   ControlDeletet   PageUpt   PageDownt   BackTabt   Tabt   ControlLeftt   ControlRightt	   ControlUpt   ControlDownt   Insertt   IgnoreR   R   t   AnyR   t   CPRResponset   BracketedPastet   True(   t   registryt   insert_modet   handlet   has_selectionR   t   text_before_cursorR   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   load_basic_bindings   sì    			ö  #"#!-c          C  sC   t  ƒ  }  |  j t j ƒ d „  ƒ } |  j t j ƒ d „  ƒ } |  S(   ul   
    Key bindings, required for mouse support.
    (Mouse events enter through the key binding system.)
    c      	   S  s@  |  j  d d k r² t t |  j  d ƒ \ } } } i t j d 6t j d 6t j d 6t j d 6j | ƒ } | d k r‚ | d 8} n  | d k r› | d 8} n  | d 8} | d 8} nâ |  j  d } | d	  d
 k râ t	 } | d	 } n t
 } t t | d  j d ƒ ƒ \ } } } | d } | r]i t j d 6t j d 6t j d 6t j d 6j | | f ƒ } n7 i t j d 6t j d 6t j d 6t j d 6j | ƒ } | d	 8} | d	 8} |  j j j r<| d k	 r<y | |  j j j 8} Wn t k
 rîd SX|  j j j j | | f } | |  j t d t d | d | ƒ d | ƒ ƒ n  d S(   u3   
        Handling of incoming mouse event.
        i   u   Mi   i    i#   i`   ia   i Ü  i   u   <iÿÿÿÿu   ;i    u   mi@   iA   Nt   positiont   xt   yt
   event_type(   i    u   M(   i    u   m(   i@   u   M(   iA   u   M(   R(   R,   t   ordR   t
   MOUSE_DOWNt   MOUSE_UPt	   SCROLL_UPt   SCROLL_DOWNt   getR†   R*   R-   R.   R   R/   t   height_is_knownt   Nonet   rows_above_layoutR
   t   mouse_handlersR	   R   (   R   t   mouse_eventRŽ   R   R(   t   sgrt   mt   handler(    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ò   sX    



	  
%






	

$c      	   S  sË   t  ƒ  s t ‚ |  j j d ƒ \ } } } t | ƒ } t | ƒ } |  j j j j ƒ  } | j	 j
 |  j j j j } | | 8} |  j j j j | | f } | |  j t d t d | d | ƒ d | ƒ ƒ d S(   u7   
        Handling of mouse events for Windows.
        u   ;R   RŽ   R   R   N(   R   t   AssertionErrorR(   R.   R-   R   R/   t   outputt   get_win32_screen_buffer_infot   dwCursorPositiont   Yt   _cursor_posR   Rš   R	   R   (   R   R   RŽ   R   t   screen_buffer_infot   rows_above_cursorRž   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   <  s    
$(   R   R7   R   t   Vt100MouseEventt   WindowsMouseEvent(   R‡   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   load_mouse_bindingsë   s    	Jc          C  s\   t  ƒ  }  |  j } | t j ƒ d „  ƒ } t d „  ƒ } | t j d | ƒt d ƒ ƒ |  S(   u>   
    Basic bindings for abort (Ctrl-C) and exit (Ctrl-D).
    c         S  s   |  j  j ƒ  d S(   u(    Abort when Control-C has been pressed. N(   R   t   abort(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   \  s    c         S  s   |  j  t k o |  j j S(   uV    Ctrl-D binding is only active when the default buffer is selected
        and empty. (   t   current_buffer_nameR   R   R   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   ctrl_d_conditiona  s    R   u   end-of-file(   R   R7   R   R:   R   R;   R   (   R‡   R‰   R   R¬   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   load_abort_and_exit_bindingsU  s    		c          C  s=   t  ƒ  }  t d „  ƒ } |  j t j d | ƒd „  ƒ } |  S(   u=   
    Basic system bindings (For both Emacs and Vi mode.)
    c         S  s   t  ƒ  S(   N(   R   (   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   t  s    R   c         S  s   |  j  j ƒ  d S(   u0   
        Suspend process to background.
        N(   R   t   suspend_to_background(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   v  s    (   R   R   R7   R   RQ   (   R‡   t   suspend_supportedR   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   load_basic_system_bindingsm  s
    	!c          C  sm   t  ƒ  }  |  j } t d „  ƒ } | t j d | ƒ| t j d | ƒ| t j d | ƒd „  ƒ ƒ ƒ } |  S(   u:   
    Key bindings for accepting auto suggestion text.
    c         S  s   |  j  j d  k	 o |  j  j j S(   N(   R   t
   suggestionR˜   t   documentt   is_cursor_at_the_end(   R   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   ˆ  s    R   c         S  s/   |  j  } | j } | r+ | j | j ƒ n  d S(   u    Accept suggestion. N(   R   R±   R)   R   (   R   t   bR±   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyR   Œ  s    		(   R   R7   R   R   R=   R<   Rn   (   R‡   R‰   t   suggestion_availableR   (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   load_auto_suggestion_bindings€  s    		$	N(   u   load_basic_bindingsu   load_abort_and_exit_bindingsu   load_basic_system_bindingsu   load_auto_suggestion_bindings(    t
   __future__R    t   prompt_toolkit.enumsR   t   prompt_toolkit.filtersR   R   R   R   t   prompt_toolkit.keysR   t   prompt_toolkit.layout.screenR   t   prompt_toolkit.mouse_eventsR   R	   t   prompt_toolkit.rendererR
   t   prompt_toolkit.utilsR   R   t   named_commandsR   R‡   R   t   __all__R   RŒ   R©   R­   R°   R¶   (    (    (    sH   lib/python2.7/site-packages/prompt_toolkit/key_binding/bindings/basic.pyt   <module>   s&   "   		Î	j		