netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2 0/2] Improve coloured text readability
@ 2025-03-26 14:07 Ben Hutchings
  2025-03-26 14:08 ` [PATCH iproute2 1/2] color: Assume background is dark if unknown Ben Hutchings
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ben Hutchings @ 2025-03-26 14:07 UTC (permalink / raw)
  To: netdev; +Cc: 1088739

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

Currently coloured text output isn't very readable in GNOME Terminal
or xterm with a dark background:

- These terminals don't set $COLORFGBG, so we end up using the
  light-background palette.

- The standard (dark) blue is also too close to black in their default
  dark palettes.

Ben.

Ben Hutchings (2):
  color: Assume background is dark if unknown
  color: Do not use dark blue in dark-background palette

 lib/color.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH iproute2 1/2] color: Assume background is dark if unknown
  2025-03-26 14:07 [PATCH iproute2 0/2] Improve coloured text readability Ben Hutchings
@ 2025-03-26 14:08 ` Ben Hutchings
  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
  2 siblings, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2025-03-26 14:08 UTC (permalink / raw)
  To: netdev; +Cc: 1088739

[-- 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 --]

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH iproute2 2/2] color: Do not use dark blue in dark-background palette
  2025-03-26 14:07 [PATCH iproute2 0/2] Improve coloured text readability Ben Hutchings
  2025-03-26 14:08 ` [PATCH iproute2 1/2] color: Assume background is dark if unknown Ben Hutchings
@ 2025-03-26 14:08 ` Ben Hutchings
  2025-04-06 17:00 ` [PATCH iproute2 0/2] Improve coloured text readability patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Ben Hutchings @ 2025-03-26 14:08 UTC (permalink / raw)
  To: netdev; +Cc: 1088739

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

In GNOME Terminal's default dark colour schemes, the default (dark)
blue on a black background is barely readable.  Light blue is
significantly more readable to me, and is also easily readable on a
white background.

In Konsole, rxvt, and xterm, I can see little if any difference
between dark and light blue in the default dark colour schemes.

So replace dark blue with light blue in the dark-background palette.

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

diff --git a/lib/color.c b/lib/color.c
index 88ba9b03..aa112352 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -24,7 +24,7 @@ enum color {
 	C_BOLD_RED,
 	C_BOLD_GREEN,
 	C_BOLD_YELLOW,
-	C_BOLD_BLUE,
+	C_BOLD_LIGHT_BLUE,
 	C_BOLD_MAGENTA,
 	C_BOLD_CYAN,
 	C_BOLD_WHITE,
@@ -42,7 +42,7 @@ static const char * const color_codes[] = {
 	"\e[1;31m",
 	"\e[1;32m",
 	"\e[1;33m",
-	"\e[1;34m",
+	"\e[1;94m",
 	"\e[1;35m",
 	"\e[1;36m",
 	"\e[1;37m",
@@ -66,7 +66,7 @@ static enum color attr_colors_dark[] = {
 	C_BOLD_CYAN,
 	C_BOLD_YELLOW,
 	C_BOLD_MAGENTA,
-	C_BOLD_BLUE,
+	C_BOLD_LIGHT_BLUE,
 	C_BOLD_GREEN,
 	C_BOLD_RED,
 	C_CLEAR

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2 0/2] Improve coloured text readability
  2025-03-26 14:07 [PATCH iproute2 0/2] Improve coloured text readability Ben Hutchings
  2025-03-26 14:08 ` [PATCH iproute2 1/2] color: Assume background is dark if unknown Ben Hutchings
  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 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-06 17:00 UTC (permalink / raw)
  To: Ben Hutchings; +Cc: netdev, 1088739

Hello:

This series was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Wed, 26 Mar 2025 15:07:49 +0100 you wrote:
> Currently coloured text output isn't very readable in GNOME Terminal
> or xterm with a dark background:
> 
> - These terminals don't set $COLORFGBG, so we end up using the
>   light-background palette.
> 
> - The standard (dark) blue is also too close to black in their default
>   dark palettes.
> 
> [...]

Here is the summary with links:
  - [iproute2,1/2] color: Assume background is dark if unknown
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=cc0f1109d286
  - [iproute2,2/2] color: Do not use dark blue in dark-background palette
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=46a4659313c2

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-06 16:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 14:07 [PATCH iproute2 0/2] Improve coloured text readability Ben Hutchings
2025-03-26 14:08 ` [PATCH iproute2 1/2] color: Assume background is dark if unknown Ben Hutchings
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

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).