[tor-commits] [arm/release] Source flags for color prompt and hostname lookups

atagar at torproject.org atagar at torproject.org
Sun Sep 25 21:38:29 UTC 2011


commit 6e88a85a7a8c45d798e8471e9ce27295aa0b122e
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue Sep 13 09:34:30 2011 -0700

    Source flags for color prompt and hostname lookups
    
    Adding source flags for portions of the interpretor that include substantial
    tradeoffs. For color prompts there's bugs in small displays/huge input, and
    hostname lookups add a second or two to the runtime of /info queries (otherwise
    the lookup is instantanious).
    
    Defaulting the hostname lookups to be disabled for now. There's plans for
    having cached results with...
    https://trac.torproject.org/projects/tor/wiki/doc/arm#CircuitDetails
    
    though I haven't a clue if it'll ever be implemented.
---
 src/util/torInterpretor.py |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index 2c4e7fa..fbb33da 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -11,6 +11,9 @@ import version
 
 from util import connections, enum, hostnames, torTools
 
+COLOR_PROMPT = True     # provides a colored interpretor prompt
+INFO_HOSTNAMES = False  # hostname lookups in /info results
+
 INIT_MSG = """Arm %s Control Interpretor
 Enter \"/help\" for usage information and \"/quit\" to stop.
 """ % version.VERSION
@@ -325,7 +328,11 @@ class ControlInterpretor:
       if not address or not port: return
       
       locale = conn.getInfo("ip-to-country/%s" % address, "??")
-      hostname = hostnames.resolve(address, 10)
+      
+      if INFO_HOSTNAMES:
+        hostname = hostnames.resolve(address, 10)
+      else:
+        hostname = None
       
       # TODO: Most of the following is copied from the _getDetailContent method
       # of cli/connections/connEntry.py - useful bits should be refactored.
@@ -370,8 +377,9 @@ class ControlInterpretor:
       
       outputEntry.append(("%s (%s)\n" % (nickname, fingerprint), infoAttr))
       
+      hostnameLabel = ", %s" % hostname if hostname else ""
       outputEntry.append(("address: ", headingAttr))
-      outputEntry.append(("%s:%s (%s, %s)\n" % (address, port, locale, hostname), infoAttr))
+      outputEntry.append(("%s:%s (%s%s)\n" % (address, port, locale, hostnameLabel), infoAttr))
       
       outputEntry.append(("published: ", headingAttr))
       outputEntry.append(("%s %s" % (pubTime, pubDate) + "\n", infoAttr))
@@ -504,8 +512,11 @@ def prompt():
   # - if the terminal's width is smaller than the non-rendered prompt length
   #   then the cursor and some movement will be displaced
   
-  prompt = format(">>> ", Color.GREEN, Attr.BOLD)
-  prompt += "\x1b[0m" * 10
+  if COLOR_PROMPT:
+    prompt = format(">>> ", Color.GREEN, Attr.BOLD)
+    prompt += "\x1b[0m" * 10
+  else:
+    prompt = ">>> "
   
   input = ""
   





More information about the tor-commits mailing list