Merge PR #274: fix(setup): handle TerminalMenu init failures with safe fallback

Authored by jdblackstar. Catches runtime exceptions from TerminalMenu
init (e.g. CalledProcessError from tput with unknown TERM like
xterm-ghostty over SSH) and falls through to the text-based menu.
This commit is contained in:
teknium1 2026-03-05 01:26:58 -08:00
commit fe15a2c65c

View file

@ -106,28 +106,32 @@ def prompt_choice(question: str, choices: list, default: int = 0) -> int:
return idx return idx
except (ImportError, NotImplementedError): except (ImportError, NotImplementedError):
# Fallback to number-based selection (simple_term_menu doesn't support Windows) pass
for i, choice in enumerate(choices): except Exception as e:
marker = "" if i == default else "" print(f" (Interactive menu unavailable: {e})")
if i == default:
print(color(f" {marker} {choice}", Colors.GREEN))
else:
print(f" {marker} {choice}")
while True: # Fallback to number-based selection (simple_term_menu doesn't support Windows)
try: for i, choice in enumerate(choices):
value = input(color(f" Select [1-{len(choices)}] ({default + 1}): ", Colors.DIM)) marker = "" if i == default else ""
if not value: if i == default:
return default print(color(f" {marker} {choice}", Colors.GREEN))
idx = int(value) - 1 else:
if 0 <= idx < len(choices): print(f" {marker} {choice}")
return idx
print_error(f"Please enter a number between 1 and {len(choices)}") while True:
except ValueError: try:
print_error("Please enter a number") value = input(color(f" Select [1-{len(choices)}] ({default + 1}): ", Colors.DIM))
except (KeyboardInterrupt, EOFError): if not value:
print() return default
sys.exit(1) idx = int(value) - 1
if 0 <= idx < len(choices):
return idx
print_error(f"Please enter a number between 1 and {len(choices)}")
except ValueError:
print_error("Please enter a number")
except (KeyboardInterrupt, EOFError):
print()
sys.exit(1)
def prompt_yes_no(question: str, default: bool = True) -> bool: def prompt_yes_no(question: str, default: bool = True) -> bool:
"""Prompt for yes/no.""" """Prompt for yes/no."""