page: methods to go to beginning/end of page
This commit is contained in:
parent
8fdf23689d
commit
ff49f0d17e
|
@ -2,6 +2,7 @@ import curses
|
||||||
import curses.ascii
|
import curses.ascii
|
||||||
import curses.textpad
|
import curses.textpad
|
||||||
import os
|
import os
|
||||||
|
from math import inf
|
||||||
|
|
||||||
from bebop.colors import ColorPair, init_colors
|
from bebop.colors import ColorPair, init_colors
|
||||||
from bebop.command_line import (CommandLine, EscapeCommandInterrupt,
|
from bebop.command_line import (CommandLine, EscapeCommandInterrupt,
|
||||||
|
@ -94,6 +95,12 @@ class Browser:
|
||||||
self.quick_command("open")
|
self.quick_command("open")
|
||||||
elif char == ord("H"):
|
elif char == ord("H"):
|
||||||
self.go_back()
|
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):
|
elif curses.ascii.isdigit(char):
|
||||||
self.handle_digit_input(char)
|
self.handle_digit_input(char)
|
||||||
elif char == curses.KEY_MOUSE:
|
elif char == curses.KEY_MOUSE:
|
||||||
|
@ -409,11 +416,19 @@ class Browser:
|
||||||
self.screen.refresh()
|
self.screen.refresh()
|
||||||
self.refresh_windows()
|
self.refresh_windows()
|
||||||
|
|
||||||
def scroll_page_vertically(self, by_lines: int):
|
def scroll_page_vertically(self, by_lines):
|
||||||
if self.page.scroll_v(by_lines, self.h - 2):
|
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()
|
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):
|
if self.page.scroll_h(by_columns, self.w):
|
||||||
self.refresh_page()
|
self.refresh_page()
|
||||||
|
|
||||||
|
|
|
@ -78,3 +78,16 @@ class Page:
|
||||||
self.current_column = min(new_column, max_column)
|
self.current_column = min(new_column, max_column)
|
||||||
return True
|
return True
|
||||||
return False
|
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
|
||||||
|
|
Reference in a new issue