diff --git a/bebop/browser.py b/bebop/browser.py index 8f85dc8..b32299f 100644 --- a/bebop/browser.py +++ b/bebop/browser.py @@ -2,6 +2,7 @@ import curses import curses.ascii import curses.textpad import os +from math import inf from bebop.colors import ColorPair, init_colors from bebop.command_line import (CommandLine, EscapeCommandInterrupt, @@ -94,6 +95,12 @@ class Browser: self.quick_command("open") elif char == ord("H"): self.go_back() + elif char == ord("g"): + char = self.screen.getch() + if char == ord("g"): + self.scroll_page_vertically(-inf) + elif char == ord("G"): + self.scroll_page_vertically(inf) elif curses.ascii.isdigit(char): self.handle_digit_input(char) elif char == curses.KEY_MOUSE: @@ -409,11 +416,19 @@ class Browser: self.screen.refresh() self.refresh_windows() - def scroll_page_vertically(self, by_lines: int): - if self.page.scroll_v(by_lines, self.h - 2): + def scroll_page_vertically(self, by_lines): + window_height = self.h - 2 + require_refresh = False + if by_lines == inf: + require_refresh = self.page.go_to_end(window_height) + elif by_lines == -inf: + require_refresh = self.page.go_to_beginning() + else: + require_refresh = self.page.scroll_v(by_lines, window_height) + if require_refresh: self.refresh_page() - def scroll_page_horizontally(self, by_columns: int): + def scroll_page_horizontally(self, by_columns): if self.page.scroll_h(by_columns, self.w): self.refresh_page() diff --git a/bebop/page.py b/bebop/page.py index 2de27d0..a047a85 100644 --- a/bebop/page.py +++ b/bebop/page.py @@ -78,3 +78,16 @@ class Page: self.current_column = min(new_column, max_column) return True return False + + def go_to_beginning(self): + if self.current_line: + self.current_line = 0 + return True + return False + + def go_to_end(self, window_height): + max_line = self.dim[0] - window_height + if self.current_line != max_line: + self.current_line = max_line + return True + return False