o
    eEd                     @   s   d dl mZmZmZ d dlZd dlm  mZ d dlm  m	Z	 d dl
mZ d dl
mZ ddlmZ G dd dejZdd	 ZdS )
    )absolute_importprint_functionunicode_literalsN)log   )basemodec                       s  e Zd ZdZ fddZdd Zdd Zdd	d
Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Z d=d> Z!d?d@ Z"dAdB Z#dCdD Z$dEdF Z%dGdH Z&dIdJ Z'dKdL Z(dMdN Z)dOdP Z*dQdR Z+dSdT Z,dUdV Z-dWdX Z.dYdZ Z/d[d\ Z0d]d^ Z1d_d` Z2dadb Z3dcdd Z4dedf Z5dgdh Z6didj Z7dkdl Z8dmdn Z9dodp Z:dqdr Z;dsdt Z<dudv Z=dwdx Z>dydz Z?d{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQ  ZRS )NotEmacsModeZnotemacsc                    s   t t| | d S )N)superr   __init__)selfZrlobj	__class__ JD:\Projects\ConvertPro\env\Lib\site-packages\pyreadline3/modes/notemacs.pyr
      s   zNotEmacsMode.__init__c                 C      dS )Nz<NotEmacsMode>r   )r   r   r   r   __repr__   s   zNotEmacsMode.__repr__c           	      C   s   | j }	 |   | }| jr d| _|j\}}}}|d||f|_|j| jv r0t| jdkr0t	| j
|j| j}td|jf  d }|rN||}| j  || _|rY|   d S q)NTFr   zreadline from keyboard:%s)console_update_linegetkeypress	next_metakeyinfoZexit_dispatchlineobjZ	EndOfLinel_bufferEOFErrorZkey_dispatchgetself_insertr   Z	push_undoZprevious_func)	r   ceventcontrolmetashiftcodeZdispatch_funcrr   r   r   _readline_from_keyboard   s0   
z$NotEmacsMode._readline_from_keyboard c                 C   s0  | j r!d| _ | jr!z|   W n ty    td t  Y nw | j}| j  || _	| 
  | jrNz|   W n tyM   td t  d| _Y nw td| j  t| jdkrwt| jd | _|   | jdd | _|d n	|   |d | | j  td	| j   | j d
 S )zTry to act like GNU readline.Fzstartup hook failedzpre_input_hook failedNzin readline: %sr   r   z
zreturning(%s)
)Zfirst_promptZstartup_hookBaseExceptionprint	traceback	print_excr   r   Z
reset_lineprompt_print_promptZpre_input_hookr   paste_line_bufferlenr   ZReadlineTextBufferr   writer#   add_historycopyZget_line_text)r   r*   r   r   r   r   readline;   sD   


