aboutsummaryrefslogtreecommitdiff
path: root/src/python/console.py
diff options
context:
space:
mode:
authorGravatar Sadie Powell2026-04-28 15:57:33 +0100
committerGravatar Sadie Powell2026-04-28 15:57:33 +0100
commit08d00dd92116c98a5b70afb9cc6e10b1785a0bf3 (patch)
treed81b4518deec2f95d9209c678dc17ec8774750b1 /src/python/console.py
parentFix 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.py23
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"] = {