[tor-commits] [stem/master] Readline history can screw up the prompt
atagar at torproject.org
atagar at torproject.org
Tue May 6 01:21:13 UTC 2014
commit 6945b02706ca7c49bb75447ebc05a6721ae15759
Author: Damian Johnson <atagar at torproject.org>
Date: Thu Apr 17 09:53:36 2014 -0700
Readline history can screw up the prompt
Something between raw_input() and readline history has a bug for color prompts
like ours. Certain histories cause our prompt to be widened. Widening our
initial prompt with invisiable characters (like resets) seems to mitigate this.
And yes, this is quite a hack. :(
Steps to repro for python 2.7.1...
1. Start prompt.
2. Type "/help GETINFO version".
3. Press 'up' to render that command. Your prompt should now look screwed up.
4. Press 'down' to return to what should be a blank prompt. You'll still be
offset several characters to the right.
---
stem/interpretor/__init__.py | 13 ++++++-------
stem/interpretor/arguments.py | 3 ++-
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/stem/interpretor/__init__.py b/stem/interpretor/__init__.py
index 3dce2a0..f1da5d9 100644
--- a/stem/interpretor/__init__.py
+++ b/stem/interpretor/__init__.py
@@ -13,19 +13,18 @@ import sys
import stem
import stem.connection
-import stem.prereq
import stem.util.conf
-from stem.util.term import Attr, Color, format
+from stem.util.term import RESET, Attr, Color, format
-# We can only present a color prompt with python 2.7 or later...
+# Our color prompt triggers a bug between raw_input() and readline history,
+# where scrolling through history widens our prompt. Widening our prompt via
+# invisible characters (like resets) seems to sidestep this bug for short
+# inputs. Contrary to the ticket, this still manifests with python 2.7.1...
#
# http://bugs.python.org/issue12972
-if stem.prereq.is_python_27():
- PROMPT = format(">>> ", Color.GREEN, Attr.BOLD)
-else:
- PROMPT = ">>> "
+PROMPT = format(">>> ", Color.GREEN, Attr.BOLD) + RESET * 10
def main():
diff --git a/stem/interpretor/arguments.py b/stem/interpretor/arguments.py
index ff25fb7..c2971b0 100644
--- a/stem/interpretor/arguments.py
+++ b/stem/interpretor/arguments.py
@@ -84,7 +84,8 @@ def get_help():
:returns: **str** with our usage information
"""
- return stem.interpretor.msg('msg.help',
+ return stem.interpretor.msg(
+ 'msg.help',
address = DEFAULT_ARGS['control_address'],
port = DEFAULT_ARGS['control_port'],
socket = DEFAULT_ARGS['control_socket'],
More information about the tor-commits
mailing list