Finally made progress on scrolling behavior for short submissions.
This commit is contained in:
@@ -68,6 +68,12 @@ class BaseContent(object):
|
||||
def iterate(self, index, step, n_cols):
|
||||
|
||||
while True:
|
||||
|
||||
# Hack to prevent displaying negative indicies if iterating in the
|
||||
# negative direction.
|
||||
if step < 0 and index < 0:
|
||||
break
|
||||
|
||||
try:
|
||||
yield self.get(index, n_cols=n_cols)
|
||||
except IndexError:
|
||||
|
||||
37
rtv/page.py
37
rtv/page.py
@@ -52,18 +52,15 @@ class Navigator(object):
|
||||
valid = False
|
||||
else:
|
||||
self.cursor_index += 1
|
||||
if self.cursor_index >= n_windows - 1:
|
||||
# We have reached the end of the page
|
||||
if self._is_valid(self.absolute_index):
|
||||
# Flip the orientation
|
||||
self.page_index += (self.step * self.cursor_index)
|
||||
self.cursor_index = 0
|
||||
self.inverted = not self.inverted
|
||||
redraw = True
|
||||
else:
|
||||
# Unless we are at the absolute end of the submission
|
||||
self.cursor_index -= 1 # Revert
|
||||
if not self._is_valid(self.absolute_index):
|
||||
# Move would take us out of bounds
|
||||
self.cursor_index -= 1
|
||||
valid = False
|
||||
elif self.cursor_index >= (n_windows - 1):
|
||||
# Flip the orientation and reset the cursor
|
||||
self.flip(self.cursor_index)
|
||||
self.cursor_index = 0
|
||||
redraw = True
|
||||
else:
|
||||
if self.cursor_index > 0:
|
||||
self.cursor_index -= 1
|
||||
@@ -78,12 +75,17 @@ class Navigator(object):
|
||||
|
||||
return valid, redraw
|
||||
|
||||
def flip(self, n_windows):
|
||||
"Flip the orientation of the page"
|
||||
self.page_index += (self.step * n_windows)
|
||||
self.cursor_index = n_windows
|
||||
self.inverted = not self.inverted
|
||||
|
||||
def _is_valid(self, page_index):
|
||||
"Check if a page index will cause entries to fall outside valid range"
|
||||
|
||||
try:
|
||||
self._page_cb(page_index)
|
||||
self._page_cb(page_index + self.step * self.cursor_index)
|
||||
except IndexError:
|
||||
return False
|
||||
else:
|
||||
@@ -185,6 +187,15 @@ class BasePage(object):
|
||||
current_row += step * (window_rows + 1)
|
||||
if available_rows <= 0:
|
||||
break
|
||||
else:
|
||||
# If the page is not full we need to make sure that it is NOT
|
||||
# inverted. Unfortunately, this currently means drawing the whole
|
||||
# page over again. Could not think of a better way to pre-determine
|
||||
# if the content will fill up the page, given that it is dependent
|
||||
# on the size of the terminal.
|
||||
if self.nav.inverted:
|
||||
self.nav.flip((len(self._subwindows) - 1))
|
||||
self._draw_content()
|
||||
|
||||
self._content_window.refresh()
|
||||
|
||||
@@ -196,7 +207,7 @@ class BasePage(object):
|
||||
if not valid:
|
||||
curses.flash()
|
||||
|
||||
# If we don't redraw, ACS_VLINE gets screwed up when changing the
|
||||
# TODO: If we don't redraw, ACS_VLINE gets screwed up when changing the
|
||||
# attr back to normal. There may be a way around this.
|
||||
if True: #if redraw
|
||||
self._draw_content()
|
||||
|
||||
@@ -39,10 +39,12 @@ class SubmissionPage(BasePage):
|
||||
# Refresh page
|
||||
elif cmd in (curses.KEY_F5, ord('r')):
|
||||
self.refresh_content()
|
||||
self.draw()
|
||||
|
||||
# Show / hide a comment tree
|
||||
elif cmd in (curses.KEY_RIGHT, ord(' ')):
|
||||
self.toggle_comment()
|
||||
self.draw()
|
||||
|
||||
elif cmd == curses.KEY_RESIZE:
|
||||
self.draw()
|
||||
@@ -61,14 +63,12 @@ class SubmissionPage(BasePage):
|
||||
def toggle_comment(self):
|
||||
|
||||
self.content.toggle(self.nav.absolute_index)
|
||||
self.draw()
|
||||
|
||||
def refresh_content(self):
|
||||
|
||||
self.content.reset()
|
||||
self.nav.page_index, self.nav.cursor_index = -1, 0
|
||||
self.nav.inverted = False
|
||||
self.draw()
|
||||
|
||||
def draw_item(self, win, data, inverted=False):
|
||||
|
||||
|
||||
@@ -36,10 +36,12 @@ class SubredditPage(BasePage):
|
||||
# View submission
|
||||
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord(' '), 10):
|
||||
self.open_submission()
|
||||
self.draw()
|
||||
|
||||
# Enter edit mode to change subreddit
|
||||
elif cmd == ord('/'):
|
||||
self.prompt_subreddit()
|
||||
self.draw()
|
||||
|
||||
# Refresh page
|
||||
elif cmd in (curses.KEY_F5, ord('r')):
|
||||
@@ -72,8 +74,6 @@ class SubredditPage(BasePage):
|
||||
self.nav.inverted = False
|
||||
self.name = name
|
||||
|
||||
self.draw()
|
||||
|
||||
def prompt_subreddit(self):
|
||||
|
||||
attr = curses.A_BOLD | Color.MAGENTA
|
||||
@@ -85,9 +85,7 @@ class SubredditPage(BasePage):
|
||||
window.attrset(attr)
|
||||
|
||||
out = text_input(window)
|
||||
if out is None:
|
||||
self.draw()
|
||||
else:
|
||||
if out is not None:
|
||||
self.refresh_content(name=out)
|
||||
|
||||
def open_submission(self):
|
||||
|
||||
Reference in New Issue
Block a user