add page up/down keys

master
Felix Pankratz 1 year ago
parent 1fc2d55983
commit 1b7a9047e6

28
hn.py

@ -94,6 +94,18 @@ class Client:
footer_text = footer_text[:self.cols - 1] footer_text = footer_text[:self.cols - 1]
self.set_footer(footer_text) 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): async def handle_input(self):
c = self.screen.getch() c = self.screen.getch()
story = self.loadedstories[self.topstories[self.story_pos + self.cursor_pos]] 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'): elif c == curses.KEY_UP or c == ord('k'):
self.cursor_pos -= 1 self.cursor_pos -= 1
if self.cursor_pos < 0: if self.cursor_pos < 0:
self.cursor_pos = self.stories_in_a_site-1 self.page_up()
# 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
elif c == curses.KEY_DOWN or c == ord('j'): elif c == curses.KEY_DOWN or c == ord('j'):
self.cursor_pos += 1 self.cursor_pos += 1
if self.cursor_pos >= self.stories_in_a_site: if self.cursor_pos >= self.stories_in_a_site:
self.cursor_pos = 0 await self.page_down()
# scroll up down a page :)
self.story_pos += self.stories_in_a_site elif c == curses.KEY_NPAGE:
await self.load_more_if_needed() await self.page_down()
elif c == curses.KEY_PPAGE:
self.page_up()
elif c == ord('c'): elif c == ord('c'):
# open comments # open comments

Loading…
Cancel
Save