diff --git a/pyreadline/__init__.py b/pyreadline/__init__.py index 8e7b9c8..7a50e1c 100644 --- a/pyreadline/__init__.py +++ b/pyreadline/__init__.py @@ -9,4 +9,3 @@ import unicode_helper, logger, clipboard, lineeditor, modes, console from rlmain import * import rlmain -import release diff --git a/pyreadline/lineeditor/history.py b/pyreadline/lineeditor/history.py index 92f41d3..3eae6dd 100644 --- a/pyreadline/lineeditor/history.py +++ b/pyreadline/lineeditor/history.py @@ -33,11 +33,27 @@ class LineHistory(object): self.lastcommand = None self.query = u"" + def get_current_history_length(self): + u'''Return the number of lines currently in the history. + (This is different from get_history_length(), which returns + the maximum number of lines that will be written to a history file.)''' + value = len(self.history) + log(u"get_current_history_length:%d"%value) + return value + def get_history_length(self): + u'''Return the desired length of the history file. Negative values imply + unlimited history file size.''' value = self._history_length log(u"get_history_length:%d"%value) return value + def get_history_item(self, index): + u'''Return the current contents of history item at index.''' + item = self.history[index] + log(u"get_history_item: index:%d item:%r"%(index, item)) + return item.get_line_text() + def set_history_length(self, value): log(u"set_history_length: old:%d new:%d"%(self._history_length, value)) self._history_length = value diff --git a/pyreadline/rlmain.py b/pyreadline/rlmain.py index 6ab21cf..3e1e387 100644 --- a/pyreadline/rlmain.py +++ b/pyreadline/rlmain.py @@ -128,6 +128,12 @@ class BaseReadline(object): u'''Append a line to the history buffer, as if it was the last line typed.''' self.mode._history.add_history(line) + def get_current_history_length(self ): + u'''Return the number of lines currently in the history. + (This is different from get_history_length(), which returns + the maximum number of lines that will be written to a history file.)''' + return self.mode._history.get_current_history_length() + def get_history_length(self ): u'''Return the desired length of the history file. @@ -142,6 +148,10 @@ class BaseReadline(object): ''' self.mode._history.set_history_length(length) + def get_history_item(self, index): + u'''Return the current contents of history item at index.''' + return self.mode._history.get_history_item(index) + def clear_history(self): u'''Clear readline history''' self.mode._history.clear_history() diff --git a/readline.py b/readline.py index 5c76f79..99db186 100644 --- a/readline.py +++ b/readline.py @@ -11,7 +11,9 @@ __all__ = [ 'parse_and_bind', 'read_init_file', 'read_history_file', 'write_history_file', + 'get_current_history_length', 'get_history_length', + 'get_history_item', 'set_history_length', 'set_startup_hook', 'set_pre_input_hook', @@ -54,7 +56,9 @@ else: read_history_file = rl.read_history_file get_completer_delims = rl.get_completer_delims + get_current_history_length = rl.get_current_history_length get_history_length = rl.get_history_length + get_history_item = rl.get_history_item get_line_buffer = rl.get_line_buffer set_completer = rl.set_completer get_completer = rl.get_completer