commit bd33fb6afefc39805720c5dc27b2f563c7637de5 Author: Sambuddha Basu sambuddhabasu1@gmail.com Date: Fri Jun 17 20:30:59 2016 -0700
Added basic interpretor panel --- nyx/controller.py | 5 +++++ nyx/panel/interpretor.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
diff --git a/nyx/controller.py b/nyx/controller.py index d2f202f..c167c9a 100644 --- a/nyx/controller.py +++ b/nyx/controller.py @@ -20,6 +20,7 @@ import nyx.panel.graph import nyx.panel.header import nyx.panel.log import nyx.panel.torrc +import nyx.panel.interpretor
import stem
@@ -46,6 +47,7 @@ CONFIG = conf.config_dict('nyx', { 'features.panels.show.connection': True, 'features.panels.show.config': True, 'features.panels.show.torrc': True, + 'features.panels.show.interpretor': True, 'features.redrawRate': 5, 'features.refreshRate': 5, 'features.confirmQuit': True, @@ -118,6 +120,9 @@ class Controller(object): if CONFIG['features.panels.show.torrc']: self._page_panels.append([nyx.panel.torrc.TorrcPanel()])
+ if CONFIG['features.panels.show.interpretor']: + self._page_panels.append([nyx.panel.interpretor.InterpretorPanel()]) + self.quit_signal = False self._page = 0 self._paused = False diff --git a/nyx/panel/interpretor.py b/nyx/panel/interpretor.py new file mode 100644 index 0000000..995490c --- /dev/null +++ b/nyx/panel/interpretor.py @@ -0,0 +1,49 @@ +""" +Panel providing raw control port access with syntax hilighting, usage +information, tab completion, and other usability features. +""" + +import nyx.curses + +from nyx.curses import GREEN, CYAN, BOLD, HIGHLIGHT +from nyx import panel + + +USAGE_INFO = "to use this panel press enter" +PROMPT = ">>> " +PROMPT_LINE = [[(PROMPT, GREEN, BOLD), (USAGE_INFO, CYAN, BOLD)]] + +class InterpretorPanel(panel.Panel): + """ + Renders the current torrc or nyxrc with syntax highlighting in a scrollable + area. + """ + + def __init__(self): + panel.Panel.__init__(self, 'interpretor') + + self._is_input_mode = False + + def key_handlers(self): + def _execute_command(): + self._is_input_mode ^= True + self.redraw(True) + + return ( + nyx.panel.KeyHandler('enter', 'execute a command', _execute_command, key_func = lambda key: key.is_selection()), + ) + + def draw(self, width, height): + usage_msg = " (enter "/help" for usage or a blank line to stop)" if self._is_input_mode else "" + self.addstr(0, 0, 'Control Interpretor%s:' % usage_msg, HIGHLIGHT) + + x_offset = 0 + draw_line = 1 + for entry in PROMPT_LINE: + cursor = x_offset + + for msg, color, attr in entry: + self.addstr(draw_line, cursor, msg, color, attr) + cursor += len(msg) + + draw_line += 1