[tor-commits] [nyx/master] Revise event selector dialog
atagar at torproject.org
atagar at torproject.org
Tue Apr 5 01:47:44 UTC 2016
commit 2ab1b5f2f2f90ea11383c091b0b86202b7c3ca5d
Author: Damian Johnson <atagar at torproject.org>
Date: Mon Apr 4 17:11:33 2016 -0700
Revise event selector dialog
There's a couple popups left within the panels. Moving, cleaning up, and
testing.
---
nyx/panel/log.py | 31 ++++---------------------------
nyx/popups.py | 37 +++++++++++++++++++++++++++++++++++++
test/popups.py | 33 +++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 27 deletions(-)
diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index 4582885..364878f 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -43,7 +43,6 @@ CONFIG = conf.config_dict('nyx', {
'features.log.prepopulateReadLimit': 5000,
'features.log.maxRefreshRate': 300,
'features.log.regex': [],
- 'msg.misc.event_types': '',
'startup.events': 'N3',
}, conf_handler)
@@ -142,33 +141,11 @@ class LogPanel(nyx.panel.Panel, threading.Thread):
Prompts the user to select the events being listened for.
"""
- # allow user to enter new types of events to log - unchanged if left blank
+ event_types = nyx.popups.show_event_selector()
- with nyx.popups.popup_window(16, 80) as (popup, width, height):
- if popup:
- # displays the available flags
-
- popup.draw_box()
- popup.addstr(0, 0, 'Event Types:', HIGHLIGHT)
- event_lines = CONFIG['msg.misc.event_types'].split('\n')
-
- for i in range(len(event_lines)):
- popup.addstr(i + 1, 1, event_lines[i][6:])
-
- popup.win.refresh()
-
- user_input = nyx.controller.input_prompt('Events to log: ')
-
- if user_input:
- try:
- user_input = user_input.replace(' ', '') # strip spaces
- event_types = nyx.arguments.expand_events(user_input)
-
- if event_types != self._event_types:
- self._event_types = nyx.log.listen_for_events(self._register_tor_event, event_types)
- self.redraw(True)
- except ValueError as exc:
- nyx.controller.show_message('Invalid flags: %s' % exc, HIGHLIGHT, max_wait = 2)
+ if event_types != self._event_types:
+ self._event_types = nyx.log.listen_for_events(self._register_tor_event, event_types)
+ self.redraw(True)
def show_snapshot_prompt(self):
"""
diff --git a/nyx/popups.py b/nyx/popups.py
index 4bf14fe..3160949 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -9,12 +9,15 @@ import math
import operator
import nyx
+import nyx.arguments
import nyx.controller
import nyx.curses
import nyx.panel
from nyx.curses import RED, GREEN, YELLOW, CYAN, WHITE, NORMAL, BOLD, HIGHLIGHT
+import stem.util.conf
+
NO_STATS_MSG = "Usage stats aren't available yet, press any key..."
HEADERS = ['Consensus:', 'Microdescriptor:', 'Server Descriptor:']
@@ -26,6 +29,10 @@ BLOCK_START, BLOCK_END = '-----BEGIN ', '-----END '
UNRESOLVED_MSG = 'No consensus data available'
ERROR_MSG = 'Unable to retrieve data'
+CONFIG = stem.util.conf.config_dict('nyx', {
+ 'msg.misc.event_types': '',
+})
+
def popup_window(height = -1, width = -1, top = 0, left = 0, below_static = True):
"""
@@ -308,6 +315,36 @@ def show_sort_dialog(title, options, previous_order, option_colors):
return new_order
+def show_event_selector():
+ """
+ Presents a chart of event types we support, with a prompt for the user to
+ select a set.
+
+ :returns: **list** of event types the user has selected or **None** if dialog
+ is canceled
+ """
+
+ def _render(subwindow):
+ subwindow.box()
+ subwindow.addstr(0, 0, 'Event Types:', HIGHLIGHT)
+
+ for i, line in enumerate(CONFIG['msg.misc.event_types'].split('\n')):
+ subwindow.addstr(1, i + 1, line[6:])
+
+ with nyx.curses.CURSES_LOCK:
+ nyx.curses.draw(_render, top = _top(), width = 80, height = 16)
+ user_input = nyx.controller.input_prompt('Events to log: ')
+
+ if user_input:
+ try:
+ user_input = user_input.replace(' ', '') # strip spaces
+ return nyx.arguments.expand_events(user_input)
+ except ValueError as exc:
+ nyx.controller.show_message('Invalid flags: %s' % exc, HIGHLIGHT, max_wait = 2)
+
+ return None
+
+
def show_descriptor(fingerprint, color, is_close_key):
"""
Provides a dialog showing descriptors for a relay.
diff --git a/test/popups.py b/test/popups.py
index 2a308f0..e34398b 100644
--- a/test/popups.py
+++ b/test/popups.py
@@ -90,6 +90,25 @@ Config Option Ordering:--------------------------------------------------------+
+------------------------------------------------------------------------------+
""".strip()
+EXPECTED_EVENT_SELECTOR = """
+Event Types:-------------------------------------------------------------------+
+| d DEBUG a ADDRMAP r CLIENTS_SEEN C SIGNAL |
+| i INFO f AUTHDIR_NEWDESCS u DESCCHANGED F STREAM_BW |
+| n NOTICE j BUILDTIMEOUT_SET g GUARD G STATUS_CLIENT |
+| w WARN b BW h HS_DESC H STATUS_GENERAL |
+| e ERR k CELL_STATS v HS_DESC_CONTENT I STATUS_SERVER |
+| c CIRC x NETWORK_LIVENESS s STREAM |
+| l CIRC_BW y NEWCONSENSUS J TB_EMPTY |
+| m CIRC_MINOR z NEWDESC t TRANSPORT_LAUNCHED |
+| p CONF_CHANGED B NS |
+| q CONN_BW o ORCONN |
+| |
+| DINWE tor runlevel+ A All Events |
+| 12345 nyx runlevel+ X No Events |
+| U Unknown Events |
++------------------------------------------------------------------------------+
+""".strip()
+
EXPECTED_DESCRIPTOR_WITHOUT_FINGERPRINT = """
Consensus Descriptor:----------+
| No consensus data available |
@@ -253,6 +272,20 @@ class TestPopups(unittest.TestCase):
self.assertEqual(['Name', 'Summary', 'Description'], rendered.return_value)
@patch('nyx.popups._top', Mock(return_value = 0))
+ @patch('nyx.controller.input_prompt', Mock(return_value = None))
+ def test_event_selector_when_canceled(self):
+ rendered = test.render(nyx.popups.show_event_selector)
+ self.assertEqual(EXPECTED_EVENT_SELECTOR, rendered.content)
+ self.assertEqual(None, rendered.return_value)
+
+ @patch('nyx.popups._top', Mock(return_value = 0))
+ @patch('nyx.controller.input_prompt', Mock(return_value = '2bwe'))
+ def test_event_selector_with_input(self):
+ rendered = test.render(nyx.popups.show_event_selector)
+ self.assertEqual(EXPECTED_EVENT_SELECTOR, rendered.content)
+ self.assertEqual(set(['NYX_INFO', 'ERR', 'WARN', 'BW', 'NYX_ERR', 'NYX_WARN', 'NYX_NOTICE']), rendered.return_value)
+
+ @patch('nyx.popups._top', Mock(return_value = 0))
def test_descriptor_without_fingerprint(self):
rendered = test.render(nyx.popups.show_descriptor, None, nyx.curses.Color.RED, lambda key: key.match('esc'))
self.assertEqual(EXPECTED_DESCRIPTOR_WITHOUT_FINGERPRINT, rendered.content)
More information about the tor-commits
mailing list