X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=input_utils.py;fp=input_utils.py;h=e0b457d5a0e73ffc43d3d83ff09228328e6a641e;hb=b29be4f1750fd20bd2eada88e751dfae85817882;hp=a989b2d6fe3db428d25a2de5b8baf6baef3c8734;hpb=ed8fa2b10b0177b15b7423263bdd390efde2f0c8;p=python_utils.git diff --git a/input_utils.py b/input_utils.py index a989b2d..e0b457d 100644 --- a/input_utils.py +++ b/input_utils.py @@ -2,6 +2,7 @@ """Utilities related to user input.""" +import logging import signal import sys from typing import List @@ -11,6 +12,9 @@ import readchar # type: ignore import exceptions +logger = logging.getLogger(__file__) + + def single_keystroke_response( valid_responses: List[str], *, @@ -34,6 +38,7 @@ def single_keystroke_response( try: while True: response = readchar.readchar() + logger.debug(f'Keystroke: {ord(response)}') if response in valid_responses: break if ord(response) in os_special_keystrokes: @@ -50,6 +55,9 @@ def single_keystroke_response( response = _single_keystroke_response_internal( valid_responses, timeout_seconds ) + if ord(response) == 3: + raise KeyboardInterrupt('User pressed ^C in input_utils.') + except exceptions.TimeoutError: if default_response is not None: response = default_response