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):
|
def iterate(self, index, step, n_cols):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
# Hack to prevent displaying negative indicies if iterating in the
|
||||||
|
# negative direction.
|
||||||
|
if step < 0 and index < 0:
|
||||||
|
break
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield self.get(index, n_cols=n_cols)
|
yield self.get(index, n_cols=n_cols)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|||||||
39
rtv/page.py
39
rtv/page.py
@@ -52,18 +52,15 @@ class Navigator(object):
|
|||||||
valid = False
|
valid = False
|
||||||
else:
|
else:
|
||||||
self.cursor_index += 1
|
self.cursor_index += 1
|
||||||
if self.cursor_index >= n_windows - 1:
|
if not self._is_valid(self.absolute_index):
|
||||||
# We have reached the end of the page
|
# Move would take us out of bounds
|
||||||
if self._is_valid(self.absolute_index):
|
self.cursor_index -= 1
|
||||||
# Flip the orientation
|
valid = False
|
||||||
self.page_index += (self.step * self.cursor_index)
|
elif self.cursor_index >= (n_windows - 1):
|
||||||
self.cursor_index = 0
|
# Flip the orientation and reset the cursor
|
||||||
self.inverted = not self.inverted
|
self.flip(self.cursor_index)
|
||||||
redraw = True
|
self.cursor_index = 0
|
||||||
else:
|
redraw = True
|
||||||
# Unless we are at the absolute end of the submission
|
|
||||||
self.cursor_index -= 1 # Revert
|
|
||||||
valid = False
|
|
||||||
else:
|
else:
|
||||||
if self.cursor_index > 0:
|
if self.cursor_index > 0:
|
||||||
self.cursor_index -= 1
|
self.cursor_index -= 1
|
||||||
@@ -78,12 +75,17 @@ class Navigator(object):
|
|||||||
|
|
||||||
return valid, redraw
|
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):
|
def _is_valid(self, page_index):
|
||||||
"Check if a page index will cause entries to fall outside valid range"
|
"Check if a page index will cause entries to fall outside valid range"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._page_cb(page_index)
|
self._page_cb(page_index)
|
||||||
self._page_cb(page_index + self.step * self.cursor_index)
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
@@ -185,6 +187,15 @@ class BasePage(object):
|
|||||||
current_row += step * (window_rows + 1)
|
current_row += step * (window_rows + 1)
|
||||||
if available_rows <= 0:
|
if available_rows <= 0:
|
||||||
break
|
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()
|
self._content_window.refresh()
|
||||||
|
|
||||||
@@ -196,7 +207,7 @@ class BasePage(object):
|
|||||||
if not valid:
|
if not valid:
|
||||||
curses.flash()
|
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.
|
# attr back to normal. There may be a way around this.
|
||||||
if True: #if redraw
|
if True: #if redraw
|
||||||
self._draw_content()
|
self._draw_content()
|
||||||
|
|||||||
@@ -39,10 +39,12 @@ class SubmissionPage(BasePage):
|
|||||||
# Refresh page
|
# Refresh page
|
||||||
elif cmd in (curses.KEY_F5, ord('r')):
|
elif cmd in (curses.KEY_F5, ord('r')):
|
||||||
self.refresh_content()
|
self.refresh_content()
|
||||||
|
self.draw()
|
||||||
|
|
||||||
# Show / hide a comment tree
|
# Show / hide a comment tree
|
||||||
elif cmd in (curses.KEY_RIGHT, ord(' ')):
|
elif cmd in (curses.KEY_RIGHT, ord(' ')):
|
||||||
self.toggle_comment()
|
self.toggle_comment()
|
||||||
|
self.draw()
|
||||||
|
|
||||||
elif cmd == curses.KEY_RESIZE:
|
elif cmd == curses.KEY_RESIZE:
|
||||||
self.draw()
|
self.draw()
|
||||||
@@ -61,14 +63,12 @@ class SubmissionPage(BasePage):
|
|||||||
def toggle_comment(self):
|
def toggle_comment(self):
|
||||||
|
|
||||||
self.content.toggle(self.nav.absolute_index)
|
self.content.toggle(self.nav.absolute_index)
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def refresh_content(self):
|
def refresh_content(self):
|
||||||
|
|
||||||
self.content.reset()
|
self.content.reset()
|
||||||
self.nav.page_index, self.nav.cursor_index = -1, 0
|
self.nav.page_index, self.nav.cursor_index = -1, 0
|
||||||
self.nav.inverted = False
|
self.nav.inverted = False
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def draw_item(self, win, data, inverted=False):
|
def draw_item(self, win, data, inverted=False):
|
||||||
|
|
||||||
|
|||||||
@@ -36,10 +36,12 @@ class SubredditPage(BasePage):
|
|||||||
# View submission
|
# View submission
|
||||||
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord(' '), 10):
|
elif cmd in (curses.KEY_RIGHT, curses.KEY_ENTER, ord(' '), 10):
|
||||||
self.open_submission()
|
self.open_submission()
|
||||||
|
self.draw()
|
||||||
|
|
||||||
# Enter edit mode to change subreddit
|
# Enter edit mode to change subreddit
|
||||||
elif cmd == ord('/'):
|
elif cmd == ord('/'):
|
||||||
self.prompt_subreddit()
|
self.prompt_subreddit()
|
||||||
|
self.draw()
|
||||||
|
|
||||||
# Refresh page
|
# Refresh page
|
||||||
elif cmd in (curses.KEY_F5, ord('r')):
|
elif cmd in (curses.KEY_F5, ord('r')):
|
||||||
@@ -72,8 +74,6 @@ class SubredditPage(BasePage):
|
|||||||
self.nav.inverted = False
|
self.nav.inverted = False
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
self.draw()
|
|
||||||
|
|
||||||
def prompt_subreddit(self):
|
def prompt_subreddit(self):
|
||||||
|
|
||||||
attr = curses.A_BOLD | Color.MAGENTA
|
attr = curses.A_BOLD | Color.MAGENTA
|
||||||
@@ -85,9 +85,7 @@ class SubredditPage(BasePage):
|
|||||||
window.attrset(attr)
|
window.attrset(attr)
|
||||||
|
|
||||||
out = text_input(window)
|
out = text_input(window)
|
||||||
if out is None:
|
if out is not None:
|
||||||
self.draw()
|
|
||||||
else:
|
|
||||||
self.refresh_content(name=out)
|
self.refresh_content(name=out)
|
||||||
|
|
||||||
def open_submission(self):
|
def open_submission(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user