read status, eyecandy

master
Felix Pankratz 1 year ago
parent 0e590eefed
commit edeeb793ff

15
hn.py

@ -1,10 +1,5 @@
#!/usr/bin/env python3
#TODO: make sure things dont explode no matter what terminal size
# x prevent linebreaks in a single story
# x only load as many stories as fit
# -> refresh on resize
import requests
from bs4 import BeautifulSoup as Soup
import curses
@ -72,10 +67,16 @@ class Client:
self.screen.addstr(prefix)
if i == self.cursor_pos:
if story.read:
self.screen.addstr(title, curses.A_DIM | curses.A_UNDERLINE)
else:
self.screen.addstr(title, curses.A_UNDERLINE)
self.screen.addstr(f' ({link})\n', curses.A_DIM )
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
self.screen.addstr(detail)
else:
if story.read:
self.screen.addstr(title, curses.A_DIM)
else:
self.screen.addstr(title)
self.screen.addstr(f' ({link})\n', curses.A_DIM )
@ -107,7 +108,11 @@ class Client:
elif c == ord('c'):
webbrowser.open(f'https://news.ycombinator.com/item?id={self.loadedstories[self.story_pos + self.cursor_pos].id}')
elif c == curses.KEY_ENTER or c == 10:
if self.loadedstories[self.story_pos + self.cursor_pos].link == 'No URL':
webbrowser.open(f'https://news.ycombinator.com/item?id={self.loadedstories[self.story_pos + self.cursor_pos].id}')
else:
webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link)
self.loadedstories[self.story_pos + self.cursor_pos].read = True
elif c == curses.KEY_RESIZE:
curses.resize_term(*self.screen.getmaxyx())
self.lines, self.cols = self.screen.getmaxyx()

Loading…
Cancel
Save