browser: rework default movement keys

This commit is contained in:
dece 2021-03-13 18:58:02 +01:00
parent bcc9a72d97
commit 33f215dd3e

View file

@ -84,35 +84,33 @@ class Browser:
elif char == ord("r"): elif char == ord("r"):
self.reload_page() self.reload_page()
elif char == ord("h"): elif char == ord("h"):
self.scroll_page_horizontally(-1)
elif char == ord("H"):
self.scroll_page_horizontally(-3) self.scroll_page_horizontally(-3)
elif char == ord("H"):
pass # TODO h-scroll whole page left
elif char == ord("j"): elif char == ord("j"):
self.scroll_page_vertically(1)
elif char == ord("J"):
self.scroll_page_vertically(3) self.scroll_page_vertically(3)
elif char == ord("J"):
self.scroll_whole_page_down()
elif char == ord("k"): elif char == ord("k"):
self.scroll_page_vertically(-1)
elif char == ord("K"):
self.scroll_page_vertically(-3) self.scroll_page_vertically(-3)
elif char == ord("K"):
self.scroll_whole_page_up()
elif char == ord("l"): elif char == ord("l"):
self.scroll_page_horizontally(1)
elif char == ord("L"):
self.scroll_page_horizontally(3) self.scroll_page_horizontally(3)
elif char == ord("f"): elif char == ord("L"):
self.scroll_page_vertically(self.page_pad_size[0]) pass # TODO h-scroll whole page right
elif char == ord("b"): elif char == ord("^"):
self.scroll_page_vertically(-self.page_pad_size[0]) pass # TODO reset horizontal scrolling
elif char == ord("o"):
self.quick_command("open")
elif char == ord("p"):
self.go_back()
elif char == ord("g"): elif char == ord("g"):
char = self.screen.getch() char = self.screen.getch()
if char == ord("g"): if char == ord("g"):
self.scroll_page_vertically(-inf) self.scroll_page_vertically(-inf)
elif char == ord("G"): elif char == ord("G"):
self.scroll_page_vertically(inf) self.scroll_page_vertically(inf)
elif char == ord("o"):
self.quick_command("open")
elif char == ord("p"):
self.go_back()
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:
@ -121,13 +119,24 @@ class Browser:
self.handle_resize() self.handle_resize()
elif char == curses.ascii.ESC: # Can be ESC or ALT char. elif char == curses.ascii.ESC: # Can be ESC or ALT char.
self.screen.nodelay(True) self.screen.nodelay(True)
ch = self.screen.getch() char = self.screen.getch()
if ch == -1: if char == -1:
self.set_status(self.current_url) self.set_status(self.current_url)
else: else: # ALT keybinds.
pass # No alt-key shortcuts for now! if char == ord("h"):
self.scroll_page_horizontally(-1)
elif char == ord("j"):
self.scroll_page_vertically(1)
elif char == ord("k"):
self.scroll_page_vertically(-1)
elif char == ord("l"):
self.scroll_page_horizontally(1)
self.screen.nodelay(False) self.screen.nodelay(False)
ctrl_char = curses.unctrl(char)
if ctrl_char == "a":
self.set_status("yup!")
@property @property
def page_pad_size(self): def page_pad_size(self):
return self.h - 3, self.w - 1 return self.h - 3, self.w - 1
@ -383,6 +392,14 @@ class Browser:
if require_refresh: if require_refresh:
self.refresh_page() self.refresh_page()
def scroll_whole_page_down(self):
"""Scroll down by a whole page."""
self.scroll_page_vertically(self.page_pad_size[0])
def scroll_whole_page_up(self):
"""Scroll up by a whole page."""
self.scroll_page_vertically(-self.page_pad_size[0])
def scroll_page_horizontally(self, by_columns): def scroll_page_horizontally(self, by_columns):
"""Scroll page horizontally.""" """Scroll page horizontally."""
if self.page.scroll_h(by_columns, self.w): if self.page.scroll_h(by_columns, self.w):