[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Drop python command support
commit b55c9176e49fabc701ec81c97de121e06575c4e0
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Jul 29 09:46:09 2016 -0700
Drop python command support
Hopefully it's temporary, we'll see. What we have here isn't a useful starting
place. It uses Mock and stdout/stderr making it DOA. That aside, it doesn't
work very well. Multi-line commands like the following break...
for i in range(5):
print i
---
nyx/panel/interpreter.py | 49 +++++++++++++++++-------------------------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index 915210b..cf0f261 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -3,14 +3,10 @@ Panel providing raw control port access with syntax hilighting, usage
information, tab completion, and other usability features.
"""
-import code
import curses
import nyx.controller
import nyx.curses
-import sys
-from cStringIO import StringIO
-from mock import patch
from nyx.curses import GREEN, MAGENTA, CYAN, BOLD, HIGHLIGHT
from nyx import tor_controller, panel
@@ -19,7 +15,7 @@ import stem.interpreter.autocomplete
import stem.interpreter.commands
-BACKLOG_LIMIT = 100
+USER_INPUT_BACKLOG_LIMIT = 100
PROMPT = [('>>> ', (GREEN, BOLD)), ('to use this panel press enter', (CYAN, BOLD))]
@@ -54,11 +50,12 @@ class InterpreterPanel(panel.Panel):
self._x_offset = 0
self._scroller = nyx.curses.Scroller()
self._lines = []
- self._backlog = [] # previous user inputs
+ self._user_inputs = [] # previous user inputs
controller = tor_controller()
self._autocompleter = stem.interpreter.autocomplete.Autocompleter(controller)
self._interpreter = stem.interpreter.commands.ControlInterpretor(controller)
+ self._interpreter._run_python_commands = False
def key_handlers(self):
def _scroll(key):
@@ -75,34 +72,24 @@ class InterpreterPanel(panel.Panel):
self.redraw()
_scroll(nyx.curses.KeyInput(curses.KEY_END))
page_height = self.get_height() - 1
- user_input = nyx.curses.str_input(4 + self._x_offset, self.get_top() + max(len(self._lines[-page_height:]), 1), '', self._backlog, self._autocompleter.matches)
- user_input, is_done = user_input.strip(), False
+
+ user_input = nyx.curses.str_input(
+ 4 + self._x_offset,
+ self.get_top() + max(len(self._lines[-page_height:]), 1),
+ backlog = self._user_inputs,
+ tab_completion = self._autocompleter.matches
+ ).strip()
if not user_input:
- is_done = True
+ self._is_input_mode = False
else:
- self._backlog.append(user_input)
+ self._user_inputs.append(user_input)
- if len(self._backlog) > BACKLOG_LIMIT:
- self._backlog = self._backlog[-BACKLOG_LIMIT:]
+ if len(self._user_inputs) > USER_INPUT_BACKLOG_LIMIT:
+ self._user_inputs = self._user_inputs[-USER_INPUT_BACKLOG_LIMIT:]
try:
- console_called = False
-
- with patch('stem.interpreter.commands.code.InteractiveConsole.push') as console_push:
- response = self._interpreter.run_command(user_input)
-
- if console_push.called:
- console_called = True
-
- if console_called:
- old_stderr = sys.stderr
- sys.stderr = new_stderr = StringIO()
- interactive_console = code.InteractiveConsole()
- interactive_console.push(user_input)
- sys.stderr = old_stderr
- response = '\x1b[31;1m' + new_stderr.getvalue()
- sys.stderr = old_stderr
+ response = self._interpreter.run_command(user_input)
if response:
self._lines.append(format_input(user_input))
@@ -110,11 +97,9 @@ class InterpreterPanel(panel.Panel):
for line in response.split('\n'):
self._lines.append([(text, attr) for text, attr in nyx.curses.asci_to_curses(line)])
except stem.SocketClosed:
- is_done = True
+ self._is_input_mode = False
- if is_done:
- self._is_input_mode = False
- self.redraw()
+ self.redraw()
return (
nyx.panel.KeyHandler('enter', 'execute a command', _execute_command, key_func = lambda key: key.is_selection()),
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits