From patchwork Wed Mar 26 14:08:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 14030104 X-Patchwork-Delegate: dsahern@gmail.com Received: from maynard.decadent.org.uk (maynard.decadent.org.uk [65.21.191.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F7161EDA34 for ; Wed, 26 Mar 2025 14:08:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.21.191.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742998115; cv=none; b=Ji+FOXkemJvOhddqmYl66SpF02ADg7mrBihjrLdyXfXXARgsCeoGQDy6mnzlekS0NHtpRAyWPBM53giPJtIOUUD9V8SaYhzZRG+4628XJ83t0WDu9R8Tcu+OKMtfDOopQuJl53MN+FHEXzmTwuxfLDaWwA2O4G3h89/V6scTQcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742998115; c=relaxed/simple; bh=7PJvNXeESnkT3I30lLhCqSCwgE7dEULIZmDJ2WTjop0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TxLQpQwoyxdclhZAuR+gUXscfOk1KLQW2ZsIoww16Trt6VaOpEh4R5Dvr8cPFeydLQn2IEnIQiDaoKgiqRko8IgkTOwbPJpmDRhNOEvOBjNxllNfKNp3z5oxMGba9lea1H9umcyH68PQt2+cjJiW8lrASZjKBgJEXdKhg2K7DOo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=decadent.org.uk; arc=none smtp.client-ip=65.21.191.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=decadent.org.uk Received: from [2a02:578:851f:1502:391e:c5f5:10e2:b9a3] (helo=deadeye) by maynard with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txRQk-00Aa6I-1p; Wed, 26 Mar 2025 14:08:30 +0000 Received: from ben by deadeye with local (Exim 4.98.1) (envelope-from ) id 1txRQj-00000004jT1-0mHo; Wed, 26 Mar 2025 15:08:29 +0100 Date: Wed, 26 Mar 2025 15:08:29 +0100 From: Ben Hutchings To: netdev@vger.kernel.org Cc: 1088739@bugs.debian.org Subject: [PATCH iproute2 1/2] color: Assume background is dark if unknown Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a02:578:851f:1502:391e:c5f5:10e2:b9a3 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on maynard); SAEximRunCond expanded to false X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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))) From patchwork Wed Mar 26 14:08:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Hutchings X-Patchwork-Id: 14030105 X-Patchwork-Delegate: dsahern@gmail.com Received: from maynard.decadent.org.uk (maynard.decadent.org.uk [65.21.191.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F3F21EDA34 for ; Wed, 26 Mar 2025 14:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=65.21.191.19 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742998141; cv=none; b=UogTXbBz/018bsJyQlQZqRxFWLeWtOqT8nLFI9CQPWKlSUa7S1gbneeuHnum5BsilQtIH0MDkPvwf4iR0tZVCS2IzvC4/wuxOpQ3mwffyzPdMaMLMEaJ4R2f7XH14myrJJmQy4F3ITqkQKdquQJPPJpoflsDZtPyNAWz4G1n0F4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742998141; c=relaxed/simple; bh=CsUicUuxg8bnsFN2wF+gOPmBexkOA7uPv9yv7q7WE/Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lfOISHr3zUFoKTKCyOXM/3cwi7JRAduYmYv9qrU0vmWSvbAT/4aPG1TJnRj1WEC+phgrn5cEdKbcJ06MpbBFKfcnnukIr9ugWh0rIAbREQwc1anPRnY8ZxRplZ0WjwJpXjY+IPUNmh1N1qmljO/31VIwi/qm/wpXWSWPLpwfIb8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org; spf=pass smtp.mailfrom=decadent.org.uk; arc=none smtp.client-ip=65.21.191.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=debian.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=decadent.org.uk Received: from [2a02:578:851f:1502:391e:c5f5:10e2:b9a3] (helo=deadeye) by maynard with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1txRRB-00Aa6T-2b; Wed, 26 Mar 2025 14:08:57 +0000 Received: from ben by deadeye with local (Exim 4.98.1) (envelope-from ) id 1txRRA-00000004jTf-3Oxx; Wed, 26 Mar 2025 15:08:56 +0100 Date: Wed, 26 Mar 2025 15:08:56 +0100 From: Ben Hutchings To: netdev@vger.kernel.org Cc: 1088739@bugs.debian.org Subject: [PATCH iproute2 2/2] color: Do not use dark blue in dark-background palette Message-ID: References: Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-SA-Exim-Connect-IP: 2a02:578:851f:1502:391e:c5f5:10e2:b9a3 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on maynard); SAEximRunCond expanded to false X-Patchwork-Delegate: dsahern@gmail.com 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 --- 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