browser: capture C-c

This commit is contained in:
dece 2021-03-09 00:44:42 +01:00
parent 398f526b82
commit 2db721d48a

View file

@ -69,13 +69,17 @@ 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() char = self.screen.getch()
if char == ord(":"): if char == ord(":"):
self.quick_command("") self.quick_command("")
elif char == ord("r"): elif char == ord("r"):
self.reload_page() self.reload_page()
elif char == ord("s"):
self.set_status(f"h {self.h} w {self.w}")
elif char == ord("h"): elif char == ord("h"):
self.scroll_page_horizontally(-1) self.scroll_page_horizontally(-1)
elif char == ord("H"): elif char == ord("H"):
@ -112,6 +116,14 @@ class Browser:
self.handle_mouse(*curses.getmouse()) self.handle_mouse(*curses.getmouse())
elif char == curses.KEY_RESIZE: elif char == curses.KEY_RESIZE:
self.handle_resize() self.handle_resize()
elif char == curses.ascii.ESC: # Can be ESC or ALT char.
self.screen.nodelay(True)
ch = self.screen.getch()
if ch == -1:
self.set_status(self.current_url)
else:
pass # No alt-key shortcuts for now!
self.screen.nodelay(False)
@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."""