You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
import urwid
|
|
|
|
|
|
class TUI(urwid.Frame):
|
|
|
|
@classmethod
|
|
def create(cls):
|
|
|
|
tui = cls()
|
|
palette = [('header', 'white', 'black'), ('reveal focus', 'black', 'dark cyan', 'standout')]
|
|
loop = urwid.MainLoop(
|
|
tui,
|
|
palette,
|
|
event_loop=urwid.AsyncioEventLoop(),
|
|
)
|
|
tui.loop = loop
|
|
|
|
return tui
|
|
|
|
def __init__(self):
|
|
self.loop = None
|
|
self.items = [urwid.Text("Feed# " + str(i)) for i in range(0, 15)]
|
|
walker = urwid.SimpleListWalker([urwid.AttrMap(item, None, 'reveal focus') for item in self.items])
|
|
self.lb = urwid.ListBox(walker)
|
|
self.body = self.lb
|
|
|
|
super().__init__(self.body)
|
|
|
|
def run(self):
|
|
self.loop.run()
|
|
self.executor.shutdown(wait=False)
|
|
|
|
def keypress(self, size, key):
|
|
if key in ("j", "down"):
|
|
item_size = len(self.lb.body)
|
|
focus_widget, idx = self.lb.get_focus()
|
|
if idx < item_size - 1:
|
|
idx = idx + 1
|
|
self.lb.set_focus(idx)
|
|
elif key in ("k", "up"):
|
|
focus_widget, idx = self.lb.get_focus()
|
|
if idx > 0:
|
|
idx = idx - 1
|
|
self.lb.set_focus(idx)
|
|
elif key == "a":
|
|
self.lb.body.append(urwid.AttrMap(urwid.Text("XXX"), None, 'reveal focus'))
|
|
else:
|
|
self.lb.keypress(size, key)
|
|
del self.lb.body[3]
|
|
|
|
|
|
tui = TUI.create()
|
|
tui.run()
|