From 8478641ad0bdeebea7d79422e3174243b4508a91 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 16 Feb 2012 00:04:59 +0100 Subject: Add shortcuts to browse the history one line at a time (C-b / C-f) --- doc/en/keys.txt | 4 ++++ src/core.py | 10 ++++++++++ src/tabs.py | 46 ++++++++++++++++++++++++++-------------------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/doc/en/keys.txt b/doc/en/keys.txt index 074c9559..616468f5 100644 --- a/doc/en/keys.txt +++ b/doc/en/keys.txt @@ -82,6 +82,10 @@ height of the conversation window - 1. *Page Down*:: Like Page Up, but down. +*Ctrl-b*:: Go one line up in the buffer. + +*Ctrl-f*:: Go one line down in the buffer. + *Alt-/*:: Complete what you’re typing using the "recent" words from the current conversation, if any. diff --git a/src/core.py b/src/core.py index 0b5bb37b..91f69813 100644 --- a/src/core.py +++ b/src/core.py @@ -156,6 +156,8 @@ class Core(object): self.key_func = { "KEY_PPAGE": self.scroll_page_up, "KEY_NPAGE": self.scroll_page_down, + "^B": self.scroll_line_up, + "^F": self.scroll_line_down, "KEY_F(5)": self.rotate_rooms_left, "^P": self.rotate_rooms_left, 'kLFT3': self.rotate_rooms_left, @@ -1130,6 +1132,14 @@ class Core(object): self.current_tab().on_scroll_up() self.refresh_window() + def scroll_line_up(self, args=None): + self.current_tab().on_line_up() + self.refresh_window() + + def scroll_line_down(self, args=None): + self.current_tab().on_line_down() + self.refresh_window() + def get_error_message_from_error_stanza(self, stanza): """ Takes a stanza of the form diff --git a/src/tabs.py b/src/tabs.py index 492a4412..f9032b6e 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -302,13 +302,25 @@ class Tab(object): def on_scroll_down(self): """ - Defines what happens when we scrol down + Defines what happens when we scroll down """ pass def on_scroll_up(self): """ - Defines what happens when we scrol down + Defines what happens when we scroll up + """ + pass + + def on_line_up(self): + """ + Defines what happens when we scroll one line up + """ + pass + + def on_line_down(self): + """ + Defines what happens when we scroll one line up """ pass @@ -505,6 +517,18 @@ class ChatTab(Tab): def command_say(self, line): raise NotImplementedError + def on_line_up(self): + self.text_win.scroll_up(1) + + def on_line_down(self): + self.text_win.scroll_down(1) + + def on_scroll_up(self): + self.text_win.scroll_up(self.text_win.height-1) + + def on_scroll_down(self): + self.text_win.scroll_down(self.text_win.height-1) + class MucTab(ChatTab): """ @@ -1055,12 +1079,6 @@ class MucTab(ChatTab): if self.joined and config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and not self.input.get_text(): self.send_chat_state('active') - def on_scroll_up(self): - self.text_win.scroll_up(self.text_win.height-1) - - def on_scroll_down(self): - self.text_win.scroll_down(self.text_win.height-1) - def on_info_win_size_changed(self): if self.core.information_win_size >= self.height-3: return @@ -1555,12 +1573,6 @@ class PrivateTab(ChatTab): if tab and tab.joined and config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and not self.input.get_text(): self.send_chat_state('active') - def on_scroll_up(self): - self.text_win.scroll_up(self.text_win.height-1) - - def on_scroll_down(self): - self.text_win.scroll_down(self.text_win.height-1) - def on_info_win_size_changed(self): if self.core.information_win_size >= self.height-3: return @@ -2340,12 +2352,6 @@ class ConversationTab(ChatTab): if resource: self.send_chat_state('active') - def on_scroll_up(self): - self.text_win.scroll_up(self.text_win.height-1) - - def on_scroll_down(self): - self.text_win.scroll_down(self.text_win.height-1) - def on_info_win_size_changed(self): if self.core.information_win_size >= self.height-3: return -- cgit v1.2.3