From 4bd8d61d7c1b1bf5266bd58f2f8dd0dbd4eeb5f9 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 29 Aug 2023 20:48:53 +0200 Subject: [PATCH] resizable (somewhat...) --- hn.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/hn.py b/hn.py index 2267657..b3a067a 100755 --- a/hn.py +++ b/hn.py @@ -14,7 +14,6 @@ import api spinner_states = ['-', '\\', '|', '/'] - class Client: def __init__(self): # set up curses @@ -42,6 +41,7 @@ class Client: self.screen.addstr(curses.LINES - 1, 0, footer, curses.A_REVERSE) def draw(self): + self.screen.clear() self.lines = curses.LINES self.cols = curses.COLS @@ -84,6 +84,10 @@ class Client: webbrowser.open(f'https://news.ycombinator.com/item?id={self.loadedstories[self.story_pos + self.cursor_pos].id}') elif c == curses.KEY_ENTER or c == 10: webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link) + elif c == curses.KEY_RESIZE: + curses.resize_term(*self.screen.getmaxyx()) + self.lines, self.cols = self.screen.getmaxyx() + self.stories_in_a_site = self.lines - 3 def run(self): self.load_stories(0, self.stories_in_a_site) @@ -97,8 +101,12 @@ class Client: sys.exit(0) def main(): - client = Client() - client.run() + try: + client = Client() + client.run() + except Exception as e: + curses.endwin() + print(e) if __name__ == '__main__': main()