add paging
This commit is contained in:
parent
3077cb62f8
commit
41d3e07a3f
17
hn.py
17
hn.py
@ -89,10 +89,18 @@ class Client:
|
||||
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
|
||||
|
||||
elif c == curses.KEY_DOWN:
|
||||
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
|
||||
self.load_more_if_needed()
|
||||
|
||||
elif c == ord('c'):
|
||||
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:
|
||||
@ -101,9 +109,12 @@ class Client:
|
||||
curses.resize_term(*self.screen.getmaxyx())
|
||||
self.lines, self.cols = self.screen.getmaxyx()
|
||||
self.stories_in_a_site = self.lines - 3
|
||||
if len(self.loadedstories) < self.story_pos + self.stories_in_a_site:
|
||||
# load more
|
||||
self.load_stories(len(self.loadedstories), self.story_pos + self.stories_in_a_site)
|
||||
self.load_more_if_needed()
|
||||
|
||||
def load_more_if_needed(self):
|
||||
if len(self.loadedstories) < self.story_pos + self.stories_in_a_site:
|
||||
# load more
|
||||
self.load_stories(len(self.loadedstories), self.story_pos + self.stories_in_a_site)
|
||||
|
||||
def run(self):
|
||||
self.load_stories(0, self.stories_in_a_site)
|
||||
|
Loading…
Reference in New Issue
Block a user