diff options
author | mathieui <mathieui@mathieui.net> | 2011-09-12 00:55:00 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2011-09-12 00:55:00 +0200 |
commit | a20b42d2b4bf42fc9d6b9883439235fe43b7f533 (patch) | |
tree | 9dae8ee9b93600199e23ea022aad6e9c4d89679b | |
parent | 71ed190f30bc41a62da6c45089895b76b5b8b18d (diff) | |
download | poezio-a20b42d2b4bf42fc9d6b9883439235fe43b7f533.tar.gz poezio-a20b42d2b4bf42fc9d6b9883439235fe43b7f533.tar.bz2 poezio-a20b42d2b4bf42fc9d6b9883439235fe43b7f533.tar.xz poezio-a20b42d2b4bf42fc9d6b9883439235fe43b7f533.zip |
Add an history in the RosterInfoTab (Fixes #2223)
-rw-r--r-- | src/tabs.py | 1 | ||||
-rw-r--r-- | src/windows.py | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/src/tabs.py b/src/tabs.py index dc20b65f..37c5e888 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1378,6 +1378,7 @@ class RosterInfoTab(Tab): def execute_slash_command(self, txt): if txt.startswith('/'): + self.input.key_enter() self.execute_command(txt) return self.reset_help_message() diff --git a/src/windows.py b/src/windows.py index 29f80007..89fb368c 100644 --- a/src/windows.py +++ b/src/windows.py @@ -1160,6 +1160,8 @@ class CommandInput(Input): HelpMessage when a command is started The on_input callback """ + history = list() + def __init__(self, help_message, on_abort, on_success, on_input=None): Input.__init__(self) self.on_abort = on_abort @@ -1169,6 +1171,11 @@ class CommandInput(Input): self.key_func['^M'] = self.success self.key_func['^G'] = self.abort self.key_func['^C'] = self.abort + self.key_func["KEY_UP"] = self.key_up + self.key_func["M-A"] = self.key_up + self.key_func["KEY_DOWN"] = self.key_down + self.key_func["M-B"] = self.key_down + self.histo_pos = -1 def do_command(self, key): res = Input.do_command(self, key) @@ -1223,6 +1230,46 @@ class CommandInput(Input): self.on_input = None self.key_func.clear() + def key_up(self): + """ + Get the previous line in the history + """ + self.reset_completion() + if self.histo_pos == -1 and self.get_text(): + if not self.history or self.history[0] != self.get_text(): + # add the message to history, we do not want to lose it + self.history.insert(0, self.get_text()) + self.histo_pos += 1 + if self.histo_pos < len(self.history) - 1: + self.histo_pos += 1 + self.text = self.history[self.histo_pos] + self.key_end() + + def key_down(self): + """ + Get the next line in the history + """ + self.reset_completion() + if self.histo_pos > 0: + self.histo_pos -= 1 + self.text = self.history[self.histo_pos] + elif self.histo_pos <= 0 and self.get_text(): + if not self.history or self.history[0] != self.get_text(): + # add the message to history, we do not want to lose it + self.history.insert(0, self.get_text()) + self.text = '' + self.histo_pos = -1 + self.key_end() + + def key_enter(self): + txt = self.get_text() + if len(txt) != 0: + if not self.history or self.history[0] != txt: + # add the message to history, but avoid duplicates + self.history.insert(0, txt) + self.histo_pos = -1 + + class VerticalSeparator(Win): """ Just a one-column window, with just a line in it, that is |