U
    dS                     @  s   d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZmZ d dlmZ ddlmZ dd	lmZ d
gZeZdddddZdddd
ZdS )    )annotations)get_app)	Conditionemacs_insert_modehas_selectionin_paste_modeis_multilinevi_insert_mode)KeyPressKeyPressEvent)Keys   )KeyBindings   )get_by_nameload_basic_bindingsEbooleventreturnc                 C  s   | j  S )zXCallable that returns True when the previous event was delivered to
    another handler.)Z	is_repeatr    r   M/tmp/pip-unpacked-wheel-4x_7prb2/prompt_toolkit/key_binding/bindings/basic.pyif_no_repeat   s    r   r   r   c               ]   C  sz  t  } ttB }| j}|d|d|d|d|d|d|d|d|d	|d
|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!|d"|d#|d$|d%|d&|d'|d(|d)|d*|d+|d,|d-|d.|d/|d0|d1|d2|d3|d4|d5|d6|d7|d8|d9|d:|d;|d<|d=|d>|d?|d@|dA|dB|dC|dD|dE|dF|dG|dH|dI|dJ|dK|dL|dM|dN|dO|dP|dQ|dR|dS|dT|dU|dV|dW|dX|dY|tjdZd[d\d]d^}|dAtd_ |dBtd` |d<tda |d;tdb |dRtdc |dStdd |dtde |d|dftdg |d|dftdh |d8|tditdj |dE|tditdk |dG|tditdk |tj|tditdl |d|dftdm |d	|dftdn |dJ|dftdo |d|dftdp |dHt	 dftdc |dIt	 dftdd t
dqdrdsdt}|d||@ dftdk |du|t@ dfdZd[d\dvdw}|d
dZd[d\dxdy}|d9dZd[d\dzd{}|d:dZd[d\d|d}}|dEt	dfdZd[d\d~d}	|ddZd[d\dd}
|tjdZd[d\dd}t
dqdrdd}|tj|dddZd[d\dd}| S )Nzc-azc-bzc-czc-dzc-ezc-fzc-gzc-hzc-izc-jzc-kzc-lzc-mzc-nzc-ozc-pzc-qzc-rzc-szc-tzc-uzc-vzc-wzc-xzc-yzc-zf1f2Zf3Zf4Zf5Zf6Zf7Zf8Zf9Zf10Zf11Zf12Zf13Zf14Zf15Zf16Zf17Zf18Zf19Zf20Zf21Zf22Zf23Zf24zc-@zc-\zc-]zc-^zc-_Z	backspaceZupZdownrightleftzs-upzs-downzs-rightzs-lefthomeendzs-homezs-enddeletezs-deletezc-deleteZpageupZpagedownzs-tabtabzc-s-leftz	c-s-rightzc-s-homezc-s-endzc-leftzc-rightzc-upzc-downzc-homezc-endinsertzs-insertzc-insertz<sigint>r   Noner   c                 S  s   dS )aM  
        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.)
        Nr   r   r   r   r   _ignore%   s    cz$load_basic_bindings.<locals>._ignorezbeginning-of-linezend-of-linezbackward-charzforward-charzprevious-historyznext-historyzclear-screen)filterz	kill-linezunix-line-discard)r'   Zsave_beforezbackward-delete-charzdelete-charzself-insertztranspose-charszmenu-completezmenu-complete-backwardzunix-word-ruboutr   r   c                   S  s   t t jjS N)r   r   current_buffertextr   r   r   r   has_text_before_cursor   s    z3load_basic_bindings.<locals>.has_text_before_cursorZenterc                 S  s   | j jt  d dS )z6
        Newline (in case of multiline input.
        )Zcopy_marginN)r)   newliner   r   r   r   r   _newline   s    z%load_basic_bindings.<locals>._newlinec                 S  s   | j jttjddd dS )z
        By default, handle \n as if it were a \r (enter).
        (It appears that some terminals send \n instead of \r when pressing
        enter. - at least the Linux subsystem for Windows.)
        T)firstN)Zkey_processorfeedr
   r   ZControlMr   r   r   r   	_newline2   s    z&load_basic_bindings.<locals>._newline2c                 S  s   | j j| jd d S N)count)r)   Zauto_upargr   r   r   r   _go_up   s    z#load_basic_bindings.<locals>._go_upc                 S  s   | j j| jd d S r2   )r)   Z	auto_downr4   r   r   r   r   _go_down   s    z%load_basic_bindings.<locals>._go_downc                 S  s   | j  }| jj| d S r(   )r)   Zcut_selectionappZ	clipboardset_datar   datar   r   r   _cut   s    
z!load_basic_bindings.<locals>._cutc                 S  s   | j | j dS )aj  
        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_textr:   r   r   r   r   _insert_ctrl_z   s    z+load_basic_bindings.<locals>._insert_ctrl_zc                 S  s.   | j }|dd}|dd}| j| dS )z)
        Pasting from clipboard.
        z

r.   N)r:   replacer)   r<   r9   r   r   r   _paste   s    z#load_basic_bindings.<locals>._pastec                   S  s   t  jS r(   )r   quoted_insertr   r   r   r   in_quoted_insert   s    z-load_basic_bindings.<locals>.in_quoted_insertT)r'   eagerc                 S  s   | j j| jdd d| j_dS )z'
        Handle quoted insert.
        F)	overwriteN)r)   r<   r:   r7   rA   r   r   r   r   _insert_text   s    z)load_basic_bindings.<locals>._insert_text)r   r	   r   addr   Ignorer   r   Anyr   r   r   ZBracketedPaste)key_bindingsZinsert_modehandler&   r+   r-   r1   r5   r6   r;   r=   r@   rB   rE   r   r   r   r       s"   

N)
__future__r   Z"prompt_toolkit.application.currentr   Zprompt_toolkit.filtersr   r   r   r   r   r	   Z(prompt_toolkit.key_binding.key_processorr
   r   Zprompt_toolkit.keysr   rI   r   Znamed_commandsr   __all__r   r   r   r   r   r   r   <module>   s    