add status bar at the bottom

master
Felix Pankratz 1 year ago
parent ed2e395e5f
commit 1a5ac7bb5a

11
hn.py

@ -22,6 +22,10 @@ class Story:
votes: int
comments: int
def footer(stdscr, content):
stdscr.addstr(curses.LINES-1, 0, content, curses.A_REVERSE)
def main(stdscr):
stdscr.clear()
@ -36,8 +40,8 @@ def main(stdscr):
stories = []
for idx, i in enumerate(ids):
stdscr.clear()
stdscr.addstr(f'{num_stories}\n')
stdscr.addstr(f'[{spinner_states[idx%4]}] Getting stories...')
#stdscr.addstr(f'[{spinner_states[idx%4]}] Getting stories...')
footer(stdscr, f'[{spinner_states[idx%4]}] Getting stories...')
stdscr.refresh()
story_url = f'https://hacker-news.firebaseio.com/v0/item/{i}.json'
s = requests.get(story_url).json()
@ -59,7 +63,7 @@ def main(stdscr):
chars_available = width - len(text)
max_title_len = min((chars_available//3)*2, len(story.title))
max_url_len = chars_available - max_title_len
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
@ -69,6 +73,7 @@ def main(stdscr):
if i == current_pos:
detail = f' by {story.author} | {story.comments} comments | {story.votes} points\n'
stdscr.addstr(detail)
footer(stdscr, f'Loaded {num_stories} stories.')
stdscr.refresh()
c = stdscr.getch()

Loading…
Cancel
Save