From 1b7a9047e6d19b42b901c94a659a8a5ec1e22d83 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Tue, 5 Sep 2023 12:27:51 +0200 Subject: [PATCH] add page up/down keys --- hn.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/hn.py b/hn.py index d883700..74ad902 100755 --- a/hn.py +++ b/hn.py @@ -94,6 +94,18 @@ class Client: footer_text = footer_text[:self.cols - 1] self.set_footer(footer_text) + def page_up(self): + # scroll up a page (: + self.cursor_pos = self.stories_in_a_site-1 + self.story_pos -= self.stories_in_a_site + self.story_pos = 0 if self.story_pos < 0 else self.story_pos + + async def page_down(self): + # scroll up down a page :) + self.cursor_pos = 0 + self.story_pos += self.stories_in_a_site + await self.load_more_if_needed() + async def handle_input(self): c = self.screen.getch() story = self.loadedstories[self.topstories[self.story_pos + self.cursor_pos]] @@ -104,18 +116,18 @@ class Client: elif c == curses.KEY_UP or c == ord('k'): self.cursor_pos -= 1 if self.cursor_pos < 0: - self.cursor_pos = self.stories_in_a_site-1 - # scroll up a page (: - self.story_pos -= self.stories_in_a_site - self.story_pos = 0 if self.story_pos < 0 else self.story_pos + self.page_up() elif c == curses.KEY_DOWN or c == ord('j'): self.cursor_pos += 1 if self.cursor_pos >= self.stories_in_a_site: - self.cursor_pos = 0 - # scroll up down a page :) - self.story_pos += self.stories_in_a_site - await self.load_more_if_needed() + await self.page_down() + + elif c == curses.KEY_NPAGE: + await self.page_down() + + elif c == curses.KEY_PPAGE: + self.page_up() elif c == ord('c'): # open comments