|
|
|
@ -2,6 +2,7 @@ import urwid
|
|
|
|
import yaml
|
|
|
|
import yaml
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
import warnings
|
|
|
|
import warnings
|
|
|
|
|
|
|
|
import os
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
|
from API import Fetcher
|
|
|
|
from API import Fetcher
|
|
|
|
from Render import Article
|
|
|
|
from Render import Article
|
|
|
|
@ -154,7 +155,7 @@ class RightPane(urwid.ListBox):
|
|
|
|
tui.rightBox.set_title(self.article.title + " (" + str(self.article.currentPageNumber) + "/" +
|
|
|
|
tui.rightBox.set_title(self.article.title + " (" + str(self.article.currentPageNumber) + "/" +
|
|
|
|
str(self.article.numberOfPages) + ")")
|
|
|
|
str(self.article.numberOfPages) + ")")
|
|
|
|
|
|
|
|
|
|
|
|
def keypress(self, size, key):
|
|
|
|
def keypress(self, size, key): #noqa
|
|
|
|
if key in ("j", "down"):
|
|
|
|
if key in ("j", "down"):
|
|
|
|
if not self.isList:
|
|
|
|
if not self.isList:
|
|
|
|
walker = urwid.SimpleListWalker([urwid.Text(self.article.scrollDown())])
|
|
|
|
walker = urwid.SimpleListWalker([urwid.Text(self.article.scrollDown())])
|
|
|
|
@ -196,10 +197,52 @@ class RightPane(urwid.ListBox):
|
|
|
|
tui.rightBox.set_title(focusFeed.attr_map[None][1])
|
|
|
|
tui.rightBox.set_title(focusFeed.attr_map[None][1])
|
|
|
|
self.set_focus(self.articlePosition)
|
|
|
|
self.set_focus(self.articlePosition)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
|
|
|
|
elif key == "m":
|
|
|
|
|
|
|
|
if self.isList is False and len(self.article.links) > 0:
|
|
|
|
|
|
|
|
top = Links(self.article.links)
|
|
|
|
|
|
|
|
tui.createOverlay(urwid.LineBox(top), len(self.article.links)+2)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
return super().keypress(size, key)
|
|
|
|
return super().keypress(size, key)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Links(urwid.ListBox):
|
|
|
|
|
|
|
|
def __init__(self, links):
|
|
|
|
|
|
|
|
super().__init__(self)
|
|
|
|
|
|
|
|
items = [urwid.AttrMap(urwid.Columns([urwid.Text(link)]), (link), "reveal focus") for link in links]
|
|
|
|
|
|
|
|
walker = urwid.SimpleFocusListWalker(items)
|
|
|
|
|
|
|
|
self.body = walker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parseLink(self, link):
|
|
|
|
|
|
|
|
ext = link.split(".")[-1]
|
|
|
|
|
|
|
|
if ext.lower() in ("jpg", "jpeg", "gif", "png", "tif", "tiff"):
|
|
|
|
|
|
|
|
os.popen('feh {link}'.format(link=link))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
os.popen('firefox -new-tab {link}'.format(link=link))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def keypress(self, size, key):
|
|
|
|
|
|
|
|
if key in ("j", "down"):
|
|
|
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
|
|
|
item_size = len(self.body)
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
elif key in ("l", "right"):
|
|
|
|
|
|
|
|
focus_widget, idx = self.get_focus()
|
|
|
|
|
|
|
|
link = focus_widget.attr_map[None]
|
|
|
|
|
|
|
|
self.parseLink(link)
|
|
|
|
|
|
|
|
elif key == "q":
|
|
|
|
|
|
|
|
tui.destroyOverlay()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TUI(urwid.Frame):
|
|
|
|
class TUI(urwid.Frame):
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
@classmethod
|
|
|
|
@ -225,6 +268,7 @@ class TUI(urwid.Frame):
|
|
|
|
URL = config["server"]["URL"]
|
|
|
|
URL = config["server"]["URL"]
|
|
|
|
token = config["server"]["token"]
|
|
|
|
token = config["server"]["token"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.overlay = None
|
|
|
|
self.fetcher = Fetcher(URL, token)
|
|
|
|
self.fetcher = Fetcher(URL, token)
|
|
|
|
|
|
|
|
|
|
|
|
self.leftPaneItems = {}
|
|
|
|
self.leftPaneItems = {}
|
|
|
|
@ -237,22 +281,12 @@ class TUI(urwid.Frame):
|
|
|
|
self.rightBox = urwid.LineBox(self.articleView, title="Articles")
|
|
|
|
self.rightBox = urwid.LineBox(self.articleView, title="Articles")
|
|
|
|
self.views = urwid.Columns(
|
|
|
|
self.views = urwid.Columns(
|
|
|
|
[(56, self.leftBox), self.rightBox])
|
|
|
|
[(56, self.leftBox), self.rightBox])
|
|
|
|
self.status = urwid.Text("")
|
|
|
|
self.container = urwid.Pile([self.views])
|
|
|
|
self.footer = urwid.ListBox([self.status])
|
|
|
|
|
|
|
|
self.container = urwid.Pile([self.views, (1, self.footer)])
|
|
|
|
|
|
|
|
self.body = self.container
|
|
|
|
self.body = self.container
|
|
|
|
self.articles = []
|
|
|
|
self.articles = []
|
|
|
|
|
|
|
|
|
|
|
|
super().__init__(self.body)
|
|
|
|
super().__init__(self.body)
|
|
|
|
|
|
|
|
|
|
|
|
def fetchAll(self):
|
|
|
|
|
|
|
|
articles = tui.fetcher.fetch()
|
|
|
|
|
|
|
|
for text in articles:
|
|
|
|
|
|
|
|
self.status.set_text(text)
|
|
|
|
|
|
|
|
tui.loop.entering_idle()
|
|
|
|
|
|
|
|
self.status.set_text("")
|
|
|
|
|
|
|
|
self.loop.event_loop.remove_alarm(self.handle)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
def run(self):
|
|
|
|
focus_widget, idx = self.feedView.get_focus()
|
|
|
|
focus_widget, idx = self.feedView.get_focus()
|
|
|
|
item = focus_widget.attr_map[None][0]
|
|
|
|
item = focus_widget.attr_map[None][0]
|
|
|
|
@ -264,6 +298,16 @@ class TUI(urwid.Frame):
|
|
|
|
self.loop.run()
|
|
|
|
self.loop.run()
|
|
|
|
self.executor.shutdown(wait=False)
|
|
|
|
self.executor.shutdown(wait=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def createOverlay(self, element, h):
|
|
|
|
|
|
|
|
self.overlay = urwid.Overlay(
|
|
|
|
|
|
|
|
element,
|
|
|
|
|
|
|
|
self.body, align="center", width=("relative", 50), valign="middle", height=h)
|
|
|
|
|
|
|
|
self.body = self.overlay
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def destroyOverlay(self):
|
|
|
|
|
|
|
|
self.body = self.overlay.bottom_w
|
|
|
|
|
|
|
|
del(self.overlay)
|
|
|
|
|
|
|
|
|
|
|
|
def unhandled_input(self, key):
|
|
|
|
def unhandled_input(self, key):
|
|
|
|
if key == "tab":
|
|
|
|
if key == "tab":
|
|
|
|
self.activePane = not self.activePane
|
|
|
|
self.activePane = not self.activePane
|
|
|
|
@ -273,11 +317,16 @@ class TUI(urwid.Frame):
|
|
|
|
elif key == "q":
|
|
|
|
elif key == "q":
|
|
|
|
raise urwid.ExitMainLoop()
|
|
|
|
raise urwid.ExitMainLoop()
|
|
|
|
elif key == "r":
|
|
|
|
elif key == "r":
|
|
|
|
self.handle = self.loop.event_loop.alarm(0, self.fetchAll)
|
|
|
|
olb = urwid.ListBox(urwid.SimpleListWalker([urwid.Text("")]))
|
|
|
|
focus_widget, idx = self.feedView.get_focus()
|
|
|
|
overlay = urwid.Overlay(
|
|
|
|
itemId = focus_widget.attr_map[None][0]
|
|
|
|
urwid.LineBox(olb),
|
|
|
|
self.articles = tui.fetcher.articles[itemId]
|
|
|
|
self.body, align="center", width=("relative", 50), valign="middle", height=3)
|
|
|
|
self.articleView.fill(self.articles)
|
|
|
|
self.body = overlay
|
|
|
|
|
|
|
|
articles = tui.fetcher.fetch()
|
|
|
|
|
|
|
|
for text in articles:
|
|
|
|
|
|
|
|
olb.body = urwid.SimpleListWalker([urwid.Text(text)])
|
|
|
|
|
|
|
|
tui.loop.entering_idle()
|
|
|
|
|
|
|
|
self.body = overlay.bottom_w
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tui = TUI.create()
|
|
|
|
tui = TUI.create()
|
|
|
|
|