diff --git a/doc/ChangeLog b/doc/ChangeLog index 4adb9da..08927c1 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,9 +1,12 @@ +2006-10-25 Jörgen Stenarson + * port set_text_color and set_prompt_color config file options from trunk + * Fix bug in history search and add tests for the case. + * port ansi color changes from trunk + 2006-10-19 Jörgen Stenarson * 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 * Adding argument handling. diff --git a/pyreadline/console/ansi.py b/pyreadline/console/ansi.py index 413e4b6..e20bf10 100644 --- a/pyreadline/console/ansi.py +++ b/pyreadline/console/ansi.py @@ -84,9 +84,14 @@ class AnsiWriter(object): for chunk in chunks: m = escape_parts.match(chunk) if m: - for part in m.group(1).split(";"): + parts=m.group(1).split(";") + if len(parts)==1 and parts[0]=="0": + attr = self.defaultstate.copy() + continue + for part in parts: if part == "0": # No text attribute attr = self.defaultstate.copy() + attr.bold=False elif part == "7": # switch on reverse attr.inverse=True elif part == "1": # switch on bold (i.e. intensify foreground color) diff --git a/pyreadline/console/console.py b/pyreadline/console/console.py index e2b30a4..411c484 100644 --- a/pyreadline/console/console.py +++ b/pyreadline/console/console.py @@ -188,7 +188,8 @@ class Console(object): self.defaultstate=AnsiState() self.defaultstate.winattr=info.wAttributes self.ansiwriter=AnsiWriter(self.defaultstate) - +# self.ansiwriter.defaultstate.bold=False + background = self.attr & 0xf0 for escape in self.escape_to_color: if self.escape_to_color[escape] is not None: @@ -343,9 +344,12 @@ class Console(object): return n def write_color(self, text, attr=None): + log_sock(text) + log_sock("%s"%attr) n,res= self.ansiwriter.write_color(text,attr) junk = c_int(0) for attr,chunk in res: + log_sock("%s:%s"%(attr,chunk)) log(str(attr)) log(str(chunk)) self.SetConsoleTextAttribute(self.hout, attr.winattr) diff --git a/pyreadline/lineeditor/history.py b/pyreadline/lineeditor/history.py index 8facb74..fd1bccf 100644 --- a/pyreadline/lineeditor/history.py +++ b/pyreadline/lineeditor/history.py @@ -26,17 +26,32 @@ from pyreadline.logger import log_sock class LineHistory(object): def __init__(self): self.history=[] - self.history_length=100 - self.history_cursor=0 + self._history_length=100 + self._history_cursor=0 self.history_filename=os.path.expanduser('~/.history') self.lastcommand=None self.query="" def get_history_length(self): - return self.history_length + value=self._history_length + log_sock("get_history_length:%d"%value,"history") + return value def set_history_length(self,value): - self.history_length=value + log_sock("set_history_length: old:%d new:%d"%(self._history_length,value),"history") + self._history_length=value + + def get_history_cursor(self): + value=self._history_cursor + log_sock("get_history_cursor:%d"%value,"history") + return value + + def set_history_cursor(self,value): + log_sock("set_history_cursor: old:%d new:%d"%(self._history_cursor,value),"history") + self._history_cursor=value + + history_length=property(get_history_length,set_history_length) + history_cursor=property(get_history_cursor,set_history_cursor) def read_history_file(self, filename=None): '''Load a readline history file.''' @@ -184,6 +199,7 @@ class LineHistory(object): if len(self.history)==0: pass elif hc>=len(self.history) and not self.query: + self.history_cursor=len(self.history) return lineobj.ReadLineTextBuffer("",point=0) elif self.history[hcstart].get_line_text().startswith(self.query) and self.query: return lineobj.ReadLineTextBuffer(self.history[hcstart],point=partial.point) diff --git a/pyreadline/modes/basemode.py b/pyreadline/modes/basemode.py index 0e479d4..1683187 100644 --- a/pyreadline/modes/basemode.py +++ b/pyreadline/modes/basemode.py @@ -363,7 +363,8 @@ class BaseMode(object): def self_insert(self, e): # (a, b, A, 1, !, ...) '''Insert yourself. ''' - if ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys. + + if e.char and ord(e.char)!=0: #don't insert null character in buffer, can happen with dead keys. self.insert_text(e.char) diff --git a/pyreadline/rlmain.py b/pyreadline/rlmain.py index a502b54..3b394cc 100644 --- a/pyreadline/rlmain.py +++ b/pyreadline/rlmain.py @@ -366,7 +366,17 @@ class Readline(object): logger.start_log(on,filename) logger.log("STARTING LOG") # print release.branch + def set_prompt_color(color): + trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, + "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} + self.prompt_color=trtable.get(color.lower(),7) + + def set_input_color(color): + trtable={"black":0,"darkred":4,"darkgreen":2,"darkyellow":6,"darkblue":1,"darkmagenta":5,"darkcyan":3,"gray":7, + "red":4+8,"green":2+8,"yellow":6+8,"blue":1+8,"magenta":5+8,"cyan":3+8,"white":7+8} + self.command_color=trtable.get(color.lower(),7) loc={"branch":release.branch, + "version":release.version, "mode":mode, "modes":modes, "set_mode":setmode, @@ -380,7 +390,10 @@ class Readline(object): "completer_delims":completer_delims, "debug_output":debug_output, "history_filename":sethistoryfilename, - "history_length":sethistorylength} + "history_length":sethistorylength, + "set_prompt_color":set_prompt_color, + "set_input_color":set_input_color, + } if os.path.isfile(inputrcpath): try: execfile(inputrcpath,loc,loc) diff --git a/pyreadline/test/emacs_test.py b/pyreadline/test/emacs_test.py index 0c307d0..337c16f 100644 --- a/pyreadline/test/emacs_test.py +++ b/pyreadline/test/emacs_test.py @@ -45,7 +45,7 @@ class EmacsModeTest (EmacsMode): line_cursor = property (get_line_cursor) def input (self, keytext): - if keytext[0] == '"' and keytext[-1] == '"': + if keytext[0:1] == '"' and keytext[-1:] == '"': lst_key = ['"%s"' % c for c in keytext[1:-1]] else: lst_key = [keytext] @@ -254,51 +254,62 @@ class TestsHistory (unittest.TestCase): r.add_history ('akca') r.add_history ('bbb') r.add_history ('ako') - self.assertEqual (r.line, '') + self.assert_line(r,'',0) r.input ('"a"') r.input ('Up') - self.assertEqual (r.line, 'ako') - self.assertEqual (r.line_cursor, 1) + self.assert_line(r,'ako',1) r.input ('Up') - self.assertEqual (r.line, 'akca') - self.assertEqual (r.line_cursor, 1) + self.assert_line(r,'akca',1) r.input ('Up') - self.assertEqual (r.line, 'aaca') - self.assertEqual (r.line_cursor, 1) + self.assert_line(r,'aaca',1) r.input ('Up') - self.assertEqual (r.line, 'aaba') - self.assertEqual (r.line_cursor, 1) + self.assert_line(r,'aaba',1) r.input ('Up') - self.assertEqual (r.line, 'aaaa') - self.assertEqual (r.line_cursor, 1) + self.assert_line(r,'aaaa',1) r.input ('Right') - self.assertEqual (r.line, 'aaaa') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'aaaa',2) r.input ('Down') - self.assertEqual (r.line, 'aaba') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'aaba',2) r.input ('Down') - self.assertEqual (r.line, 'aaca') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'aaca',2) r.input ('Down') - self.assertEqual (r.line, 'aaca') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'aaca',2) r.input ('Left') r.input ('Left') r.input ('Down') r.input ('Down') - self.assertEqual (r.line, 'bbb') - self.assertEqual (r.line_cursor, 3) + self.assert_line(r,'bbb',3) r.input ('Left') - self.assertEqual (r.line, 'bbb') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'bbb',2) r.input ('Down') - self.assertEqual (r.line, 'bbb') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'bbb',2) r.input ('Up') - self.assertEqual (r.line, 'bbb') - self.assertEqual (r.line_cursor, 2) + self.assert_line(r,'bbb',2) + + def test_history_3 (self): + r = EmacsModeTest () + r.add_history ('aaaa') + r.add_history ('aaba') + r.add_history ('aaca') + r.add_history ('akca') + r.add_history ('bbb') + r.add_history ('ako') + self.assert_line(r,'',0) + r.input ('') + r.input ('Up') + self.assert_line(r,'ako',3) + r.input ('Down') + self.assert_line(r,'',0) + r.input ('Up') + self.assert_line(r,'ako',3) + + + + def assert_line(self,r,line,cursor): + self.assertEqual (r.line, line) + self.assertEqual (r.line_cursor, cursor) + #---------------------------------------------------------------------- # utility functions