[Nym3-commit] r176 - trunk/nym3/Client

jr at conuropsis.org jr at conuropsis.org
Wed Apr 6 08:25:14 CEST 2005


Author: jr
Date: 2005-04-06 08:25:13 +0200 (Wed, 06 Apr 2005)
New Revision: 176

Modified:
   trunk/nym3/Client/Main.py
Log:
add prompthidden and promptmultiline


Modified: trunk/nym3/Client/Main.py
===================================================================
--- trunk/nym3/Client/Main.py	2005-04-06 05:16:00 UTC (rev 175)
+++ trunk/nym3/Client/Main.py	2005-04-06 06:25:13 UTC (rev 176)
@@ -28,6 +28,7 @@
 import sys
 import os
 import string
+import termios
 from optparse import OptionParser, make_option
 from nym3.Message import SToCCODE
 import nym3.Client.Account as Account
@@ -40,12 +41,38 @@
 
 class CLI:
     def __init__(self):
-	self.prompthidden = self.prompt # TODO
+	pass
 
     def prompt(self, s):
-	sys.stdout.write(s + ": ")
-	sys.stdout.flush()
-	return sys.stdin.readline()
+	try:
+	    return raw_input(s + ": ")
+	except EOFError:
+	    return ""
+	
+    def promptmultiline(self, s):
+	res = []
+	while True:
+	    if len(res) == 0:
+		nym = self.prompt(s)
+	    else:
+		nym = raw_input()
+	    if nym == "":
+		break
+	    else:
+		res.append(nym)
+	return res
+	    
+    def prompthidden(self, s):
+	fd = sys.stdin.fileno()
+	old = termios.tcgetattr(fd)
+	new = termios.tcgetattr(fd)
+	new[3] = new[3] & ~termios.ECHO          # lflags
+	try:
+	    termios.tcsetattr(fd, termios.TCSADRAIN, new)
+	    passwd = prompt(s)
+	finally:
+	    termios.tcsetattr(fd, termios.TCSADRAIN, old)
+	return passwd
 
     def display(self, s):
 	print s
@@ -87,7 +114,7 @@
 			       " this account")
     if not usernamelist:
 	ui.display("You need a username for this account.")
-	usernamelist = ui.prompt("Enter several choices, one per line,"
+	usernamelist = ui.promptmultiline("Enter several choices, one per line,"
 				 " finish by a blank line")
     if not emailAddress:
 	emailAddress = ui.prompt("What is the default email address for "



More information about the Nym3-commit mailing list