zNotEmacsMode.readlinec                 C      | j   dS )z'Move to the start of the current line. N)r   beginning_of_liner   er   r   r   r3   f      zNotEmacsMode.beginning_of_linec                 C   r2   )zMove to the end of the line. N)r   end_of_liner4   r   r   r   r7   j   r6   zNotEmacsMode.end_of_linec                 C   r2   )zMove forward a character. N)r   forward_charr4   r   r   r   r8   n   r6   zNotEmacsMode.forward_charc                 C   r2   )zMove back a character. N)r   backward_charr4   r   r   r   r9   r   r6   zNotEmacsMode.backward_charc                 C   r2   )z[Move forward to the end of the next word. Words are composed of
        letters and digits.N)r   forward_wordr4   r   r   r   r:   v      zNotEmacsMode.forward_wordc                 C   r2   )ziMove back to the start of the current or previous word. Words are
        composed of letters and digits.N)r   backward_wordr4   r   r   r   r<   {   r;   zNotEmacsMode.backward_wordc                 C   r2   )zhClear the screen and redraw the current line, leaving the current
        line at the top of the screen.N)r   pager4   r   r   r   clear_screen   r;   zNotEmacsMode.clear_screenc                 C   r   )z6Refresh the current line. By default, this is unbound.Nr   r4   r   r   r   redraw_current_line      z NotEmacsMode.redraw_current_linec                 C   r   )a  Accept the line regardless of where the cursor is. If this line
        is non-empty, it may be added to the history list for future recall
        with add_history(). If this line is a modified history line, the
        history line is restored to its original state.Tr   r4   r   r   r   accept_line      zNotEmacsMode.accept_linec                 C      | j | j dS )zCMove back through the history list, fetching the previous command. N)_historyprevious_historyr   r4   r   r   r   rE         zNotEmacsMode.previous_historyc                 C   rC   )zBMove forward through the history list, fetching the next command. N)rD   next_historyr   r4   r   r   r   rG      rF   zNotEmacsMode.next_historyc                 C   r2   )z&Move to the first line in the history.N)rD   beginning_of_historyr4   r   r   r   rH      r6   z!NotEmacsMode.beginning_of_historyc                 C   rC   )zUMove to the end of the input history, i.e., the line currently
        being entered.N)rD   end_of_historyr   r4   r   r   r   rI      s   zNotEmacsMode.end_of_historyc                 C   sZ  | j }|  }d}| jj}	 | j\}}	|d|	 |dk r d}
nd}
|d|
||f }| | |   |	 }|j
dkrTt|dkrO|d d }|| j_n:|   n5|jtjtj tj d	 v rl|| j_||j7 }n|j|jkr| j j|7  _||}n
|j
d
kr|   n||}q| j\}}|d| | j| |   t| jj| j_d S )Nr$   Tr   zreverse-i-searchzforward-i-searchz
%s`%s': %s	BackSpace Return)r   Zget_line_bufferrD   Zhistory_cursorZprompt_end_posposZwrite_scrollingZ_update_prompt_posZ_clear_afterr   Zkeysymr-   _bellcharstringlettersdigitspunctuationr   Zprompt_begin_posr   Zset_liner+   history)r   Z	searchfun	directionZ
init_eventr   linequeryZhc_startxyr*   scrollr   Zpxpyr   r   r   	_i_search   sH   






 zNotEmacsMode._i_searchc                 C      |  | jjd| dS )zSearch backward starting at the current line and moving up
        through the history as necessary. This is an incremental search.rK   N)r]   rD   reverse_search_historyr4   r   r   r   r_         z#NotEmacsMode.reverse_search_historyc                 C   r^   )zSearch forward starting at the current line and moving down
        through the the history as necessary. This is an incremental search.r   N)r]   rD   forward_search_historyr4   r   r   r   ra      r`   z#NotEmacsMode.forward_search_historyc                 C   rC   )zSearch backward starting at the current line and moving up
        through the history as necessary using a non-incremental search for
        a string supplied by the user.NrD   &non_incremental_reverse_search_historyr   r4   r   r   r   rc         z3NotEmacsMode.non_incremental_reverse_search_historyc                 C   rC   )zSearch forward starting at the current line and moving down
        through the the history as necessary using a non-incremental search
        for a string supplied by the user.Nrb   r4   r   r   r   &non_incremental_forward_search_history   rd   z3NotEmacsMode.non_incremental_forward_search_historyc                 C      | j | j| _dS )zSearch forward through the history for the string of characters
        between the start of the current line and the point. This is a
        non-incremental search. By default, this command is unbound.N)rD   history_search_forwardr   r4   r   r   r   rg         z#NotEmacsMode.history_search_forwardc                 C   rf   )zSearch backward through the history for the string of characters
        between the start of the current line and the point. This is a
        non-incremental search. By default, this command is unbound.N)rD   history_search_backwardr   r4   r   r   r   ri      rh   z$NotEmacsMode.history_search_backwardc                 C   r   )aR  Insert the first argument to the previous command (usually the
        second word on the previous line) at point. With an argument n,
        insert the nth word from the previous command (the words in the
        previous command begin with word 0). A negative argument inserts the
        nth word from the end of the previous command.Nr   r4   r   r   r   yank_nth_arg   s   zNotEmacsMode.yank_nth_argc                 C   r   )a  Insert last argument to the previous command (the last word of
        the previous history entry). With an argument, behave exactly like
        yank-nth-arg. Successive calls to yank-last-arg move back through
        the history list, inserting the last argument of each line in turn.Nr   r4   r   r   r   yank_last_arg   rB   zNotEmacsMode.yank_last_argc                 C   r2   )zDelete the character at point. If point is at the beginning of
        the line, there are no characters in the line, and the last
        character typed was not bound to delete-char, then return EOF.N)r   delete_charr4   r   r   r   rl        zNotEmacsMode.delete_charc                 C   r2   )zyDelete the character behind the cursor. A numeric argument means
        to kill the characters instead of deleting them.N)r   backward_delete_charr4   r   r   r   rn     r;   z!NotEmacsMode.backward_delete_charc                 C   r   )zDelete the character under the cursor, unless the cursor is at
        the end of the line, in which case the character behind the cursor
        is deleted. By default, this is not bound to a key.Nr   r4   r   r   r   forward_backward_delete_char     z)NotEmacsMode.forward_backward_delete_charc                 C   s   | j  }| |j dS )zuAdd the next character typed to the line verbatim. This is how to
        insert key sequences like C-q, for example.N)r   r   insert_textrP   r4   r   r   r   quoted_insert  s   
