[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z-QKXdq2gFltMvnX@decadent.org.uk>
Date: Wed, 26 Mar 2025 15:08:29 +0100
From: Ben Hutchings <benh@...ian.org>
To: netdev@...r.kernel.org
Cc: 1088739@...s.debian.org
Subject: [PATCH iproute2 1/2] color: Assume background is dark if unknown
We rely on the COLORFGBG environment variable to tell us whether the
background is dark. This variable is set by Konsole and rxvt but not
by GNOME Terminal or xterm. This means we use the wrong set of
colours when GNOME Terminal or xterm is configured with a dark
background.
It appears to me that the dark-background colour palette works better
on a light background than vice versa. So it is better to assume a
dark background if we cannot find this out from $COLORFGBG.
- Change the initial value of is_dark_bg to 1.
- In set_color_palette(). conditinally set is_dark_bg to 0 with an
inverted test of the colour.
Signed-off-by: Ben Hutchings <benh@...ian.org>
---
lib/color.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/color.c b/lib/color.c
index 3c6db08d..88ba9b03 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -72,7 +72,11 @@ static enum color attr_colors_dark[] = {
C_CLEAR
};
-static int is_dark_bg;
+/*
+ * Assume dark background until we know otherwise. The dark-background
+ * colours work better on a light background than vice versa.
+ */
+static int is_dark_bg = 1;
static int color_is_enabled;
static void enable_color(void)
@@ -138,12 +142,12 @@ 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 this value is 0-6 or 8, background is dark; otherwise it's 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] >= '0' && p[1] <= '6') || p[1] == '8')
+ && p[2] == '\0'))
+ is_dark_bg = 0;
}
__attribute__((format(printf, 3, 4)))
Download attachment "signature.asc" of type "application/pgp-signature" (834 bytes)
Powered by blists - more mailing lists