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 = '%s [%s]' % (prompt, '/'.join(possibilities))
|
||||||
prompt = prompt.strip() + ' '
|
prompt = prompt.strip() + ' '
|
||||||
s = raw_input(prompt)
|
s = raw_input(prompt)
|
||||||
|
s = s.strip()
|
||||||
if possibilities:
|
if possibilities:
|
||||||
if s in possibilities:
|
if s in possibilities:
|
||||||
return s.strip()
|
return s
|
||||||
else:
|
else:
|
||||||
return expect(originalPrompt, possibilities, recursed=True)
|
return expect(originalPrompt, possibilities, recursed=True)
|
||||||
else:
|
else:
|
||||||
return s.strip()
|
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):
|
def anything(prompt):
|
||||||
return expect(prompt, [])
|
return expect(prompt, [])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user