zNotEmacsMode.quoted_insertc                 C   s8   t | jjt| jj}d| j|| j   }| | dS )zInsert a tab character. rL   N)minr   pointr-   line_bufferZtabstoprq   )r   r5   cursorwsr   r   r   
tab_insert  s   zNotEmacsMode.tab_insertc                 C   s"   t |jdkr| |j dS dS )zInsert yourself. r   N)ordrP   rq   r4   r   r   r   r     s   zNotEmacsMode.self_insertc                 C   r2   )a  Drag the character before the cursor forward over the character
        at the cursor, moving the cursor forward as well. If the insertion
        point is at the end of the line, then this transposes the last two
        characters of the line. Negative arguments have no effect.N)r   transpose_charsr4   r   r   r   rz   %  s   zNotEmacsMode.transpose_charsc                 C   r2   )zDrag the word before point past the word after point, moving
        point past that word as well. If the insertion point is at the end
        of the line, this transposes the last two words on the line.N)r   transpose_wordsr4   r   r   r   r{   ,  rm   zNotEmacsMode.transpose_wordsc                 C   r2   )zUppercase the current (or following) word. With a negative
        argument, uppercase the previous word, but do not move the cursor.N)r   upcase_wordr4   r   r   r   r|   2  r;   zNotEmacsMode.upcase_wordc                 C   r2   )zLowercase the current (or following) word. With a negative
        argument, lowercase the previous word, but do not move the cursor.N)r   downcase_wordr4   r   r   r   r}   7  r;   zNotEmacsMode.downcase_wordc                 C   r2   )zCapitalize the current (or following) word. With a negative
        argument, capitalize the previous word, but do not move the cursor.N)r   capitalize_wordr4   r   r   r   r~   <  r;   zNotEmacsMode.capitalize_wordc                 C   r   )a*  Toggle overwrite mode. With an explicit positive numeric
        argument, switches to overwrite mode. With an explicit non-positive
        numeric argument, switches to insert mode. This command affects only
        emacs mode; vi mode does overwrite differently. Each call to
        readline() starts in insert mode. In overwrite mode, characters
        bound to self-insert replace the text at point rather than pushing
        the text to the right. Characters bound to backward-delete-char
        replace the character before point with a space.Nr   r4   r   r   r   overwrite_modeA  s   	zNotEmacsMode.overwrite_modec                 C   r2   )z1Kill the text from point to the end of the line. N)r   	kill_liner4   r   r   r   r   L  r6   zNotEmacsMode.kill_linec                 C   r2   )z,Kill backward to the beginning of the line. N)r   backward_kill_liner4   r   r   r   r   P  r6   zNotEmacsMode.backward_kill_linec                 C   r2   )zDKill backward from the cursor to the beginning of the current line. N)r   unix_line_discardr4   r   r   r   r   T  r;   zNotEmacsMode.unix_line_discardc                 C   r2   )zgKill all characters on the current line, no matter where point
        is. By default, this is unbound.N)r   kill_whole_liner4   r   r   r   r   Y  r;   zNotEmacsMode.kill_whole_linec                 C   r2   )zKill 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.N)r   	kill_wordr4   r   r   r   r   ^  rm   zNotEmacsMode.kill_wordc                 C   r2   )zSKill the word behind point. Word boundaries are the same as
        backward-word. N)r   backward_kill_wordr4   r   r   r   r   d  r;   zNotEmacsMode.backward_kill_wordc                 C   r2   )ztKill the word behind point, using white space as a word
        boundary. The killed text is saved on the kill-ring.N)r   unix_word_ruboutr4   r   r   r   r   i  r;   zNotEmacsMode.unix_word_ruboutc                 C   r   )zFDelete all spaces and tabs around point. By default, this is unbound. Nr   r4   r   r   r   delete_horizontal_spacen  r@   z$NotEmacsMode.delete_horizontal_spacec                 C   r   )zJKill the text in the current region. By default, this command is unbound. Nr   r4   r   r   r   kill_regionr  r@   zNotEmacsMode.kill_regionc                 C   r   )z|Copy the text in the region to the kill buffer, so it can be
        yanked right away. By default, this command is unbound.Nr   r4   r   r   r   copy_region_as_killv     z NotEmacsMode.copy_region_as_killc                 C   s   | j r?t| jjt| jj}t| jjt| jj}| jjdkr!dS t||}t||}d| jj|| }t	
