|
17 | 17 | SCENARIOS_DIR = Path(__file__).parent / "scenarios" |
18 | 18 |
|
19 | 19 |
|
| 20 | +def _prompt_yes_no(prompt): |
| 21 | + """Prompt user and wait for a single key: Enter=yes, Escape=no. |
| 22 | +
|
| 23 | + Returns True for yes, False for no. |
| 24 | + """ |
| 25 | + import sys |
| 26 | + print(f" [MANUAL] {prompt} [Entree=oui / Echap=non] ", end="", flush=True) |
| 27 | + try: |
| 28 | + import tty |
| 29 | + import termios |
| 30 | + fd = sys.stdin.fileno() |
| 31 | + old = termios.tcgetattr(fd) |
| 32 | + try: |
| 33 | + tty.setraw(fd) |
| 34 | + ch = sys.stdin.read(1) |
| 35 | + finally: |
| 36 | + termios.tcsetattr(fd, termios.TCSADRAIN, old) |
| 37 | + print() # newline after keypress |
| 38 | + return ch in ("\r", "\n") |
| 39 | + except (ImportError, OSError): |
| 40 | + # Fallback for non-Unix or piped stdin |
| 41 | + response = input("") |
| 42 | + return response.strip().lower() != "n" |
| 43 | + |
| 44 | + |
20 | 45 | def _print_result(result, test): |
21 | 46 | """Print the measured value for report capture.""" |
22 | 47 | if isinstance(result, float): |
@@ -108,8 +133,7 @@ def test_scenario(scenario, test, mode, port): |
108 | 133 | else: |
109 | 134 | print(f" {label}: {value} {unit}") |
110 | 135 | prompt = test.get("prompt", "Manual check") |
111 | | - response = input(f" [MANUAL] {prompt} [y/n] ") |
112 | | - result = response.strip().lower() == "y" |
| 136 | + result = _prompt_yes_no(prompt) |
113 | 137 | elif action == "call": |
114 | 138 | result = bridge.call_method( |
115 | 139 | scenario["driver"], |
|
0 commit comments