browser: capture C-c
This commit is contained in:
parent
398f526b82
commit
2db721d48a
|
@ -69,49 +69,61 @@ class Browser:
|
||||||
self.open_url(start_url, assume_absolute=True)
|
self.open_url(start_url, assume_absolute=True)
|
||||||
|
|
||||||
while self.running:
|
while self.running:
|
||||||
|
try:
|
||||||
|
self.handle_inputs()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self.set_status("Cancelled.")
|
||||||
|
|
||||||
|
def handle_inputs(self):
|
||||||
|
char = self.screen.getch()
|
||||||
|
if char == ord(":"):
|
||||||
|
self.quick_command("")
|
||||||
|
elif char == ord("r"):
|
||||||
|
self.reload_page()
|
||||||
|
elif char == ord("h"):
|
||||||
|
self.scroll_page_horizontally(-1)
|
||||||
|
elif char == ord("H"):
|
||||||
|
self.scroll_page_horizontally(-3)
|
||||||
|
elif char == ord("j"):
|
||||||
|
self.scroll_page_vertically(1)
|
||||||
|
elif char == ord("J"):
|
||||||
|
self.scroll_page_vertically(3)
|
||||||
|
elif char == ord("k"):
|
||||||
|
self.scroll_page_vertically(-1)
|
||||||
|
elif char == ord("K"):
|
||||||
|
self.scroll_page_vertically(-3)
|
||||||
|
elif char == ord("l"):
|
||||||
|
self.scroll_page_horizontally(1)
|
||||||
|
elif char == ord("L"):
|
||||||
|
self.scroll_page_horizontally(3)
|
||||||
|
elif char == ord("f"):
|
||||||
|
self.scroll_page_vertically(self.page_pad_size[0])
|
||||||
|
elif char == ord("b"):
|
||||||
|
self.scroll_page_vertically(-self.page_pad_size[0])
|
||||||
|
elif char == ord("o"):
|
||||||
|
self.quick_command("open")
|
||||||
|
elif char == ord("p"):
|
||||||
|
self.go_back()
|
||||||
|
elif char == ord("g"):
|
||||||
char = self.screen.getch()
|
char = self.screen.getch()
|
||||||
if char == ord(":"):
|
if char == ord("g"):
|
||||||
self.quick_command("")
|
self.scroll_page_vertically(-inf)
|
||||||
elif char == ord("r"):
|
elif char == ord("G"):
|
||||||
self.reload_page()
|
self.scroll_page_vertically(inf)
|
||||||
elif char == ord("s"):
|
elif curses.ascii.isdigit(char):
|
||||||
self.set_status(f"h {self.h} w {self.w}")
|
self.handle_digit_input(char)
|
||||||
elif char == ord("h"):
|
elif char == curses.KEY_MOUSE:
|
||||||
self.scroll_page_horizontally(-1)
|
self.handle_mouse(*curses.getmouse())
|
||||||
elif char == ord("H"):
|
elif char == curses.KEY_RESIZE:
|
||||||
self.scroll_page_horizontally(-3)
|
self.handle_resize()
|
||||||
elif char == ord("j"):
|
elif char == curses.ascii.ESC: # Can be ESC or ALT char.
|
||||||
self.scroll_page_vertically(1)
|
self.screen.nodelay(True)
|
||||||
elif char == ord("J"):
|
ch = self.screen.getch()
|
||||||
self.scroll_page_vertically(3)
|
if ch == -1:
|
||||||
elif char == ord("k"):
|
self.set_status(self.current_url)
|
||||||
self.scroll_page_vertically(-1)
|
else:
|
||||||
elif char == ord("K"):
|
pass # No alt-key shortcuts for now!
|
||||||
self.scroll_page_vertically(-3)
|
self.screen.nodelay(False)
|
||||||
elif char == ord("l"):
|
|
||||||
self.scroll_page_horizontally(1)
|
|
||||||
elif char == ord("L"):
|
|
||||||
self.scroll_page_horizontally(3)
|
|
||||||
elif char == ord("f"):
|
|
||||||
self.scroll_page_vertically(self.page_pad_size[0])
|
|
||||||
elif char == ord("b"):
|
|
||||||
self.scroll_page_vertically(-self.page_pad_size[0])
|
|
||||||
elif char == ord("o"):
|
|
||||||
self.quick_command("open")
|
|
||||||
elif char == ord("p"):
|
|
||||||
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:
|
|
||||||
self.handle_mouse(*curses.getmouse())
|
|
||||||
elif char == curses.KEY_RESIZE:
|
|
||||||
self.handle_resize()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def page_pad_size(self):
|
def page_pad_size(self):
|
||||||
|
@ -244,6 +256,9 @@ class Browser:
|
||||||
self.set_status_error(error)
|
self.set_status_error(error)
|
||||||
elif response.generic_code == 10:
|
elif response.generic_code == 10:
|
||||||
self.handle_input_request(url, response)
|
self.handle_input_request(url, response)
|
||||||
|
else:
|
||||||
|
error = f"Unhandled response code {response.code}"
|
||||||
|
self.set_status_error(error)
|
||||||
|
|
||||||
def load_page(self, gemtext: bytes):
|
def load_page(self, gemtext: bytes):
|
||||||
"""Load Gemtext data as the current page."""
|
"""Load Gemtext data as the current page."""
|
||||||
|
|
Reference in a new issue