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