From 59b432b97e361f3f5670302f51881ee596afe2f8 Mon Sep 17 00:00:00 2001 From: erkin Date: Tue, 14 Nov 2023 20:10:05 +0300 Subject: remote: T5726: Disable the progressbar if the shell is noninteractive or the terminal is missing capabilities --- python/vyos/utils/io.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'python/vyos/utils/io.py') 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'] -- cgit v1.2.3