Update of /cvsroot/cvsshell/cvsshell/src
In directory usw-pr-cvs1:/tmp/cvs-serv26979/src
Modified Files:
interactive_app.py
Log Message:
added support for default value in prompt
Index: interactive_app.py
===================================================================
RCS file: /cvsroot/cvsshell/cvsshell/src/interactive_app.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** interactive_app.py 11 Mar 2002 10:09:50 -0000 1.6
--- interactive_app.py 28 Mar 2002 23:07:37 -0000 1.7
***************
*** 20,24 ****
###############################################################################
! import os
from app import App, AppError
--- 20,24 ----
###############################################################################
! import os, types
from app import App, AppError
***************
*** 28,31 ****
--- 28,32 ----
App.__init__(self)
self.BREAK_REPL = 'BREAK_REPL'
+ self.DEF_PATTERN = '%%def%%'
try:
import readline
***************
*** 60,71 ****
def readCommand(self): # subclass hooks + App.start,stop
! return self.prompt(self.getPrompt())
def getPrompt(self):
return '? '
! def prompt(self, msg):
"""Displayes msg and prompts the user for input.
! If input is EOF, None is returned."""
try:
a = raw_input(msg)
--- 61,86 ----
def readCommand(self): # subclass hooks + App.start,stop
! p = self.getPrompt()
! if type(p) == types.TupleType:
! return self.prompt(p[0], p[1])
! else:
! return self.prompt(p)
def getPrompt(self):
return '? '
! def prompt(self, msg, default=None):
"""Displayes msg and prompts the user for input.
! If input is EOF, None is returned.
! If input is the emtpy string and default is given, default is returned.
! If a default value is given and msg contains self.DEF_PATTERN,
! this part of msg is replaced by the default value surrounded with [].
! Otherwise the default value is append at the end of msg."""
! if default is not None:
! i = msg.find(self.DEF_PATTERN)
! if i >= 0:
! msg = msg[:i] + '[' + default + ']'+ msg[i+len(self.DEF_PATTERN):]
! else:
! msg += '[%s] ' % default
try:
a = raw_input(msg)
***************
*** 78,82 ****
a = os.path.expandvars(a)
a = os.path.expanduser(a)
! return a.strip()
def evalCommand(self, command):
--- 93,99 ----
a = os.path.expandvars(a)
a = os.path.expanduser(a)
! a = a.strip()
! if a == '' and default is not None: return default
! else: return a
def evalCommand(self, command):
|