Cursor blinks on first line. Not sure how I feel about this.
This commit is contained in:
@@ -16,15 +16,10 @@ class SubredditViewer(BaseViewer):
|
||||
self._n_cols = None
|
||||
self._title_window = None
|
||||
self._content_window = None
|
||||
self._sub_windows = None
|
||||
|
||||
super(SubredditViewer, self).__init__(subreddit_content)
|
||||
self.draw()
|
||||
|
||||
@property
|
||||
def n_subwindows(self):
|
||||
return len(self._sub_windows)
|
||||
|
||||
def loop(self):
|
||||
while True:
|
||||
cmd = self.stdscr.getch()
|
||||
@@ -72,7 +67,7 @@ class SubredditViewer(BaseViewer):
|
||||
|
||||
n_rows, n_cols = self._content_window.getmaxyx()
|
||||
self._content_window.erase()
|
||||
self._sub_windows = []
|
||||
self._subwindows = []
|
||||
|
||||
page_index, cursor_index, inverted = self.nav.position
|
||||
step = self.nav.step
|
||||
@@ -87,7 +82,7 @@ class SubredditViewer(BaseViewer):
|
||||
start = current_row - window_rows if inverted else current_row
|
||||
window = self._content_window.derwin(window_rows, n_cols, start, 0)
|
||||
self.draw_submission(window, data, inverted)
|
||||
self._sub_windows.append(window)
|
||||
self._subwindows.append(window)
|
||||
available_rows -= (window_rows + 1) # Add one for the blank line
|
||||
current_row += step * (window_rows + 1)
|
||||
if available_rows <= 0:
|
||||
|
||||
@@ -49,5 +49,4 @@ def curses_session():
|
||||
stdscr.keypad(0)
|
||||
curses.echo()
|
||||
curses.nocbreak()
|
||||
curses.endwin()
|
||||
|
||||
curses.endwin()
|
||||
@@ -74,14 +74,11 @@ class BaseViewer(object):
|
||||
|
||||
self.content = content
|
||||
self.nav = Navigator(self.content.get)
|
||||
self._subwindows = None
|
||||
|
||||
def draw_content(self):
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def n_subwindows(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def move_cursor_up(self):
|
||||
self._move_cursor(-1)
|
||||
|
||||
@@ -89,16 +86,18 @@ class BaseViewer(object):
|
||||
self._move_cursor(1)
|
||||
|
||||
def add_cursor(self):
|
||||
curses.curs_set(2)
|
||||
self._edit_cursor(curses.A_REVERSE)
|
||||
|
||||
def remove_cursor(self):
|
||||
curses.curs_set(0)
|
||||
self._edit_cursor(curses.A_NORMAL)
|
||||
|
||||
def _move_cursor(self, direction):
|
||||
|
||||
self.remove_cursor()
|
||||
|
||||
valid, redraw = self.nav.move(direction, self.n_subwindows)
|
||||
valid, redraw = self.nav.move(direction, len(self._subwindows))
|
||||
if not valid:
|
||||
curses.flash()
|
||||
if redraw:
|
||||
@@ -108,8 +107,11 @@ class BaseViewer(object):
|
||||
|
||||
def _edit_cursor(self, attribute):
|
||||
|
||||
window = self._sub_windows[self.nav.cursor_index]
|
||||
window = self._subwindows[self.nav.cursor_index]
|
||||
|
||||
n_rows, _ = window.getmaxyx()
|
||||
for row in xrange(n_rows):
|
||||
window.chgat(row, 0, 1, attribute)
|
||||
window.move(0, 0)
|
||||
|
||||
window.refresh()
|
||||
Reference in New Issue
Block a user