From 99a3a5a6a37d4500fafcf0c5c4be44133587047a Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 5 Aug 2021 12:53:44 +0200 Subject: [PATCH] gopher: use new metalines system Forgot about that, sorry. Bump plugin to 0.1.2. --- plugins/gopher/bebop_gopher/plugin.py | 16 ++++++---------- plugins/gopher/setup.cfg | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/gopher/bebop_gopher/plugin.py b/plugins/gopher/bebop_gopher/plugin.py index ce76a6e..49e9474 100644 --- a/plugins/gopher/bebop_gopher/plugin.py +++ b/plugins/gopher/bebop_gopher/plugin.py @@ -81,7 +81,7 @@ class GopherPlugin(SchemePlugin): ] def open_url(self, browser: Browser, url: str) -> Optional[str]: - """Request an selector from a Gopher host. + """Request a selector from a Gopher host. As Bebop works only with URLs and not really the Gopher host/selector format, we use RFC 4266 (“The gopher URI Scheme”) for consistency with @@ -240,7 +240,7 @@ def parse_source(source: str, item_type: ItemType): if item_type == ItemType.FILE: for line in source.split("\n"): line = line.rstrip("\r") - metalines.append(({"type": LineType.PARAGRAPH}, line)) + metalines.append((LineType.PARAGRAPH, line, None)) # Gopher maps are kind of the default here, so it should be quite safe to # parse any kind of text data. @@ -265,12 +265,12 @@ def parse_source(source: str, item_type: ItemType): # INFO: render as a simple text line. if item_type == ItemType.INFO: - metalines.append(({"type": LineType.PARAGRAPH}, label)) + metalines.append((LineType.PARAGRAPH, label, None)) continue # ERROR: render as an error line. if item_type == ItemType.ERROR: - metalines.append(({"type": LineType.ERROR}, label)) + metalines.append((LineType.ERROR, label, None)) continue # Other item types are rendered as links, with a special case for @@ -280,16 +280,12 @@ def parse_source(source: str, item_type: ItemType): else: link_url = f"gopher://{host}:{port}/{ltype}{path}" - meta = { - "type": LineType.LINK, - "url": link_url, - "link": current_link_id - } links[current_link_id] = link_url icon = ICONS.get(item_type) or f"({ltype})" text = f"[{current_link_id}] {icon} {label}" - metalines.append((meta, text)) + extra = {"url": link_url, "link_id": current_link_id} + metalines.append((LineType.LINK, text, extra)) current_link_id += 1 return metalines, links diff --git a/plugins/gopher/setup.cfg b/plugins/gopher/setup.cfg index d65bee7..621256f 100644 --- a/plugins/gopher/setup.cfg +++ b/plugins/gopher/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = bebop-browser-gopher -version = 0.1.1 +version = 0.1.2 description = Gopher plugin for the Bebop terminal browser long_description = file: README.md license = GPLv3