navigation: add a "go to root" function
This commit is contained in:
parent
cf6b67f78b
commit
b508ab8128
|
@ -113,6 +113,8 @@ class Browser:
|
|||
self.go_back()
|
||||
elif char == ord("u"):
|
||||
self.go_to_parent_page()
|
||||
elif char == ord("U"):
|
||||
self.go_to_root_page()
|
||||
elif curses.ascii.isdigit(char):
|
||||
self.handle_digit_input(char)
|
||||
elif char == curses.KEY_MOUSE:
|
||||
|
@ -470,6 +472,11 @@ class Browser:
|
|||
if self.current_url:
|
||||
self.open_gemini_url(get_parent_url(self.current_url))
|
||||
|
||||
def go_to_root_page(self):
|
||||
"""Go to the root URL if possible."""
|
||||
if self.current_url:
|
||||
self.open_gemini_url(get_root_url(self.current_url))
|
||||
|
||||
def open_web_url(self, url):
|
||||
"""Open a Web URL. Currently relies in Python's webbrowser module."""
|
||||
self.set_status(f"Opening {url}")
|
||||
|
|
|
@ -58,3 +58,9 @@ def get_parent_url(url: str) -> str:
|
|||
if last_slash > -1:
|
||||
path = path[:last_slash + 1]
|
||||
return urllib.parse.urlunparse((scheme, netloc, path, params, query, frag))
|
||||
|
||||
|
||||
def get_root_url(url: str) -> str:
|
||||
"""Return the root URL (basically discards path)."""
|
||||
scheme, netloc, _, _, _, _ = parse_url(url)
|
||||
return urllib.parse.urlunparse((scheme, netloc, "/", "", "", ""))
|
||||
|
|
Reference in a new issue