commit 68cb4ab6a854d41aab575c5f0ac934aa263b6444 Author: Damian Johnson atagar@torproject.org Date: Sun Apr 17 12:52:52 2016 -0700
Draw helper for status message
Just a small helper so this can be uniform with the rest. --- nyx/panel/header.py | 24 ++++++++++++++++-------- test/panel/header.py | 10 ++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/nyx/panel/header.py b/nyx/panel/header.py index 84b4b38..115bd3b 100644 --- a/nyx/panel/header.py +++ b/nyx/panel/header.py @@ -56,7 +56,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread): self._reported_inactive = False
self._message = None - self._message_attr = None + self._message_attr = []
tor_controller().add_status_listener(self.reset_listener)
@@ -197,13 +197,7 @@ class HeaderPanel(nyx.panel.Panel, threading.Thread): _draw_fingerprint_and_fd_usage(subwindow, 0, 3, left_width, vals) _draw_flags(subwindow, 0, 4, vals.flags)
- if self._message: - subwindow.addstr(0, subwindow.height - 1, self._message, *self._message_attr) - elif not self.is_paused(): - controller = nyx.controller.get_controller() - subwindow.addstr(0, subwindow.height - 1, 'page %i / %i - m: menu, p: pause, h: page help, q: quit' % (controller.get_page() + 1, controller.get_page_count())) - else: - subwindow.addstr(0, subwindow.height - 1, 'Paused', HIGHLIGHT) + _draw_status(subwindow, 0, subwindow.height - 1, self.is_paused(), self._message, *self._message_attr)
def run(self): """ @@ -544,3 +538,17 @@ def _draw_newnym_option(subwindow, x, y, newnym_wait): else: plural = 's' if newnym_wait > 1 else '' subwindow.addstr(x, y, 'building circuits, available again in %i second%s' % (newnym_wait, plural)) + + +def _draw_status(subwindow, x, y, is_paused, message, *attr): + """ + Provides general usage information or a custom message. + """ + + if message: + subwindow.addstr(x, y, message, *attr) + elif not is_paused: + controller = nyx.controller.get_controller() + subwindow.addstr(x, y, 'page %i / %i - m: menu, p: pause, h: page help, q: quit' % (controller.get_page() + 1, controller.get_page_count())) + else: + subwindow.addstr(x, y, 'Paused', HIGHLIGHT) diff --git a/test/panel/header.py b/test/panel/header.py index e601f00..58f700c 100644 --- a/test/panel/header.py +++ b/test/panel/header.py @@ -275,3 +275,13 @@ class TestHeader(unittest.TestCase): self.assertEqual("press 'n' for a new identity", test.render(nyx.panel.header._draw_newnym_option, 0, 0, 0).content) self.assertEqual('building circuits, available again in 1 second', test.render(nyx.panel.header._draw_newnym_option, 0, 0, 1).content) self.assertEqual('building circuits, available again in 5 seconds', test.render(nyx.panel.header._draw_newnym_option, 0, 0, 5).content) + + @require_curses + @patch('nyx.controller.get_controller') + def test_draw_status(self, nyx_controller_mock): + nyx_controller_mock().get_page.return_value = 1 + nyx_controller_mock().get_page_count.return_value = 4 + + self.assertEqual('page 2 / 4 - m: menu, p: pause, h: page help, q: quit', test.render(nyx.panel.header._draw_status, 0, 0, False, None).content) + self.assertEqual('Paused', test.render(nyx.panel.header._draw_status, 0, 0, True, None).content) + self.assertEqual('pepperjack is wonderful!', test.render(nyx.panel.header._draw_status, 0, 0, False, 'pepperjack is wonderful!').content)