From 1a5ac7bb5a707a396a6ac674373f3cf2688c5510 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 29 Aug 2023 14:46:00 +0200 Subject: [PATCH] add status bar at the bottom --- hn.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hn.py b/hn.py index 8c5c6ae..10c5eae 100755 --- a/hn.py +++ b/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()