[or-cvs] r23821: {arm} Using input mode for textpads and having them terminate (wit (arm/trunk/src/util)

Damian Johnson atagar1 at gmail.com
Thu Nov 18 07:25:42 UTC 2010


Author: atagar
Date: 2010-11-18 07:25:42 +0000 (Thu, 18 Nov 2010)
New Revision: 23821

Modified:
   arm/trunk/src/util/panel.py
Log:
Using input mode for textpads and having them terminate (with no effect) when the user presses escape.



Modified: arm/trunk/src/util/panel.py
===================================================================
--- arm/trunk/src/util/panel.py	2010-11-18 06:50:37 UTC (rev 23820)
+++ arm/trunk/src/util/panel.py	2010-11-18 07:25:42 UTC (rev 23821)
@@ -351,15 +351,20 @@
     # prepopulates the initial text
     if initialText: inputSubwindow.addstr(0, 0, initialText)
     
-    # displays the text field, blocking until the user's done
-    textbox = curses.textpad.Textbox(inputSubwindow)
-    userInput = textbox.edit().strip()
+    # Displays the text field, blocking until the user's done. This closes the
+    # text panel and returns userInput to the initial text if the user presses
+    # escape (the curses.ascii.BEL is one of the character codes that can cause
+    # the textpad to terminate).
+    textbox = curses.textpad.Textbox(inputSubwindow, True)
+    userInput = textbox.edit(lambda key: curses.ascii.BEL if key == 27 else key)
     
+    if textbox.lastcmd == curses.ascii.BEL: userInput = initialText
+    
     # reverts visability settings
     try: curses.curs_set(previousCursorState)
     except curses.error: pass
     
-    return userInput
+    return userInput.strip()
   
   def addScrollBar(self, top, bottom, size, drawTop = 0, drawBottom = -1):
     """



More information about the tor-commits mailing list