From edeeb793ffb272c8204e4aa149d730540a836603 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 29 Aug 2023 23:01:30 +0200 Subject: [PATCH] read status, eyecandy --- hn.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/hn.py b/hn.py index fb8af98..ebea9fc 100755 --- a/hn.py +++ b/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,12 +67,18 @@ class Client: self.screen.addstr(prefix) if i == self.cursor_pos: - self.screen.addstr(title, curses.A_UNDERLINE) + 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: - self.screen.addstr(title) + if story.read: + self.screen.addstr(title, curses.A_DIM) + else: + self.screen.addstr(title) self.screen.addstr(f' ({link})\n', curses.A_DIM ) page = int(self.story_pos / self.stories_in_a_site + 1) @@ -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: - webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link) + 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()