nice headline and other eyecandy
This commit is contained in:
parent
d238d1e962
commit
3077cb62f8
20
hn.py
20
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):
|
||||
|
Loading…
Reference in New Issue
Block a user