From 1276c2d3ebf311a9f48494ae369bc9848b6e0a3a Mon Sep 17 00:00:00 2001 From: Bryan Gardiner Date: Sun, 28 May 2023 10:09:14 -0700 Subject: [PATCH] Respect the NO_COLOR environment variable to disable colour. --- CHANGELOG.md | 4 ++++ src/nvd | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b2b18..bba5bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.2.4 (unreleased) +- Respect the `NO_COLOR` environment variable and disable colour when it is set + and nonempty (when the default `--color=auto` is used). For more info see: + https://no-color.org + ## 0.2.3 (2023-05-22) - Fix compatibility with nix-2.3 where `nix --extra-experimental-features` isn't diff --git a/src/nvd b/src/nvd index 916a96e..9a07fd2 100755 --- a/src/nvd +++ b/src/nvd @@ -764,7 +764,9 @@ def main(): args = parse_args() action = args.action NIX_BIN_DIR = args.nix_bin_dir or None - USE_COLOUR = args.color == "always" or (args.color == "auto" and sys.stdout.isatty()) + USE_COLOUR = \ + args.color == "always" \ + or (args.color == "auto" and sys.stdout.isatty() and not os.getenv('NO_COLOR')) del args.action del args.nix_bin_dir del args.color