diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core.py | 57 | ||||
-rw-r--r-- | src/tabs.py | 28 | ||||
-rw-r--r-- | src/windows.py | 61 |
3 files changed, 100 insertions, 46 deletions
diff --git a/src/core.py b/src/core.py index 7af9e628..9de580b8 100644 --- a/src/core.py +++ b/src/core.py @@ -934,34 +934,67 @@ class Core(object): self.doupdate() def refresh_tab_win(self): + """ + Refresh the window containing the tab list + """ self.current_tab().refresh_tab_win() if self.current_tab().input: self.current_tab().input.refresh() self.doupdate() def scroll_page_down(self, args=None): - self.current_tab().on_scroll_down() - self.refresh_window() + """ + Scroll a page down, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_scroll_down(): + self.refresh_window() + return True def scroll_page_up(self, args=None): - self.current_tab().on_scroll_up() - self.refresh_window() + """ + Scroll a page up, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_scroll_up(): + self.refresh_window() + return True def scroll_line_up(self, args=None): - self.current_tab().on_line_up() - self.refresh_window() + """ + Scroll a line up, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_line_up(): + self.refresh_window() + return True def scroll_line_down(self, args=None): - self.current_tab().on_line_down() - self.refresh_window() + """ + Scroll a line down, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_line_down(): + self.refresh_window() + return True def scroll_half_up(self, args=None): - self.current_tab().on_half_scroll_up() - self.refresh_window() + """ + Scroll half a screen down, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_half_scroll_up(): + self.refresh_window() + return True def scroll_half_down(self, args=None): - self.current_tab().on_half_scroll_down() - self.refresh_window() + """ + Scroll half a screen down, if possible. + Returns True on success, None on failure. + """ + if self.current_tab().on_half_scroll_down(): + self.refresh_window() + return True def grow_information_win(self, nb=1): if self.information_win_size >= self.current_tab().height -5 or \ diff --git a/src/tabs.py b/src/tabs.py index 7eed1790..74475779 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -543,22 +543,22 @@ class ChatTab(Tab): raise NotImplementedError def on_line_up(self): - self.text_win.scroll_up(1) + return self.text_win.scroll_up(1) def on_line_down(self): - self.text_win.scroll_down(1) + return self.text_win.scroll_down(1) def on_scroll_up(self): - self.text_win.scroll_up(self.text_win.height-1) + return 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) + return self.text_win.scroll_down(self.text_win.height-1) def on_half_scroll_up(self): - self.text_win.scroll_up((self.text_win.height-1) // 2) + return self.text_win.scroll_up((self.text_win.height-1) // 2) def on_half_scroll_down(self): - self.text_win.scroll_down((self.text_win.height-1) // 2) + return self.text_win.scroll_down((self.text_win.height-1) // 2) def scroll_separator(self): self.text_win.scroll_to_separator() @@ -2359,14 +2359,10 @@ class RosterInfoTab(Tab): self.core.doupdate() def on_scroll_down(self): - for i in range(self.height-1): - self.roster_win.move_cursor_down() - return True + return self.roster_win.move_cursor_down(self.height // 2) def on_scroll_up(self): - for i in range(self.height-1): - self.roster_win.move_cursor_up() - return True + return self.roster_win.move_cursor_up(self.height // 2) def on_space(self): selected_row = self.roster_win.get_selected_row() @@ -2858,10 +2854,10 @@ class MucListTab(Tab): curses.curs_set(0) def on_scroll_up(self): - self.listview.scroll_up() + return self.listview.scroll_up() def on_scroll_down(self): - self.listview.scroll_down() + return self.listview.scroll_down() class XMLTab(Tab): @@ -2943,10 +2939,10 @@ class XMLTab(Tab): return True def on_scroll_up(self): - self.text_win.scroll_up(self.text_win.height-1) + return 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) + return self.text_win.scroll_down(self.text_win.height-1) def command_clear(self, args): """ diff --git a/src/windows.py b/src/windows.py index 03905d4b..a46edb1e 100644 --- a/src/windows.py +++ b/src/windows.py @@ -212,11 +212,14 @@ class UserList(Win): } def scroll_up(self): self.pos += self.height-1 + return True def scroll_down(self): + pos = self.pos self.pos -= self.height-1 if self.pos < 0: self.pos = 0 + return self.pos != pos def draw_plus(self, y): self.addstr(y, self.width-2, '++', to_curses_attr(get_theme().COLOR_MORE_INDICATOR)) @@ -714,16 +717,20 @@ class TextWin(Win): self.pos = 0 def scroll_up(self, dist=14): + pos = self.pos self.pos += dist if self.pos + self.height > len(self.built_lines): self.pos = len(self.built_lines) - self.height if self.pos < 0: self.pos = 0 + return self.pos != pos def scroll_down(self, dist=14): + pos = self.pos self.pos -= dist if self.pos <= 0: self.pos = 0 + return self.pos != pos def scroll_to_separator(self): """ @@ -1540,35 +1547,53 @@ class RosterWin(Win): self.roster_len = 0 self.selected_row = None - def move_cursor_down(self): + def move_cursor_down(self, number=1): """ Return True if we scrolled, False otherwise """ - if self.pos < self.roster_len-1: - self.pos += 1 + pos = self.pos + if self.pos < self.roster_len-number: + self.pos += number else: - return False - if self.pos == self.start_pos-1 + self.height-1: - self.scroll_down() - return True + self.pos = self.roster_len - 1 + if self.pos >= self.start_pos-1 + self.height-1: + if number == 1: + self.scroll_down(8) + else: + self.scroll_down(self.pos-self.start_pos - self.height // 2) + return pos != self.pos - def move_cursor_up(self): + def move_cursor_up(self, number=1): """ Return True if we scrolled, False otherwise """ - if self.pos > 0: - self.pos -= 1 + pos = self.pos + if self.pos-number >= 0: + self.pos -= number else: - return False - if self.pos == self.start_pos-2: - self.scroll_up() - return True + self.pos = 0 + if self.pos <= self.start_pos: + if number == 1: + self.scroll_up(8) + else: + self.scroll_up(self.start_pos-self.pos + self.height // 2) + return pos != self.pos - def scroll_down(self): - self.start_pos += 8 + def scroll_down(self, number=8): + pos = self.start_pos + if self.start_pos + number <= self.roster_len-1: + self.start_pos += number + else: + self.start_pos = self.roster_len-1 + return self.start_pos != pos - def scroll_up(self): - self.start_pos -= 8 + def scroll_up(self, number=8): + pos = self.start_pos + if self.start_pos - number > 0: + self.start_pos -= number + else: + self.start_pos = 1 + return self.start_pos != pos def refresh(self, roster): """ |