linux/reicast-joyconfig: Flush stdin via termios if possible

This might be necessary to get rid of input characters from mapping
keyboard buttons.
This commit is contained in:
Jan Holthuis 2016-09-12 14:08:39 +02:00
parent dc025c7502
commit 8fd33291cf
1 changed files with 9 additions and 0 deletions

View File

@ -22,6 +22,11 @@ except ImportError:
print(" pip install evdev")
sys.exit(1)
try:
import termios
except ImportError:
termios = None
DEV_ID_PATTERN = re.compile('(\d+)')
DREAMCAST_BUTTONS = ['A', 'B', 'C', 'D', 'X', 'Y', 'Z', 'START']
DREAMCAST_DPAD = [('X', 'LEFT', 'RIGHT'), ('Y', 'UP', 'DOWN')]
@ -212,6 +217,10 @@ def setup_device(dev_id):
def ask_yes_no(question, default=True):
# Flush stdin (if possible)
if termios is not None:
termios.tcflush(sys.stdin, termios.TCIFLUSH)
valid = {"yes": True, "y": True, "ye": True,
"no": False, "n": False}
prompt = "Y/n" if default else "y/N"