From 08d00dd92116c98a5b70afb9cc6e10b1785a0bf3 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Tue, 28 Apr 2026 15:57:33 +0100 Subject: Add an interactive mode to `./modulemanager extra`. --- src/python/console.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/python/console.py') diff --git a/src/python/console.py b/src/python/console.py index cfdaf5d5f..51fbb04a3 100644 --- a/src/python/console.py +++ b/src/python/console.py @@ -54,6 +54,29 @@ def error(*messages): sys.exit(1) +# Determines if the script has been invoked in interactive mode. +def interactive(): + return os.isatty(sys.stdin.fileno()) and os.isatty(sys.stdout.fileno()) + + +# Prompts for the user to enter a boolean value. +def prompt_boolean(default): + while True: + answer = prompt_string("yes" if default else "no").lower() + if answer in ("y", "yes"): + return True + if answer in ("n", "no"): + return False + warning(f'"{answer}" is not "yes" or "no". Please try again.') + + +# Prompts for the user to enter a string value. +def prompt_string(default): + answer = input(f"[{color(default, BOLD)}] => ").strip() + print() + return answer if answer else default + + # Dispatches commands to their handler method. def subcommand(args, start, commands, default="help"): commands["help"] = { -- cgit v1.3.1-10-gc9f91