mirror of
https://github.com/wassname/pyreadline.git
synced 2026-07-21 12:40:29 +08:00
change vi mode to use process_keyevent and the default readline method from modes.basemode
This commit is contained in:
@@ -34,7 +34,7 @@ class EmacsMode(basemode.BaseMode):
|
||||
self.previous_func=None
|
||||
self.prompt=">>>"
|
||||
self._insert_verbatim=False
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<EmacsMode>"
|
||||
|
||||
@@ -56,6 +56,7 @@ class EmacsMode(basemode.BaseMode):
|
||||
return False
|
||||
|
||||
if keytuple in self.exit_dispatch:
|
||||
log_sock("exit_dispatch:%s, %s"%(self.l_buffer,lineobj.EndOfLine(self.l_buffer)))
|
||||
if lineobj.EndOfLine(self.l_buffer) == 0:
|
||||
raise EOFError
|
||||
if keyinfo.keyname:
|
||||
@@ -78,7 +79,6 @@ class EmacsMode(basemode.BaseMode):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
######### History commands
|
||||
def previous_history(self, e): # (C-p)
|
||||
'''Move back through the history list, fetching the previous command. '''
|
||||
|
||||
+22
-66
@@ -23,73 +23,29 @@ class ViMode(basemode.BaseMode):
|
||||
def __repr__(self):
|
||||
return "<ViMode>"
|
||||
|
||||
def _readline_from_keyboard(self):
|
||||
c=self.console
|
||||
while 1:
|
||||
def process_keyevent(self, keyinfo):
|
||||
def nop(e):
|
||||
pass
|
||||
keytuple=keyinfo.tuple()
|
||||
|
||||
#Process exit keys. Only exit on empty line
|
||||
if keytuple in self.exit_dispatch:
|
||||
if lineobj.EndOfLine(self.l_buffer) == 0:
|
||||
raise EOFError
|
||||
|
||||
dispatch_func = self.key_dispatch.get(keytuple,self.vi_key)
|
||||
log("readline from keyboard:%s->%s"%(keytuple,dispatch_func))
|
||||
r = None
|
||||
if dispatch_func:
|
||||
r = dispatch_func(keyinfo)
|
||||
self.l_buffer.push_undo()
|
||||
|
||||
self.previous_func = dispatch_func
|
||||
if r:
|
||||
self._update_line()
|
||||
event = c.getkeypress()
|
||||
if self.next_meta:
|
||||
self.next_meta = False
|
||||
control, meta, shift, code = event.keyinfo
|
||||
event.keyinfo = (control, True, shift, code)
|
||||
|
||||
#Process exit keys. Only exit on empty line
|
||||
if event.keyinfo in self.exit_dispatch:
|
||||
if lineobj.EndOfLine(self.l_buffer) == 0:
|
||||
raise EOFError
|
||||
|
||||
dispatch_func = self.key_dispatch.get(event.keyinfo.tuple(),self.vi_key)
|
||||
log("readline from keyboard:%s->%s"%(event.keyinfo.tuple(),dispatch_func))
|
||||
r = None
|
||||
if dispatch_func:
|
||||
r = dispatch_func(event)
|
||||
self.l_buffer.push_undo()
|
||||
|
||||
self.previous_func = dispatch_func
|
||||
if r:
|
||||
self._update_line()
|
||||
break
|
||||
|
||||
def readline(self, prompt=''):
|
||||
'''Try to act like GNU readline.'''
|
||||
# handle startup_hook
|
||||
if self.first_prompt:
|
||||
self.first_prompt = False
|
||||
if self.startup_hook:
|
||||
try:
|
||||
self.startup_hook()
|
||||
except:
|
||||
print 'startup hook failed'
|
||||
traceback.print_exc()
|
||||
|
||||
c = self.console
|
||||
self.l_buffer.reset_line()
|
||||
self.prompt = prompt
|
||||
self._print_prompt()
|
||||
|
||||
if self.pre_input_hook:
|
||||
try:
|
||||
self.pre_input_hook()
|
||||
except:
|
||||
print 'pre_input_hook failed'
|
||||
traceback.print_exc()
|
||||
self.pre_input_hook = None
|
||||
|
||||
log("in readline: %s"%self.paste_line_buffer)
|
||||
if len(self.paste_line_buffer)>0:
|
||||
self.l_buffer=lineobj.ReadlineTextBuffer(self.paste_line_buffer[0])
|
||||
self._update_line()
|
||||
self.paste_line_buffer=self.paste_line_buffer[1:]
|
||||
c.write('\r\n')
|
||||
else:
|
||||
self._readline_from_keyboard()
|
||||
c.write('\r\n')
|
||||
|
||||
self.add_history(self.l_buffer.copy())
|
||||
|
||||
log('returning(%s)' % self.l_buffer.get_line_text())
|
||||
return self.l_buffer.get_line_text() + '\n'
|
||||
|
||||
return True
|
||||
return False
|
||||
|
||||
### Methods below here are bindable emacs functions
|
||||
|
||||
def init_editing_mode(self, e): # (M-C-j)
|
||||
|
||||
Reference in New Issue
Block a user