mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Fixed the formatting problem in expect.
This commit is contained in:
parent
08244ff36e
commit
66061f6a34
@ -33,13 +33,16 @@
|
||||
|
||||
import textwrap
|
||||
|
||||
def expect(prompt, possibilities, recursed=False):
|
||||
def expect(prompt, possibilities, recursed=False, doindent=True):
|
||||
"""Prompt the user with prompt, allow them to choose from possibilities.
|
||||
|
||||
If possibilities is empty, allow anything.
|
||||
"""
|
||||
originalPrompt = prompt
|
||||
if doindent:
|
||||
indent = ' ' * ((len(originalPrompt)%68) + 2)
|
||||
else:
|
||||
indent = ''
|
||||
if recursed:
|
||||
print 'Sorry, that response was not an option.'
|
||||
if possibilities:
|
||||
@ -57,7 +60,8 @@ def expect(prompt, possibilities, recursed=False):
|
||||
if s in possibilities:
|
||||
return s
|
||||
else:
|
||||
return expect(originalPrompt, possibilities, recursed=True)
|
||||
return expect(originalPrompt, possibilities, recursed=True,
|
||||
doindent=doindent)
|
||||
else:
|
||||
return s.strip()
|
||||
|
||||
@ -91,7 +95,7 @@ def something(prompt):
|
||||
|
||||
def yn(prompt):
|
||||
"""Allow only 'y' or 'n' from the user."""
|
||||
return expect(prompt, ['y', 'n'])
|
||||
return expect(prompt, ['y', 'n'], doindent=False)
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||
|
Loading…
Reference in New Issue
Block a user