netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <benh@debian.org>
To: netdev@vger.kernel.org
Cc: 1088739@bugs.debian.org
Subject: [PATCH iproute2 2/2] color: Handle NO_COLOR environment variable in default_color_opt()
Date: Wed, 19 Mar 2025 22:51:57 +0100	[thread overview]
Message-ID: <Z9s8fb6-0Oysrc5j@decadent.org.uk> (raw)
In-Reply-To: <Z9s8RSix3wtE8QPf@decadent.org.uk>

[-- Attachment #1: Type: text/plain, Size: 905 bytes --]

The NO_COLOR environment variable is a widely supported way for users
to disable coloured text output.  See <https://no-color.org/>.  In
case iproute2 is configured to use colours by default, allow this to
be overridden by setting NO_COLOR.

This is done in default_color_opt() so that colours can still be
explicitly enabled with a command-line option.

Signed-off-by: Ben Hutchings <benh@debian.org>
---
 lib/color.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/color.c b/lib/color.c
index 5c4cc329..3c6db08d 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -83,6 +83,13 @@ static void enable_color(void)
 
 int default_color_opt(void)
 {
+	const char *no_color;
+
+	/* If NO_COLOR has a non-empty value, coloured output is never wanted */
+	no_color = getenv("NO_COLOR");
+	if (no_color && *no_color)
+		return COLOR_OPT_NEVER;
+
 	return CONF_COLOR;
 }
 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2025-03-19 21:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-19 21:51 [PATCH iproute2 1/2] color: Introduce and use default_color_opt() function Ben Hutchings
2025-03-19 21:51 ` Ben Hutchings [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z9s8fb6-0Oysrc5j@decadent.org.uk \
    --to=benh@debian.org \
    --cc=1088739@bugs.debian.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).