X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=input_utils.py;h=a166d7a4169e56937e8bb63c4398aff1abc52564;hb=31c81f6539969a5eba864d3305f9fb7bf716a367;hp=a989b2d6fe3db428d25a2de5b8baf6baef3c8734;hpb=351e77c767c9084aa486eedbdc9902c635b06261;p=python_utils.git diff --git a/input_utils.py b/input_utils.py index a989b2d..a166d7a 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 @@ -10,6 +11,8 @@ import readchar # type: ignore import exceptions +logger = logging.getLogger(__file__) + def single_keystroke_response( valid_responses: List[str], @@ -34,6 +37,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: @@ -47,9 +51,10 @@ def single_keystroke_response( print(prompt, end="") sys.stdout.flush() try: - response = _single_keystroke_response_internal( - valid_responses, timeout_seconds - ) + 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