From d84b3a5702e6730bdc1df75a2f08288fe62f70d0 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 1 Feb 2015 20:27:30 -0800 Subject: [PATCH] Added enter command. Make selfpost scroll a little more elegant. --- rtv/page.py | 26 +++++++++++++++++--------- rtv/submission.py | 3 +-- rtv/subreddit.py | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 5cb2bd2..e17bad0 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -40,17 +40,25 @@ class Navigator(object): forward = ((direction*self.step) > 0) if forward: - self.cursor_index += 1 - if self.cursor_index >= n_windows - 1: - self.page_index += (self.step * self.cursor_index) + if self.page_index < 0: + # Special case - advance the page index if less than zero + self.page_index = 0 self.cursor_index = 0 - self.inverted = not self.inverted redraw = True + else: + self.cursor_index += 1 + if self.cursor_index >= n_windows - 1: + # We have reached the end of the page - flip the orientation + self.page_index += (self.step * self.cursor_index) + self.cursor_index = 0 + self.inverted = not self.inverted + redraw = True else: if self.cursor_index > 0: self.cursor_index -= 1 else: if self._is_valid(self.page_index - self.step): + # We have reached the beginning of the page - move the index self.page_index -= self.step redraw = True else: @@ -179,11 +187,11 @@ class BasePage(object): def _edit_cursor(self, attribute): - # Don't alow the cursor to go below page index 0 - if self.nav.absolute_index == -1: - window = self._subwindows[self.nav.cursor_index + 1] - else: - window = self._subwindows[self.nav.cursor_index] + # Don't allow the cursor to go below page index 0 + if self.nav.absolute_index < 0: + return + + window = self._subwindows[self.nav.cursor_index] n_rows, _ = window.getmaxyx() for row in xrange(n_rows): diff --git a/rtv/submission.py b/rtv/submission.py index 6a3ac7e..874a5bf 100644 --- a/rtv/submission.py +++ b/rtv/submission.py @@ -18,8 +18,7 @@ class SubmissionPage(BasePage): else: raise ValueError('Must specify url or submission') - super(SubmissionPage, self).__init__( - stdscr, content, page_index=-1, cursor_index=1) + super(SubmissionPage, self).__init__(stdscr, content, page_index=-1) def loop(self): diff --git a/rtv/subreddit.py b/rtv/subreddit.py index 0f50e90..b910f07 100644 --- a/rtv/subreddit.py +++ b/rtv/subreddit.py @@ -33,7 +33,7 @@ class SubredditPage(BasePage): self.clear_input_queue() # View submission - elif cmd in (curses.KEY_RIGHT, ord(' ')): + elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord(' '), 10): self.open_submission() self.draw()