resizable (somewhat...)

master
Felix Pankratz 1 year ago
parent dea614c5c8
commit 4bd8d61d7c

14
hn.py

@ -14,7 +14,6 @@ import api
spinner_states = ['-', '\\', '|', '/'] spinner_states = ['-', '\\', '|', '/']
class Client: class Client:
def __init__(self): def __init__(self):
# set up curses # set up curses
@ -42,6 +41,7 @@ class Client:
self.screen.addstr(curses.LINES - 1, 0, footer, curses.A_REVERSE) self.screen.addstr(curses.LINES - 1, 0, footer, curses.A_REVERSE)
def draw(self): def draw(self):
self.screen.clear() self.screen.clear()
self.lines = curses.LINES self.lines = curses.LINES
self.cols = curses.COLS 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}') 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: elif c == curses.KEY_ENTER or c == 10:
webbrowser.open(self.loadedstories[self.story_pos + self.cursor_pos].link) 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): def run(self):
self.load_stories(0, self.stories_in_a_site) self.load_stories(0, self.stories_in_a_site)
@ -97,8 +101,12 @@ class Client:
sys.exit(0) sys.exit(0)
def main(): def main():
client = Client() try:
client.run() client = Client()
client.run()
except Exception as e:
curses.endwin()
print(e)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

Loading…
Cancel
Save