commit 2f7c528340181b5945e149779f82e46107a64427 Author: Damian Johnson atagar@torproject.org Date: Wed Sep 27 14:16:31 2017 -0700
Redraw right away when actions are taken
Unnecessarily providing the 'forced' flag when redrawing can cause screen flickering, but omitting it causes actions to not be visible. For instance, when the relay is inactive changing pages takes seconds to appear. --- nyx/__init__.py | 10 +++++----- nyx/curses.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py index c134a53..7475878 100644 --- a/nyx/__init__.py +++ b/nyx/__init__.py @@ -167,8 +167,6 @@ def draw_loop(): stem.util.log.info('nyx started (initialization took %0.1f seconds)' % (time.time() - CONFIG['start_time']))
while not interface._quit: - interface.redraw() - if next_key: key, next_key = next_key, None else: @@ -200,11 +198,13 @@ def draw_loop(): stem.util.log.error('Error detected when reloading tor: %s' % exc.strerror) elif key.match('h'): next_key = nyx.popups.show_help() - else: + elif not key.is_null(): for panel in interface.page_panels(): for keybinding in panel.key_handlers(): keybinding.handle(key)
+ interface.redraw(force = not key.is_null()) +
def nyx_interface(): """ @@ -666,7 +666,7 @@ class Interface(object): for panel in self.page_panels(): panel.redraw()
- def redraw(self): + def redraw(self, force = False): """ Renders our displayed content. """ @@ -674,7 +674,7 @@ class Interface(object): occupied = 0
for panel in self.page_panels(): - panel.redraw(force = False, top = occupied) + panel.redraw(force = force, top = occupied) occupied += panel.get_height()
def quit(self): diff --git a/nyx/curses.py b/nyx/curses.py index 0caf8f4..73db19e 100644 --- a/nyx/curses.py +++ b/nyx/curses.py @@ -938,6 +938,9 @@ class KeyInput(object): page_up, page_down, and esc. """
+ if self.is_null(): + return False + for key in keys: if key in SPECIAL_KEYS: if self._key == SPECIAL_KEYS[key]: @@ -950,6 +953,13 @@ class KeyInput(object):
return False
+ def is_null(self): + """ + True if there wasn't a key event (key_input() timed out). + """ + + return self._key == -1 + def is_scroll(self): """ True if the key is used for scrolling, false otherwise.