mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +01:00
Added expectWithDefault.
This commit is contained in:
parent
db5c58b98b
commit
c81c452306
@ -37,14 +37,26 @@ def expect(prompt, possibilities, recursed=False):
|
||||
prompt = '%s [%s]' % (prompt, '/'.join(possibilities))
|
||||
prompt = prompt.strip() + ' '
|
||||
s = raw_input(prompt)
|
||||
s = s.strip()
|
||||
if possibilities:
|
||||
if s in possibilities:
|
||||
return s.strip()
|
||||
return s
|
||||
else:
|
||||
return expect(originalPrompt, possibilities, recursed=True)
|
||||
else:
|
||||
return s.strip()
|
||||
|
||||
def expectWithDefault(prompt, possibilities, default):
|
||||
prompt = prompt.strip() + ' '
|
||||
prompt = '%s [%s] (default: %s) ' % \
|
||||
(prompt.strip(), '/'.join(possibilities), default)
|
||||
s = raw_input(prompt)
|
||||
s = s.strip()
|
||||
if s in possibilities:
|
||||
return s
|
||||
else:
|
||||
return default
|
||||
|
||||
def anything(prompt):
|
||||
return expect(prompt, [])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user