nice headline and other eyecandy

master
Felix Pankratz 1 year ago
parent d238d1e962
commit 3077cb62f8

20
hn.py

@ -18,6 +18,9 @@ class Client:
def __init__(self): def __init__(self):
# set up curses # set up curses
self.screen = curses.initscr() self.screen = curses.initscr()
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, 255, 208)
curses.noecho() curses.noecho()
curses.cbreak() curses.cbreak()
self.screen.keypad(True) self.screen.keypad(True)
@ -48,10 +51,13 @@ class Client:
# header, detail, footer: # header, detail, footer:
self.stories_in_a_site = self.lines - 3 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]): 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 # calculate length of line
text = f'{prefix} ()\n' text = f'{prefix} ()\n'
chars_available = self.cols - len(text) chars_available = self.cols - len(text)
@ -62,11 +68,17 @@ class Client:
link = story.link.replace('https://', '').replace('http://', '') link = story.link.replace('https://', '').replace('http://', '')
link = link[:max_url_len-1] + "" if len(link) > max_url_len else link link = link[:max_url_len-1] + "" if len(link) > max_url_len else link
text = '{}{} ({})\n'.format(prefix, title, link.replace('https://', '').replace('http://', '')) #text = '{}{} ({})\n'.format(prefix, title, link)
self.screen.addstr(text)
self.screen.addstr(prefix)
if i == self.cursor_pos: 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' detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
self.screen.addstr(detail) 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.') self.set_footer(f'Loaded {len(self.loadedstories)} stories.')
def handle_input(self): def handle_input(self):

Loading…
Cancel
Save