|
|
@ -23,6 +23,7 @@ class Client:
|
|
|
|
curses.noecho()
|
|
|
|
curses.noecho()
|
|
|
|
curses.cbreak()
|
|
|
|
curses.cbreak()
|
|
|
|
self.screen.keypad(True)
|
|
|
|
self.screen.keypad(True)
|
|
|
|
|
|
|
|
curses.curs_set(0)
|
|
|
|
|
|
|
|
|
|
|
|
self.topstories = api.get_topstories()
|
|
|
|
self.topstories = api.get_topstories()
|
|
|
|
self.loadedstories = {}
|
|
|
|
self.loadedstories = {}
|
|
|
@ -94,9 +95,11 @@ class Client:
|
|
|
|
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]]
|
|
|
|
|
|
|
|
|
|
|
|
if c == ord('q'): # Quit
|
|
|
|
if c == ord('q'): # Quit
|
|
|
|
await self.exit()
|
|
|
|
await self.exit()
|
|
|
|
elif c == curses.KEY_UP:
|
|
|
|
|
|
|
|
|
|
|
|
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.cursor_pos = self.stories_in_a_site-1
|
|
|
@ -104,7 +107,7 @@ class Client:
|
|
|
|
self.story_pos -= self.stories_in_a_site
|
|
|
|
self.story_pos -= self.stories_in_a_site
|
|
|
|
self.story_pos = 0 if self.story_pos < 0 else self.story_pos
|
|
|
|
self.story_pos = 0 if self.story_pos < 0 else self.story_pos
|
|
|
|
|
|
|
|
|
|
|
|
elif c == curses.KEY_DOWN:
|
|
|
|
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
|
|
|
|
self.cursor_pos = 0
|
|
|
@ -133,6 +136,29 @@ class Client:
|
|
|
|
self.stories_in_a_site = self.lines - 3
|
|
|
|
self.stories_in_a_site = self.lines - 3
|
|
|
|
await self.load_more_if_needed()
|
|
|
|
await self.load_more_if_needed()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif c == ord('?'):
|
|
|
|
|
|
|
|
self.help()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def help(self):
|
|
|
|
|
|
|
|
def __helpwin_addstr__(win, string, newline=True):
|
|
|
|
|
|
|
|
c_pos_y, c_pos_x = win.getyx()
|
|
|
|
|
|
|
|
win.move(c_pos_y, 1)
|
|
|
|
|
|
|
|
win.addstr(string)
|
|
|
|
|
|
|
|
if newline:
|
|
|
|
|
|
|
|
win.move(c_pos_y +1, 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
helpwin = curses.newwin(self.lines//2, self.cols//2, self.lines//4, self.cols//4)
|
|
|
|
|
|
|
|
helpwin.box()
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, 'Help')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, '')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, 'hjkl or arrows - move')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, 'enter - open link')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, 'c - open comments')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, 'r - reload')
|
|
|
|
|
|
|
|
__helpwin_addstr__(helpwin, '')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
helpwin.getch()
|
|
|
|
|
|
|
|
|
|
|
|
async def load_more_if_needed(self):
|
|
|
|
async def load_more_if_needed(self):
|
|
|
|
|
|
|
|
|
|
|
|