diff options
author | Christian Breunig <christian@breunig.cc> | 2023-11-15 07:35:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 07:35:15 +0100 |
commit | 1afaa42ee7c849ec7080ab6ff6d092bede343d26 (patch) | |
tree | 6d7dbfcfe334a7629535e094b1c5fe14dbe0e4a3 /python/vyos/utils | |
parent | aa4abbc733820c5d2398bf6357bdd1549db80d1d (diff) | |
parent | 59b432b97e361f3f5670302f51881ee596afe2f8 (diff) | |
download | vyos-1x-1afaa42ee7c849ec7080ab6ff6d092bede343d26.tar.gz vyos-1x-1afaa42ee7c849ec7080ab6ff6d092bede343d26.zip |
Merge pull request #2483 from erkin/noninteractive
remote: T5726: Disable the progressbar if the shell is noninteractive or the terminal is missing capabilities
Diffstat (limited to 'python/vyos/utils')
-rw-r--r-- | python/vyos/utils/io.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/python/vyos/utils/io.py b/python/vyos/utils/io.py index 5fffa62f8..8790cbaac 100644 --- a/python/vyos/utils/io.py +++ b/python/vyos/utils/io.py @@ -62,3 +62,13 @@ def ask_yes_no(question, default=False) -> bool: stdout.write("Please respond with yes/y or no/n\n") except EOFError: stdout.write("\nPlease respond with yes/y or no/n\n") + +def is_interactive(): + """Try to determine if the routine was called from an interactive shell.""" + import os, sys + return os.getenv('TERM', default=False) and sys.stderr.isatty() and sys.stdout.isatty() + +def is_dumb_terminal(): + """Check if the current TTY is dumb, so that we can disable advanced terminal features.""" + import os + return os.getenv('TERM') in ['vt100', 'dumb'] |