t| dS dS )z5Copy the text in the region to the windows clipboard.rK   Nr$   )enable_win32_clipboardrs   r   markr-   ru   rt   maxjoin	clipboardZSetClipboardTextstr)r   r5   r   rv   beginendZtoclipboardr   r   r   copy_region_to_clipboard{  s   

z%NotEmacsMode.copy_region_to_clipboardc                 C   r   )zCopy the word before point to the kill buffer. The word
        boundaries are the same as backward-word. By default, this command
        is unbound.Nr   r4   r   r   r   copy_backward_word  rp   zNotEmacsMode.copy_backward_wordc                 C   r   )zCopy the word following point to the kill buffer. The word
        boundaries are the same as forward-word. By default, this command is
        unbound.Nr   r4   r   r   r   copy_forward_word  rp   zNotEmacsMode.copy_forward_wordc                 C   s"   | j rtd}| | dS dS )Paste windows clipboardFN)r   r   get_clipboard_text_and_convertrq   r   r5   txtr   r   r   paste  s   
zNotEmacsMode.pastec                 C   s   t d}| jr?td}||}dd |D }|dgkr=| |d  | | j	  |dd | _
td	| j
  d
S dS dS )r   z?
Fc                 S   s   g | ]
}|  d kr|qS r$   )strip).0rowr   r   r   
<listcomp>  s    z5NotEmacsMode.paste_mulitline_code.<locals>.<listcomp>r$   r   r   Nz	multi: %sT)recompiler   r   r   splitrq   r/   r   r0   r,   r   )r   r5   regr   tr   r   r   paste_mulitline_code  s   



