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