|
|
@ -54,14 +54,17 @@ def main(stdscr):
|
|
|
|
stdscr.addstr('Hacker News Top Stories:\n')
|
|
|
|
stdscr.addstr('Hacker News Top Stories:\n')
|
|
|
|
for i, story in enumerate(stories):
|
|
|
|
for i, story in enumerate(stories):
|
|
|
|
prefix = '>>> ' if i == current_pos else ' '
|
|
|
|
prefix = '>>> ' if i == current_pos else ' '
|
|
|
|
#text = f'{prefix}{story.title} ({story.link})\n'
|
|
|
|
|
|
|
|
# calculate length of line
|
|
|
|
# calculate length of line
|
|
|
|
text = f'{prefix} ()\n'
|
|
|
|
text = f'{prefix} ()\n'
|
|
|
|
chars_available = width - len(text)
|
|
|
|
chars_available = width - len(text)
|
|
|
|
max_title_len = min((chars_available//3)*2, len(story.title))
|
|
|
|
max_title_len = min((chars_available//3)*2, len(story.title))
|
|
|
|
max_url_len = chars_available - max_title_len
|
|
|
|
max_url_len = chars_available - max_title_len
|
|
|
|
|
|
|
|
|
|
|
|
text = f'{prefix}{(story.title[:max_title_len-1] + "…") if len(story.title) > max_title_len else story.title} ({story.link[:max_url_len-1] + "…" if len(story.link) > max_url_len else story.link})\n'
|
|
|
|
title = story.title[:max_title_len-1] + "…" if len(story.title) > max_title_len else story.title
|
|
|
|
|
|
|
|
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://', ''))
|
|
|
|
stdscr.addstr(text)
|
|
|
|
stdscr.addstr(text)
|
|
|
|
if i == current_pos:
|
|
|
|
if i == current_pos:
|
|
|
|
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
|
|
|
|
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
|
|
|
@ -82,8 +85,6 @@ def main(stdscr):
|
|
|
|
elif c == ord('c'):
|
|
|
|
elif c == ord('c'):
|
|
|
|
webbrowser.open(f'https://news.ycombinator.com/item?id={stories[current_pos].id}')
|
|
|
|
webbrowser.open(f'https://news.ycombinator.com/item?id={stories[current_pos].id}')
|
|
|
|
elif c == curses.KEY_ENTER or c == 10:
|
|
|
|
elif c == curses.KEY_ENTER or c == 10:
|
|
|
|
#title, link = stories[current_pos]
|
|
|
|
|
|
|
|
#print(f'\nOpening link: {link}\n')
|
|
|
|
|
|
|
|
webbrowser.open(stories[current_pos].link)
|
|
|
|
webbrowser.open(stories[current_pos].link)
|
|
|
|
|
|
|
|
|
|
|
|
curses.wrapper(main)
|
|
|
|
curses.wrapper(main)
|
|
|
|