From: Ben Hutchings <benh@debian.org>
To: netdev@vger.kernel.org
Cc: 1088739@bugs.debian.org
Subject: [PATCH iproute2 1/2] color: Assume background is dark if unknown
Date: Wed, 26 Mar 2025 15:08:29 +0100 [thread overview]
Message-ID: <Z-QKXdq2gFltMvnX@decadent.org.uk> (raw)
In-Reply-To: <Z-QKNa7_nHKoh9Gl@decadent.org.uk>
[-- Attachment #1: Type: text/plain, Size: 1875 bytes --]
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@debian.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)))
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2025-03-26 14:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 14:07 [PATCH iproute2 0/2] Improve coloured text readability Ben Hutchings
2025-03-26 14:08 ` Ben Hutchings [this message]
2025-03-26 14:08 ` [PATCH iproute2 2/2] color: Do not use dark blue in dark-background palette Ben Hutchings
2025-04-06 17:00 ` [PATCH iproute2 0/2] Improve coloured text readability patchwork-bot+netdevbpf
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=Z-QKXdq2gFltMvnX@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 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.