aboutsummaryrefslogtreecommitdiffstats
path: root/src/python
diff options
context:
space:
mode:
Diffstat (limited to 'src/python')
-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"] = {