Merge branch '2.0.x-maintenance' into master-merge-commit
[ExpressLRS.git] / src / python / query_yes_no.py
blob6cad042968f72f06257a5aa1edf1f176c690b7f4
1 import sys
2 from inputimeout import inputimeout, TimeoutOccurred
4 def query_yes_no(question=''): #https://code.activestate.com/recipes/577058/
5 """Ask a yes/no question via raw_input() and return their answer.
6 "question" is a string that is presented to the user.
7 The "answer" return value is True for "yes" or False for "no".
8 """
9 valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False}
11 while True:
12 choice = ''
13 try:
14 choice = inputimeout(prompt=question, timeout=5)
15 except TimeoutOccurred:
16 sys.stdout.write("Please respond with 'yes' or 'no' " "(or 'y' or 'n')")
17 sys.stdout.flush()
19 if choice in valid:
20 return valid[choice]