All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gedalya Nie <gedalya@gedalya.net>
To: netdev@vger.kernel.org
Subject: [PATCH v3] iproute2: color: default to dark background
Date: Thu, 23 May 2024 02:43:57 +0800	[thread overview]
Message-ID: <E1s9tE4-00000006L4I-46tH@ws2.gedalya.net> (raw)

Since the COLORFGBG environment variable isn't always there, and
anyway it seems that terminals and consoles more commonly default
to dark backgrounds, make that assumption here.

Currently the iproute2 tools produce output that is hard to read
when color is enabled and the background is dark.

Signed-off-by: Gedalya Nie <gedalya@gedalya.net>
---
 lib/color.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/color.c b/lib/color.c
index cd0f9f75..6692f9c1 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -72,7 +72,7 @@ static enum color attr_colors_dark[] = {
 	C_CLEAR
 };
 
-static int is_dark_bg;
+static int is_dark_bg = 1;
 static int color_is_enabled;
 
 static void enable_color(void)
@@ -127,11 +127,11 @@ static void set_color_palette(void)
 	 * COLORFGBG environment variable usually contains either two or three
 	 * values separated by semicolons; we want the last value in either case.
 	 * If this value is 0-6 or 8, background is dark.
+	 * If it is 7, 9 or greater, background is light.
 	 */
 	if (p && (p = strrchr(p, ';')) != NULL
-		&& ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
-		&& p[2] == '\0')
-		is_dark_bg = 1;
+		&& (p[1] == '7' || p[1] == '9' || p[2] != '\0'))
+		is_dark_bg = 0;
 }
 
 __attribute__((format(printf, 3, 4)))
-- 
2.43.0


             reply	other threads:[~2024-05-22 21:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22 18:43 Gedalya Nie [this message]
2024-05-29 16:23 ` [PATCH v3] iproute2: color: default to dark background David Ahern
2024-05-29 16:36   ` Gedalya
2024-05-29 17:51     ` Edward Cree
2024-05-29 18:11       ` Stephen Hemminger
2024-05-30 22:58     ` Dragan Simic
2024-05-29 18:12   ` Stephen Hemminger

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=E1s9tE4-00000006L4I-46tH@ws2.gedalya.net \
    --to=gedalya@gedalya.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.