gopher: fix ugly UI spaces in Gopher selectors

This commit is contained in:
dece 2021-06-08 14:46:07 +02:00
parent 04d29f1fd6
commit c8794445df

View file

@ -44,7 +44,7 @@ ICONS = {
ItemType.FILE: "📄", ItemType.FILE: "📄",
ItemType.DIR: "📂", ItemType.DIR: "📂",
ItemType.ERROR: "", ItemType.ERROR: "",
ItemType.SEARCH: "🤔", ItemType.SEARCH: "",
ItemType.HTML: "🌐", ItemType.HTML: "🌐",
} }
@ -73,7 +73,8 @@ class GopherPlugin(SchemePlugin):
browser.set_status_error("Could not parse gopher URL.") browser.set_status_error("Could not parse gopher URL.")
return None return None
host, port = host_and_port host, port = host_and_port
path = parts["path"] # Decode path; spaces in Gopher URLs are encoded for display in Bebop.
path = parts["path"].replace("%20", " ")
# If the URL has an item type, use it to properly parse the response. # If the URL has an item type, use it to properly parse the response.
type_path_match = TYPE_PATH_RE.match(path) type_path_match = TYPE_PATH_RE.match(path)
@ -103,13 +104,13 @@ class GopherPlugin(SchemePlugin):
else: else:
item_type = ItemType.DIR item_type = ItemType.DIR
# If we have text search in our path, encode it for UI & logging. # If we have spaces in our path, encode it for UI & logging.
encoded_path = path.replace("\t", "%09") encoded_path = path.replace(" ", "%20").replace("\t", "%09")
browser.set_status(f"Loading {host} {port} '{encoded_path}'") browser.set_status(f"Loading {host} {port} '{encoded_path}'")
timeout = browser.config["connect_timeout"] timeout = browser.config["connect_timeout"]
try: try:
response = self.request(host, port, path, timeout) response = request(host, port, path, timeout)
page = parse_response(response, item_type) page = parse_response(response, item_type)
except GopherPluginException as exc: except GopherPluginException as exc:
browser.set_status_error("Error: " + exc.message) browser.set_status_error("Error: " + exc.message)
@ -120,7 +121,8 @@ class GopherPlugin(SchemePlugin):
browser.current_url = url browser.current_url = url
return url return url
def request(self, host: str, port: int, path: str, timeout: int):
def request(host: str, port: int, path: str, timeout: int):
try: try:
sock = socket.create_connection((host, port), timeout=timeout) sock = socket.create_connection((host, port), timeout=timeout)
except OSError as exc: except OSError as exc: