gopher: properly render error lines

exec
dece 3 years ago
parent 54aeafd878
commit 36d0e6f7b1

@ -3,6 +3,9 @@
In Bebop we use a list of elements as produced by our parser. These elements are
converted into so-called "metalines", which are the text lines as they will be
displayed, along with associated meta-data such as its type or a link's URL.
Note that metalines can be generated by custom functions without relying on the
elements classes as they are quite coupled to Gemtext parsing/rendering.
"""
import string
@ -33,6 +36,7 @@ class LineType(IntEnum):
PREFORMATTED = 6
BLOCKQUOTE = 7
LIST_ITEM = 8
ERROR = 9 # Not part of Gemtext but useful internally.
def generate_metalines(elements, width, dumb=False):

@ -70,5 +70,7 @@ def get_base_line_attributes(line_type) -> int:
return curses.color_pair(ColorPair.PREFORMATTED)
elif line_type == LineType.BLOCKQUOTE:
return curses.color_pair(ColorPair.BLOCKQUOTE) | A_ITALIC
elif line_type == LineType.ERROR:
return curses.color_pair(ColorPair.ERROR) | curses.A_BOLD
else: # includes LineType.PARAGRAPH
return curses.color_pair(ColorPair.NORMAL)

@ -53,7 +53,6 @@ USER_FRIENDLY_TYPES = {t.name.lower(): t for t in ItemType}
ICONS = {
ItemType.FILE: "📄",
ItemType.DIR: "📂",
ItemType.ERROR: "",
ItemType.SEARCH: "",
ItemType.HTML: "🌐",
}
@ -256,19 +255,26 @@ def parse_source(source: str, item_type: ItemType):
break
parts = tline.split("\t")
if len(parts) != 4:
# TODO move me away
# Does not seem to be split by tabs, may be a file.
metalines.append(({"type": LineType.PARAGRAPH}, line))
continue
# If the map is poorly formatted and parts are missing, pad with
# empty parts.
while len(parts) < 4:
parts.append("")
item_type = ItemType(ltype)
label, path, host, port = parts
# INFO: render as a simple text line.
if item_type == ItemType.INFO:
meta = {"type": LineType.PARAGRAPH}
metalines.append((meta, label))
metalines.append(({"type": LineType.PARAGRAPH}, label))
continue
# ERROR: render as an error line.
if item_type == ItemType.ERROR:
metalines.append(({"type": LineType.ERROR}, label))
continue
# Other item types are rendered as links, with a special case for
# "URL:"-type selectors in HTML items.
if item_type == ItemType.HTML and path[:4].upper() == "URL:":
link_url = path[4:]
else:

Loading…
Cancel
Save