diff options
author | erkin <me@erkin.party> | 2023-11-14 20:10:05 +0300 |
---|---|---|
committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2023-11-15 10:00:54 +0000 |
commit | 910cffb196ab82c16fae52709d9717319f131e51 (patch) | |
tree | fe599c81909698154225cadbb5a3080432c752c9 /python/vyos/utils/io.py | |
parent | fa92cbea9ab4802554da8b02814626b6510260d2 (diff) | |
download | vyos-1x-910cffb196ab82c16fae52709d9717319f131e51.tar.gz vyos-1x-910cffb196ab82c16fae52709d9717319f131e51.zip |
remote: T5726: Disable the progressbar if the shell is noninteractive or the terminal is missing capabilities
(cherry picked from commit 59b432b97e361f3f5670302f51881ee596afe2f8)
Diffstat (limited to 'python/vyos/utils/io.py')
-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'] |