resizable (somewhat...)

This commit is contained in:
Felix Pankratz 2023-08-29 20:48:53 +02:00
parent dea614c5c8
commit 4bd8d61d7c

14
hn.py
View File

@ -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()