From 609bc62a3aa0ffb71e9f649359fcfdf1b98dad96 Mon Sep 17 00:00:00 2001 From: Jan Niklas Hasse Date: Wed, 7 Jun 2023 17:24:23 +0200 Subject: [PATCH] Use NO_COLOR for disabling instead of CLICOLOR=0 Fix #7, #8. --- index.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/index.md b/index.md index b5cc29f..4bc7423 100644 --- a/index.md +++ b/index.md @@ -18,13 +18,13 @@ The idea is to have the environment variables `CLICOLOR` and `CLICOLOR_FORCE` (w already used for this exact reason on some UNIX systems). When set, the following rules should apply: - * `CLICOLOR != 0` + * `NO_COLOR` set + * Don't output ANSI color escape codes, see [no-color.org](https://no-color.org) + * `CLICOLOR_FORCE` set, but `NO_COLOR` unset + * ANSI colors should be enabled no matter what. + * none of the above environment variables are set * ANSI colors are supported and should be used when the program isn't piped. - * `CLICOLOR == 0` - * Don't output ANSI color escape codes. - * `CLICOLOR_FORCE != 0` - * ANSI colors should be enabled no matter what. If you have ideas or comments please [create a new issue on GitHub](https://github.com/jhasse/clicolors/issues/new) @@ -39,11 +39,11 @@ like this Python code example: import os, sys def has_colors(): - if ((os.getenv("CLICOLOR", "1") != "0" and sys.stdout.isatty()) or - os.getenv("CLICOLOR_FORCE", "0") != "0"): - return True - else: + if "NO_COLOR" in os.environ: return False + if "CLICOLOR_FORCE" in os.environ: + return True + return sys.stdout.isatty() {% endhighlight %} ## Supported Colors