[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [nyx/master] Interpreter panel broke after 100 inputs
commit c15e90aebb9c8397523c6bf5173f59baa4227cb2
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Thu Jul 28 10:47:38 2016 -0700
Interpreter panel broke after 100 inputs
Guessing this is a leftover debugging statement?
raise Exception(self._backlog)
Can't think of any reason for it to be there, and it quite simply broke us when
the user entered their 100th input.
Inverting the order our backlog handler accepts to make our panel a little more
efficient (there's no reason to invert our inputs on every call).
---
nyx/curses.py | 21 ++++++++++++++-------
nyx/panel/interpreter.py | 10 ++++------
2 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/nyx/curses.py b/nyx/curses.py
index 10ac4f0..b5819cc 100644
--- a/nyx/curses.py
+++ b/nyx/curses.py
@@ -274,7 +274,8 @@ def str_input(x, y, initial_text = '', backlog = None, tab_completion = None):
:param int x: horizontal location
:param int y: vertical location
:param str initial_text: initial input of the field
- :param list backlog: previous inputs that can be selected by pressing up/down
+ :param list backlog: previous inputs that can be selected by pressing
+ up/down, oldest to newest
:param func tab_completion: function to suggest inputs to tab complete with
:returns: **str** with the user input or **None** if the prompt is canceled
@@ -395,24 +396,30 @@ class _TextBacklog(object):
"""
def __init__(self, backlog = []):
- self._backlog = backlog # backlog contents, newest to oldest
- self._selection = -1 # selected item, -1 if we're not on the backlog
+ self._backlog = backlog # backlog contents, oldest to newest
+ self._selection = None # selected item, None if we're not on the backlog
self._custom_input = '' # field's input prior to selecting a backlog item
def _handler(self, next_handler, textbox, key):
if key in (curses.KEY_UP, curses.KEY_DOWN):
if key == curses.KEY_UP:
- new_selection = min(len(self._backlog) - 1, self._selection + 1)
+ if self._selection is None:
+ new_selection = len(self._backlog) - 1
+ else:
+ new_selection = max(0, self._selection - 1)
else:
- new_selection = max(-1, self._selection - 1)
+ if self._selection is None or self._selection == len(self._backlog) - 1:
+ new_selection = None
+ else:
+ new_selection = self._selection + 1
if self._selection == new_selection:
return None
- if self._selection == -1:
+ if self._selection is None:
self._custom_input = textbox.gather().strip() # save custom input
- new_input = self._custom_input if new_selection == -1 else self._backlog[new_selection]
+ new_input = self._custom_input if new_selection is None else self._backlog[new_selection]
y, _ = textbox.win.getyx()
_, max_x = textbox.win.getmaxyx()
diff --git a/nyx/panel/interpreter.py b/nyx/panel/interpreter.py
index c9d557d..915210b 100644
--- a/nyx/panel/interpreter.py
+++ b/nyx/panel/interpreter.py
@@ -53,8 +53,8 @@ class InterpreterPanel(panel.Panel):
self._is_input_mode = False
self._x_offset = 0
self._scroller = nyx.curses.Scroller()
- self._backlog = []
self._lines = []
+ self._backlog = [] # previous user inputs
controller = tor_controller()
self._autocompleter = stem.interpreter.autocomplete.Autocompleter(controller)
@@ -75,18 +75,16 @@ 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), '', list(reversed(self._backlog)), self._autocompleter.matches)
+ 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
if not user_input:
is_done = True
else:
self._backlog.append(user_input)
- backlog_crop = len(self._backlog) - BACKLOG_LIMIT
- if backlog_crop > 0:
- raise Exception(self._backlog)
- self._backlog = self._backlog[backlog_crop:]
+ if len(self._backlog) > BACKLOG_LIMIT:
+ self._backlog = self._backlog[-BACKLOG_LIMIT:]
try:
console_called = False
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits