added --color flag to force color even if stdout is a tty

This commit is contained in:
Daniel Schwarz 2023-12-06 17:54:46 -05:00
parent 1c5abb8419
commit b92012dae6
2 changed files with 10 additions and 0 deletions

View File

@ -164,6 +164,11 @@ common_args = [
"action": 'store_true',
"default": False,
}),
(["--color"], {
"help": "always use ANSI colors in output",
"action": 'store_true',
"default": False,
}),
(["--quiet"], {
"help": "don't write to stdout on success",
"action": 'store_true',

View File

@ -110,6 +110,11 @@ def use_ansi_color():
if sys.platform == 'win32' and 'ANSICON' not in os.environ:
return False
# With the --color flag, force color, even if stdout is a tty
# and even if --no-color is also specified (!)
if "--color" in sys.argv:
return True
# Don't show color if stdout is not a tty, e.g. if output is piped on
if not sys.stdout.isatty():
return False