Skip to content

Commit b5d1a37

Browse files
committed
cleanup
1 parent eff8e95 commit b5d1a37

File tree

4 files changed

+0
-227
lines changed

4 files changed

+0
-227
lines changed

demo.gif

2.13 MB
Loading

hypertext.py

-69
This file was deleted.

main.py

-65
Original file line numberDiff line numberDiff line change
@@ -62,71 +62,6 @@
6262
BOOKMARKS_FILE = "bookmarks.txt"
6363

6464

65-
superscript_map = {
66-
"0": "⁰",
67-
"1": "¹",
68-
"2": "²",
69-
"3": "³",
70-
"4": "⁴",
71-
"5": "⁵",
72-
"6": "⁶",
73-
"7": "⁷",
74-
"8": "⁸",
75-
"9": "⁹",
76-
}
77-
78-
79-
class TextWithLinks(urwid.WidgetWrap):
80-
def __init__(self, markup, on_link_click):
81-
self.markup = markup
82-
self.on_link_click = on_link_click
83-
self.text = urwid.Text(markup)
84-
self.focused_item_index = 0
85-
self.focusable_items = self.get_focusable_items(markup)
86-
self.update_focus(markup)
87-
super().__init__(self.text)
88-
89-
def update_focus(self, markup):
90-
rewrite = []
91-
index = 0
92-
for item in markup:
93-
if isinstance(item, tuple) and item[0].startswith("http"):
94-
if index == self.focused_item_index:
95-
rewrite.append(
96-
("link_focused", f"{item[1]} {superscript_map[str(index+1)]}")
97-
)
98-
else:
99-
rewrite.append(
100-
("link", f"{item[1]} {superscript_map[str(index+1)]}")
101-
)
102-
index += 1
103-
else:
104-
rewrite.append(item)
105-
self.text.set_text(rewrite)
106-
107-
def get_focusable_items(self, markup):
108-
return [
109-
item
110-
for item in markup
111-
if isinstance(item, tuple) and item[0].startswith("http")
112-
]
113-
114-
def keypress(self, size, key):
115-
max_position = len(self.focusable_items) - 1
116-
if key == "up" or key == "left":
117-
self.focused_item_index = max(0, self.focused_item_index - 1)
118-
elif key == "down" or key == "right":
119-
self.focused_item_index = min(max_position, self.focused_item_index + 1)
120-
elif key == "enter":
121-
self.on_link_click(self.focusable_items[self.focused_item_index][0])
122-
else:
123-
return key
124-
self.update_focus(self.markup)
125-
126-
def selectable(self):
127-
return True
128-
129-
13065
class Hyperlink(urwid.SelectableIcon):
13166
signals = ["click"]
13267

selectable.py

-93
This file was deleted.

0 commit comments

Comments
 (0)