z!NotEmacsMode.paste_mulitline_codec                 C   sZ   | j r+t| j}| jr$t|dk r$d|vr$d|vr$|dddd}| | dS dS )	zPaste windows clipboard. If enable_ipython_paste_list_of_lists is
        True then try to convert tabseparated data to repr of list of lists or
        repr of arrayi,  	r%   \/rL   z\ N)r   r   r   Z"enable_ipython_paste_list_of_listsZenable_ipython_paste_for_pathsr-   replacerq   r   r   r   r   ipython_paste  s   zNotEmacsMode.ipython_pastec                 C   r   )z8Yank the top of the kill ring into the buffer at point. Nr   r4   r   r   r   yank  r@   zNotEmacsMode.yankc                 C   r   )zrRotate the kill-ring, and yank the new top. You can only do this
        if the prior command is yank or yank-pop.Nr   r4   r   r   r   yank_pop  r   zNotEmacsMode.yank_popc                 C   r   )zuAdd this digit to the argument already accumulating, or start a
        new argument. M-- starts a negative argument.Nr   r4   r   r   r   digit_argument  r   zNotEmacsMode.digit_argumentc                 C   r   )a  This is another way to specify an argument. If this command is
        followed by one or more digits, optionally with a leading minus
        sign, those digits define the argument. If the command is followed
        by digits, executing universal-argument again ends the numeric
        argument, but is otherwise ignored. As a special case, if this
        command is immediately followed by a character that is neither a
        digit or minus sign, the argument count for the next command is
        multiplied by four. The argument count is initially one, so
        executing this function the first time makes the argument count
        four, a second time makes the argument count sixteen, and so on. By
        default, this is not bound to a key.Nr   r4   r   r   r   universal_argument  s   zNotEmacsMode.universal_argumentc                 C   r   )zDeletes the character under the cursor if not at the beginning or
        end of the line (like delete-char). If at the end of the line,
        behaves identically to possible-completions. This command is unbound
        by default.Nr   r4   r   r   r   delete_char_or_list  rB   z NotEmacsMode.delete_char_or_listc                 C   r   )zCBegin saving the characters typed into the current keyboard macro. Nr   r4   r   r   r   start_kbd_macro  r@   zNotEmacsMode.start_kbd_macroc                 C   r   )zaStop saving the characters typed into the current keyboard macro
        and save the definition.Nr   r4   r   r   r   end_kbd_macro  r   zNotEmacsMode.end_kbd_macroc                 C   r   )z}Re-execute the last keyboard macro defined, by making the
        characters in the macro appear as if typed at the keyboard.Nr   r4   r   r   r   call_last_kbd_macro  r   z NotEmacsMode.call_last_kbd_macroc                 C   r   )zsRead in the contents of the inputrc file, and incorporate any
        bindings or variable assignments found there.Nr   r4   r   r   r   re_read_init_file  r   zNotEmacsMode.re_read_init_filec                 C   s   |    dS )zrAbort the current editing command and ring the terminals bell
             (subject to the setting of bell-style).N)rO   r4   r   r   r   abort  s   zNotEmacsMode.abortc                 C   r   )zyIf the metafied character x is lowercase, run the command that is
        bound to the corresponding uppercase character.Nr   r4   r   r   r   do_uppercase_version  r   z!NotEmacsMode.do_uppercase_versionc                 C   s
   d| _ dS )z}Metafy the next character typed. This is for keyboards without a
        meta key. Typing ESC f is equivalent to typing M-f. TN)r   r4   r   r   r   prefix_meta  s   
