diff options
| author | 2026-04-28 15:57:33 +0100 | |
|---|---|---|
| committer | 2026-04-28 15:57:33 +0100 | |
| commit | 08d00dd92116c98a5b70afb9cc6e10b1785a0bf3 (patch) | |
| tree | d81b4518deec2f95d9209c678dc17ec8774750b1 /src/python/console.py | |
| parent | Fix invalidation of the CMake module glob after enabling modules. (diff) | |
Add an interactive mode to `./modulemanager extra`.
Diffstat (limited to 'src/python/console.py')
| -rw-r--r-- | src/python/console.py | 23 |
1 files changed, 23 insertions, 0 deletions
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"] = { |
