From b92012dae65e3ffdcc86f95a9e7b054602d265ef Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Wed, 6 Dec 2023 17:54:46 -0500 Subject: [PATCH] added --color flag to force color even if stdout is a tty --- toot/console.py | 5 +++++ toot/output.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/toot/console.py b/toot/console.py index 41583c12..e9ddc3cb 100644 --- a/toot/console.py +++ b/toot/console.py @@ -164,6 +164,11 @@ def editor(value): "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', diff --git a/toot/output.py b/toot/output.py index d526539f..a81630f8 100644 --- a/toot/output.py +++ b/toot/output.py @@ -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