projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Let text_utils work with strings that contain ansi escape sequences.
[python_utils.git]
/
input_utils.py
diff --git
a/input_utils.py
b/input_utils.py
index a989b2d6fe3db428d25a2de5b8baf6baef3c8734..7d5e18089331a96bc32172b90e916a37c0695d49 100644
(file)
--- a/
input_utils.py
+++ b/
input_utils.py
@@
-2,6
+2,7
@@
"""Utilities related to user input."""
"""Utilities related to user input."""
+import logging
import signal
import sys
from typing import List
import signal
import sys
from typing import List
@@
-10,6
+11,8
@@
import readchar # type: ignore
import exceptions
import exceptions
+logger = logging.getLogger(__file__)
+
def single_keystroke_response(
valid_responses: List[str],
def single_keystroke_response(
valid_responses: List[str],
@@
-34,6
+37,7
@@
def single_keystroke_response(
try:
while True:
response = readchar.readchar()
try:
while True:
response = readchar.readchar()
+ logger.debug('Keystroke: 0x%x', ord(response))
if response in valid_responses:
break
if ord(response) in os_special_keystrokes:
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:
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
except exceptions.TimeoutError:
if default_response is not None:
response = default_response