zNotEmacsMode.prefix_metac                 C   r2   )z6Incremental undo, separately remembered for each line.N)r   Zpop_undor4   r   r   r   undo  r6   zNotEmacsMode.undoc                 C   r   )z~Undo all changes made to this line. This is like executing the
        undo command enough times to get back to the beginning.Nr   r4   r   r   r   revert_line  r   zNotEmacsMode.revert_linec                 C   r   )z,Perform tilde expansion on the current word.Nr   r4   r   r   r   tilde_expand  r@   zNotEmacsMode.tilde_expandc                 C   r2   )zgSet the mark to the point. If a numeric argument is supplied, the
        mark is set to that position.N)r   set_markr4   r   r   r   r     r;   zNotEmacsMode.set_markc                 C   r   )zSwap the point with the mark. The current cursor position is set
        to the saved position, and the old cursor position is saved as the
        mark.Nr   r4   r   r   r   exchange_point_and_mark  rp   z$NotEmacsMode.exchange_point_and_markc                 C   r   )zA character is read and point is moved to the next occurrence of
        that character. A negative count searches for previous occurrences.Nr   r4   r   r   r   character_search  r   zNotEmacsMode.character_searchc                 C   r   )zA character is read and point is moved to the previous occurrence
        of that character. A negative count searches for subsequent
        occurrences.Nr   r4   r   r   r   character_search_backward  rp   z&NotEmacsMode.character_search_backwardc                 C   r   )a  Without a numeric argument, the value of the comment-begin
        variable is inserted at the beginning of the current line. If a
        numeric argument is supplied, this command acts as a toggle: if the
        characters at the beginning of the line do not match the value of
        comment-begin, the value is inserted, otherwise the characters in
        comment-begin are deleted from the beginning of the line. In either
        case, the line is accepted as if a newline had been typed.Nr   r4   r   r   r   insert_comment  s   zNotEmacsMode.insert_commentc                 C   r   )a  Print all of the functions and their key bindings to the Readline
        output stream. If a numeric argument is supplied, the output is
        formatted in such a way that it can be made part of an inputrc
        file. This command is unbound by default.Nr   r4   r   r   r   dump_functions'  rB   zNotEmacsMode.dump_functionsc                 C   r   )a  Print all of the settable variables and their values to the
        Readline output stream. If a numeric argument is supplied, the
        output is formatted in such a way that it can be made part of an
        inputrc file. This command is unbound by default.Nr   r4   r   r   r   dump_variables.  rB   zNotEmacsMode.dump_variablesc                 C   r   )a  Print all of the Readline key sequences bound to macros and the
        strings they output. If a numeric argument is supplied, the output
        is formatted in such a way that it can be made part of an inputrc
        file. This command is unbound by default.Nr   r4   r   r   r   dump_macros5  rB   zNotEmacsMode.dump_macrosc                 C   s   |  d |  d | d| j | d| j | d| j | d| j | d| j | d| j | d	| j | d
| j | d| j | d| j | d| j	 | d| j	 | d| j
 dS )zLWhen in vi command mode, this causes a switch to emacs editing
        mode.z	Control-dz	Control-zzShift-spacezControl-spacerM   Leftz	Control-bRightz	Control-frJ   ZHomeZEndDeleteZClearN)Z_bind_exit_keyZ	_bind_keyr   rA   r9   r8   rn   r3   r7   rl   r>   r4   r   r   r   init_editing_mode>  s   

zNotEmacsMode.init_editing_moder   )S__name__
__module____qualname__moder
   r   r#   r1   r3   r7   r8   r9   r:   r<   r>   r?   rA   rE   rG   rH   rI   r]   r_   ra   rc   re   rg   ri   rj   rk   rl   rn   ro   rr   rx   r   rz   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   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r   r   r   r   r      s    
++
	r   c                 C   sx   | sdS | d }| D ]/}t t|D ]&}|d|d   |d|d   kr8|d| }|dkr6  dS  nqq
|S )zGGiven a list of pathnames, returns the longest common leading componentr$   r   Nr   )ranger-   lower)mprefixitemir   r   r   commonprefixV  s   (r   )
__future__r   r   r   osZpyreadline3.lineeditor.historyZ
lineeditorrU   Zpyreadline3.lineeditor.lineobjr   Zpyreadline3.loggerloggerr   r$   r   ZBaseModer   r   r   r   r   r   <module>   s   	    D