Added Y/N prompt
This commit is contained in:
22
utils.py
Normal file
22
utils.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"""
|
||||||
|
A set of common utilities.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def inputYN(text: str, default: bool=None):
|
||||||
|
"""
|
||||||
|
Prompty the user with a yes/no prompt.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
text (str): The text displayed to the user.
|
||||||
|
default (bool): The default answer.
|
||||||
|
"""
|
||||||
|
|
||||||
|
while True:
|
||||||
|
i = input(text)
|
||||||
|
|
||||||
|
if i.lower() in ['1', 'y', 'yes']:
|
||||||
|
return True
|
||||||
|
if i.lower() in ['0', 'n', 'no']:
|
||||||
|
return False
|
||||||
|
if default is not None and i == '':
|
||||||
|
return default
|
||||||
Reference in New Issue
Block a user