|
|
@ -89,10 +89,18 @@ class Client:
|
|
|
|
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.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:
|
|
|
|
elif c == curses.KEY_DOWN:
|
|
|
|
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
|
|
|
|
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'):
|
|
|
|
elif c == ord('c'):
|
|
|
|
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:
|
|
|
@ -101,6 +109,9 @@ class Client:
|
|
|
|
curses.resize_term(*self.screen.getmaxyx())
|
|
|
|
curses.resize_term(*self.screen.getmaxyx())
|
|
|
|
self.lines, self.cols = self.screen.getmaxyx()
|
|
|
|
self.lines, self.cols = self.screen.getmaxyx()
|
|
|
|
self.stories_in_a_site = self.lines - 3
|
|
|
|
self.stories_in_a_site = self.lines - 3
|
|
|
|
|
|
|
|
self.load_more_if_needed()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_more_if_needed(self):
|
|
|
|
if len(self.loadedstories) < self.story_pos + self.stories_in_a_site:
|
|
|
|
if len(self.loadedstories) < self.story_pos + self.stories_in_a_site:
|
|
|
|
# load more
|
|
|
|
# load more
|
|
|
|
self.load_stories(len(self.loadedstories), self.story_pos + self.stories_in_a_site)
|
|
|
|
self.load_stories(len(self.loadedstories), self.story_pos + self.stories_in_a_site)
|
|
|
|