mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
pyreadline-refactor: Fixes to make tests pass. One failure remains in vi_test.py
This commit is contained in:
@@ -1,3 +1,10 @@
|
||||
2006-10-19 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Fixed bug in history_search_*
|
||||
* Fixed bug in beginning_of_line_extend_selection and end_of_line_extend_selection
|
||||
* Fixd bugs to make vi_test work again, one test failure remains
|
||||
*
|
||||
|
||||
|
||||
2006-10-19 Jörgen Stenarson <jorgen.stenarson -at- bostream.nu>
|
||||
* Adding argument handling.
|
||||
* Adding argument to functions:forward_char, backward_char, forward_word, backward_word
|
||||
|
||||
@@ -97,8 +97,8 @@ def make_KeyPress_from_keydescr(keydescr):
|
||||
keydescr = keydescr[6:]
|
||||
else:
|
||||
if len(keydescr) > 1:
|
||||
if keydescr.strip() in validkey:
|
||||
keyinfo.keyname=keydescr.strip()
|
||||
if keydescr.strip().lower() in validkey:
|
||||
keyinfo.keyname=keydescr.strip().lower()
|
||||
keyinfo.char=""
|
||||
else:
|
||||
raise IndexError("Not a valid key: '%s'"%keydescr)
|
||||
|
||||
@@ -101,7 +101,7 @@ class LineHistory(object):
|
||||
def reverse_search_history(self,searchfor,startpos=None):
|
||||
if startpos is None:
|
||||
startpos=self.history_cursor
|
||||
res=[(idx,line) for idx,line in enumerate(self.history[startpos:0:-1]) if searchfor in line]
|
||||
res=[(idx,line) for idx,line in enumerate(self.history[startpos:0:-1]) if line.startswith(searchfor)]
|
||||
if res:
|
||||
self.history_cursor-=res[0][0]
|
||||
return res[0][1].get_line_text()
|
||||
@@ -110,7 +110,7 @@ class LineHistory(object):
|
||||
def forward_search_history(self,searchfor,startpos=None):
|
||||
if startpos is None:
|
||||
startpos=self.history_cursor
|
||||
res=[(idx,line) for idx,line in enumerate(self.history[startpos:]) if searchfor in line]
|
||||
res=[(idx,line) for idx,line in enumerate(self.history[startpos:]) if line.startswith(searchfor)]
|
||||
if res:
|
||||
self.history_cursor+=res[0][0]
|
||||
return res[0][1].get_line_text()
|
||||
@@ -167,7 +167,7 @@ class LineHistory(object):
|
||||
if (self.lastcommand != self.history_search_forward and
|
||||
self.lastcommand != self.history_search_backward):
|
||||
self.query = ''.join(partial[0:partial.point].get_line_text())
|
||||
hcstart=max(self.history_cursor-1,0)
|
||||
hcstart=max(self.history_cursor,0)
|
||||
hc = self.history_cursor + direction
|
||||
while (direction < 0 and hc >= 0) or (direction > 0 and hc < len(self.history)):
|
||||
h = self.history[hc]
|
||||
@@ -210,8 +210,9 @@ class LineHistory(object):
|
||||
if __name__=="__main__":
|
||||
q=LineHistory()
|
||||
RL=lineobj.ReadLineTextBuffer
|
||||
q.add_history(RL("apan"))
|
||||
q.add_history(RL("apbn"))
|
||||
q.add_history(RL("apcn"))
|
||||
q.add_history(RL("apdn"))
|
||||
q.add_history(RL("apen"))
|
||||
q.add_history(RL("aaaa"))
|
||||
q.add_history(RL("aaba"))
|
||||
q.add_history(RL("aaca"))
|
||||
q.add_history(RL("akca"))
|
||||
q.add_history(RL("bbb"))
|
||||
q.add_history(RL("ako"))
|
||||
|
||||
+11
-6
@@ -29,13 +29,18 @@ logsocket=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
|
||||
show_event=["keypress","bound_function","bind_key"]
|
||||
show_event=["bound_function"]
|
||||
|
||||
sock_silent=False
|
||||
|
||||
def log_sock(s,event_type=None):
|
||||
if event_type is None:
|
||||
logsocket.sendto(s,(host,port))
|
||||
elif event_type in show_event:
|
||||
logsocket.sendto(s,(host,port))
|
||||
else:
|
||||
if sock_silent:
|
||||
pass
|
||||
|
||||
else:
|
||||
if event_type is None:
|
||||
logsocket.sendto(s,(host,port))
|
||||
elif event_type in show_event:
|
||||
logsocket.sendto(s,(host,port))
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
log_sock("Starting pyreadline")
|
||||
@@ -265,11 +265,11 @@ class BaseMode(object):
|
||||
### Movement with extend selection
|
||||
def beginning_of_line_extend_selection(self, e): #
|
||||
'''Move to the start of the current line. '''
|
||||
self.l_buffer.beginning_of_line_extend_selection(self.argument_reset)
|
||||
self.l_buffer.beginning_of_line_extend_selection()
|
||||
|
||||
def end_of_line_extend_selection(self, e): #
|
||||
'''Move to the end of the line. '''
|
||||
self.l_buffer.end_of_line_extend_selection(self.argument_reset)
|
||||
self.l_buffer.end_of_line_extend_selection()
|
||||
|
||||
def forward_char_extend_selection(self, e): #
|
||||
'''Move forward a character. '''
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#*****************************************************************************
|
||||
import os
|
||||
import pyreadline.logger as logger
|
||||
from pyreadline.logger import log
|
||||
from pyreadline.logger import log,log_sock
|
||||
import pyreadline.lineeditor.lineobj as lineobj
|
||||
import pyreadline.lineeditor.history as history
|
||||
import basemode
|
||||
@@ -38,8 +38,8 @@ class ViMode(basemode.BaseMode):
|
||||
if lineobj.EndOfLine(self.l_buffer) == 0:
|
||||
raise EOFError
|
||||
|
||||
dispatch_func = self.key_dispatch.get(event.keyinfo,self.self_insert)
|
||||
log("readline from keyboard:%s"%(event.keyinfo,))
|
||||
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)
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
from pyreadline.modes.emacs import *
|
||||
from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
from pyreadline.keysyms import key_text_to_keyinfo
|
||||
from pyreadline.keysyms.common import make_KeyPress_from_keydescr
|
||||
|
||||
import unittest
|
||||
class MockReadline:
|
||||
def __init__ (self):
|
||||
@@ -51,16 +52,23 @@ class MockConsole:
|
||||
|
||||
class Event:
|
||||
def __init__ (self, char):
|
||||
self.char = char
|
||||
if char=="escape":
|
||||
self.char='\x1b'
|
||||
elif char=="backspace":
|
||||
self.char='\x08'
|
||||
else:
|
||||
self.char = char
|
||||
|
||||
def keytext_to_keyinfo_and_event (keytext):
|
||||
keyinfo = keysyms.key_text_to_keyinfo (keytext)
|
||||
keyinfo = keysyms.common.make_KeyPress_from_keydescr (keytext)
|
||||
if len(keytext) == 3 and keytext[0] == '"' and keytext[2] == '"':
|
||||
event = Event (keytext[1])
|
||||
else:
|
||||
event = Event (chr (keyinfo [3]))
|
||||
event = Event (keyinfo.tuple() [3])
|
||||
return keyinfo, event
|
||||
|
||||
|
||||
|
||||
#override runTests from from main in unittest to remove sys.exit call
|
||||
class Tester(unittest.TestProgram):
|
||||
def runTests(self):
|
||||
|
||||
@@ -51,10 +51,11 @@ class EmacsModeTest (EmacsMode):
|
||||
lst_key = [keytext]
|
||||
for key in lst_key:
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (key)
|
||||
dispatch_func = self.key_dispatch.get(keyinfo,self.self_insert)
|
||||
dispatch_func = self.key_dispatch.get(keyinfo.tuple(),self.self_insert)
|
||||
self.tested_commands[dispatch_func.__name__]=dispatch_func
|
||||
# print key,dispatch_func.__name__
|
||||
dispatch_func (event)
|
||||
log_sock("emacs readline from keyboard:%s->%s"%(keyinfo.tuple(),dispatch_func))
|
||||
self.previous_func=dispatch_func
|
||||
|
||||
def accept_line (self, e):
|
||||
@@ -318,4 +319,4 @@ if __name__ == '__main__':
|
||||
print " Not tested functions ".center(60,"-")
|
||||
print "\n".join(not_tested)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#*****************************************************************************
|
||||
|
||||
import sys, unittest
|
||||
import sys, unittest,pdb
|
||||
sys.path.append ('../..')
|
||||
from pyreadline.modes.vi import *
|
||||
from pyreadline import keysyms
|
||||
from pyreadline.lineeditor import lineobj
|
||||
from pyreadline.logger import log_sock
|
||||
import pyreadline.logger as logger
|
||||
from common import *
|
||||
|
||||
from common import *
|
||||
#----------------------------------------------------------------------
|
||||
@@ -49,7 +52,7 @@ class ViModeTest (ViMode):
|
||||
lst_key = [keytext]
|
||||
for key in lst_key:
|
||||
keyinfo, event = keytext_to_keyinfo_and_event (key)
|
||||
dispatch_func = self.key_dispatch [keyinfo]
|
||||
dispatch_func = self.key_dispatch.get( keyinfo.tuple(),self.vi_key)
|
||||
self.tested_commands[dispatch_func.__name__]=dispatch_func
|
||||
dispatch_func (event)
|
||||
|
||||
@@ -2140,4 +2143,4 @@ if __name__ == '__main__':
|
||||
print " Not tested functions ".center(60,"-")
|
||||
print "\n".join(not_tested)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user