From 3077cb62f8271b4135e85a08fd8d6e2f5c8983b3 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 29 Aug 2023 22:15:32 +0200 Subject: [PATCH] nice headline and other eyecandy --- hn.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/hn.py b/hn.py index 717e4c4..f03d9fd 100755 --- a/hn.py +++ b/hn.py @@ -18,6 +18,9 @@ class Client: def __init__(self): # set up curses self.screen = curses.initscr() + curses.start_color() + curses.use_default_colors() + curses.init_pair(1, 255, 208) curses.noecho() curses.cbreak() self.screen.keypad(True) @@ -48,10 +51,13 @@ class Client: # header, detail, footer: self.stories_in_a_site = self.lines - 3 - self.screen.addstr('Hacker News Top Stories:\n') + title_string = '[Y] Hacker News' + title_string +=' ' * ( self.cols - len(title_string) - 1) + '\n' + + self.screen.addstr(title_string, curses.color_pair(1)) for i, story in enumerate(self.loadedstories[self.story_pos:self.story_pos + self.stories_in_a_site]): - prefix = '>>> ' if i == self.cursor_pos else ' ' + prefix = '>' if i == self.cursor_pos else '' # calculate length of line text = f'{prefix} ()\n' chars_available = self.cols - len(text) @@ -62,11 +68,17 @@ class Client: link = story.link.replace('https://', '').replace('http://', '') link = link[:max_url_len-1] + "…" if len(link) > max_url_len else link - text = '{}{} ({})\n'.format(prefix, title, link.replace('https://', '').replace('http://', '')) - self.screen.addstr(text) + #text = '{}{} ({})\n'.format(prefix, title, link) + + self.screen.addstr(prefix) if i == self.cursor_pos: + 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) + self.screen.addstr(f' ({link})\n', curses.A_DIM ) self.set_footer(f'Loaded {len(self.loadedstories)} stories.') def handle_input(self):