From 0ef0e1588b6088bac57843ecdc7167cd8322bdc9 Mon Sep 17 00:00:00 2001 From: AndyMik90 Date: Thu, 18 Dec 2025 10:18:34 +0100 Subject: [PATCH] fix for fixing windows/linux python handling --- auto-claude/runners/spec_runner.py | 5 +- auto-claude/ui/menu.py | 79 +++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 26 deletions(-) diff --git a/auto-claude/runners/spec_runner.py b/auto-claude/runners/spec_runner.py index 436c1573..928b7354 100644 --- a/auto-claude/runners/spec_runner.py +++ b/auto-claude/runners/spec_runner.py @@ -230,9 +230,8 @@ Examples: print( f" {muted('Or re-run spec_runner with --auto-approve to skip review:')}" ) - print( - f" {highlight('python auto-claude/spec_runner.py --task "..." --auto-approve')}" - ) + example_cmd = 'python auto-claude/spec_runner.py --task "..." --auto-approve' + print(f" {highlight(example_cmd)}") sys.exit(1) print() diff --git a/auto-claude/ui/menu.py b/auto-claude/ui/menu.py index c5f8e55d..e3fdb439 100644 --- a/auto-claude/ui/menu.py +++ b/auto-claude/ui/menu.py @@ -6,10 +6,22 @@ Interactive selection menus with keyboard navigation. """ import sys -import termios -import tty from dataclasses import dataclass +# Platform-specific imports for raw character input +try: + import termios + import tty + _HAS_TERMIOS = True +except ImportError: + _HAS_TERMIOS = False + +try: + import msvcrt + _HAS_MSVCRT = True +except ImportError: + _HAS_MSVCRT = False + from .boxes import box, divider from .capabilities import INTERACTIVE from .colors import bold, highlight, muted @@ -29,27 +41,48 @@ class MenuOption: def _getch() -> str: """Read a single character from stdin without echo.""" - fd = sys.stdin.fileno() - old_settings = termios.tcgetattr(fd) - try: - tty.setraw(sys.stdin.fileno()) - ch = sys.stdin.read(1) - # Handle escape sequences (arrow keys) - if ch == "\x1b": - ch2 = sys.stdin.read(1) - if ch2 == "[": - ch3 = sys.stdin.read(1) - if ch3 == "A": - return "UP" - elif ch3 == "B": - return "DOWN" - elif ch3 == "C": - return "RIGHT" - elif ch3 == "D": - return "LEFT" - return ch - finally: - termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + if _HAS_MSVCRT: + # Windows implementation + ch = msvcrt.getch() + # Handle special keys (arrow keys return two bytes) + if ch in (b'\x00', b'\xe0'): + ch2 = msvcrt.getch() + if ch2 == b'H': + return "UP" + elif ch2 == b'P': + return "DOWN" + elif ch2 == b'M': + return "RIGHT" + elif ch2 == b'K': + return "LEFT" + return "" + return ch.decode('utf-8', errors='replace') + elif _HAS_TERMIOS: + # Unix implementation + fd = sys.stdin.fileno() + old_settings = termios.tcgetattr(fd) + try: + tty.setraw(sys.stdin.fileno()) + ch = sys.stdin.read(1) + # Handle escape sequences (arrow keys) + if ch == "\x1b": + ch2 = sys.stdin.read(1) + if ch2 == "[": + ch3 = sys.stdin.read(1) + if ch3 == "A": + return "UP" + elif ch3 == "B": + return "DOWN" + elif ch3 == "C": + return "RIGHT" + elif ch3 == "D": + return "LEFT" + return ch + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) + else: + # No raw input available, raise to trigger fallback + raise RuntimeError("No raw input method available") def select_menu(