|
|
|
|
@ -1,4 +1,29 @@
|
|
|
|
|
import urwid
|
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Items(urwid.ListBox):
|
|
|
|
|
def __init__(self, items):
|
|
|
|
|
super().__init__(self)
|
|
|
|
|
walker = urwid.SimpleListWalker([urwid.AttrMap(item, None, 'reveal focus') for item in items])
|
|
|
|
|
self.body = walker
|
|
|
|
|
|
|
|
|
|
def keypress(self, size, key):
|
|
|
|
|
if key in ("j", "down"):
|
|
|
|
|
item_size = len(self.body)
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
if idx < item_size - 1:
|
|
|
|
|
idx = idx + 1
|
|
|
|
|
self.set_focus(idx)
|
|
|
|
|
return
|
|
|
|
|
elif key in ("k", "up"):
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
if idx > 0:
|
|
|
|
|
idx = idx - 1
|
|
|
|
|
self.set_focus(idx)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TUI(urwid.Frame):
|
|
|
|
|
@ -12,17 +37,21 @@ class TUI(urwid.Frame):
|
|
|
|
|
tui,
|
|
|
|
|
palette,
|
|
|
|
|
event_loop=urwid.AsyncioEventLoop(),
|
|
|
|
|
unhandled_input=tui.unhandled_input,
|
|
|
|
|
)
|
|
|
|
|
tui.loop = loop
|
|
|
|
|
|
|
|
|
|
return tui
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.executor = ThreadPoolExecutor(max_workers=1)
|
|
|
|
|
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
|
|
|
|
|
self.feedItems = [urwid.Text("Feed# " + str(i)) for i in range(0, 15)]
|
|
|
|
|
self.articleItems = [urwid.Text("Article# " + str(i)) for i in range(0, 10)]
|
|
|
|
|
self.feeds = Items(self.feedItems)
|
|
|
|
|
self.articles = Items(self.articleItems)
|
|
|
|
|
self.container = urwid.Columns([urwid.LineBox(self.feeds, title="Feeds"), urwid.LineBox(self.articles, title="Articles")])
|
|
|
|
|
self.body = self.container
|
|
|
|
|
|
|
|
|
|
super().__init__(self.body)
|
|
|
|
|
|
|
|
|
|
@ -30,23 +59,11 @@ class TUI(urwid.Frame):
|
|
|
|
|
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]
|
|
|
|
|
def unhandled_input(self, key):
|
|
|
|
|
if key == "tab":
|
|
|
|
|
self.container.set_focus(1)
|
|
|
|
|
elif key == "q":
|
|
|
|
|
raise urwid.ExitMainLoop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tui = TUI.create()
|
|
|
|
|
|