[tor-commits] [arm/release] Format option for getstr method
atagar at torproject.org
atagar at torproject.org
Sun Jul 17 06:08:27 UTC 2011
commit 9ffda70c2203630b41a9f799e754f7f55e70e9b9
Author: Damian Johnson <atagar at torproject.org>
Date: Thu Jun 23 08:51:20 2011 -0700
Format option for getstr method
Allowing string input fetching to have text attributes.
---
src/util/panel.py | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/util/panel.py b/src/util/panel.py
index 3f0a98a..5cbeaee 100644
--- a/src/util/panel.py
+++ b/src/util/panel.py
@@ -573,7 +573,7 @@ class Panel():
baseMsg = "Unclosed formatting tag%s:" % ("s" if len(expectedCloseTags) > 1 else "")
raise ValueError("%s: '%s'\n \"%s\"" % (baseMsg, "', '".join(expectedCloseTags), msg))
- def getstr(self, y, x, initialText = ""):
+ def getstr(self, y, x, initialText = "", format = None):
"""
Provides a text field where the user can input a string, blocking until
they've done so and returning the result. If the user presses escape then
@@ -584,8 +584,11 @@ class Panel():
y - vertical location
x - horizontal location
initialText - starting text in this field
+ format - format used for the text
"""
+ if not format: format = curses.A_NORMAL
+
# makes cursor visible
try: previousCursorState = curses.curs_set(1)
except curses.error: previousCursorState = 0
@@ -595,7 +598,8 @@ class Panel():
inputSubwindow = self.parent.subwin(1, displayWidth - x, self.top + y, self.left + x)
# prepopulates the initial text
- if initialText: inputSubwindow.addstr(0, 0, initialText[:displayWidth - x - 1])
+ if initialText:
+ inputSubwindow.addstr(0, 0, initialText[:displayWidth - x - 1], format)
# 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
@@ -609,7 +613,9 @@ class Panel():
else:
textbox = curses.textpad.Textbox(inputSubwindow)
+ textbox.win.attron(format)
userInput = textbox.edit(lambda key: _textboxValidate(textbox, key)).strip()
+ textbox.win.attroff(format)
if textbox.lastcmd == curses.ascii.BEL: userInput = None
# reverts visability settings
More information about the tor-commits
mailing list