From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id AAEFD158086 for ; Thu, 23 Dec 2021 12:55:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0BB6A2BC019; Thu, 23 Dec 2021 12:55:43 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 108132BC019 for ; Thu, 23 Dec 2021 12:55:40 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 748EB342D50 for ; Thu, 23 Dec 2021 12:55:38 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id BDDE3258 for ; Thu, 23 Dec 2021 12:55:36 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1640264022.297e49f62a6520fce353b8e82f3bba430f1ea613.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: applets.h main.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 297e49f62a6520fce353b8e82f3bba430f1ea613 X-VCS-Branch: master Date: Thu, 23 Dec 2021 12:55:36 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: c2558880-1ba6-4f3a-843e-54a122528a22 X-Archives-Hash: c941c605308b40ba371ac3fb0e648531 commit: 297e49f62a6520fce353b8e82f3bba430f1ea613 Author: Fabian Groffen gentoo org> AuthorDate: Thu Dec 23 12:53:42 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Thu Dec 23 12:53:42 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=297e49f6 main: ensure default colouring is respected Introduced in v0.93, a regression on picking up colour default. We were setting nocolor variable, but before it was acted on, it was overwritten with a default. So now instead set the default based on having a tty or not, and let profiles, env and flags override from there. Bug: https://bugs.gentoo.org/829837 Signed-off-by: Fabian Groffen gentoo.org> applets.h | 14 +++++++++++--- main.c | 13 ++++++++++--- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/applets.h b/applets.h index 6070fe4..16e7d9f 100644 --- a/applets.h +++ b/applets.h @@ -153,8 +153,16 @@ static const struct applet_t { case 'q': setup_quiet(); break; \ case 'V': version_barf(); break; \ case 'h': applet ## _usage(EXIT_SUCCESS); break; \ - case 'C': color_clear(); setenv("NOCOLOR", "true", 1); break; \ - case 0x2: color_remap(); unsetenv("NOCOLOR"); break; \ + case 'C': if (!nocolor) { \ + nocolor = 1; \ + color_clear(); \ + setenv("NOCOLOR", "true", 1); \ + } break; \ + case 0x2: if (nocolor) { \ + nocolor = 0; \ + color_remap(); \ + setenv("NOCOLOR", "false", 1); \ + } break; \ default: applet ## _usage(EXIT_FAILURE); break; extern char *portarch; @@ -178,8 +186,8 @@ extern DEFINE_ARRAY(overlay_names); extern DEFINE_ARRAY(overlay_src); extern char *main_overlay; extern int twidth; +extern bool nocolor; -void no_colors(void); void setup_quiet(void); void version_barf(void); void usage(int status, const char *flags, struct option const opts[], diff --git a/main.c b/main.c index 06c52b7..b3f2f6d 100644 --- a/main.c +++ b/main.c @@ -30,6 +30,7 @@ char *module_name = NULL; int verbose = 0; int quiet = 0; int twidth; +bool nocolor; char pretend = 0; char *portarch; char *portroot; @@ -672,7 +673,6 @@ read_portage_profile(const char *profile, env_vars vars[], set *masks) read_portage_file(profile_file, PMASK_FILE, masks); } -static bool nocolor = 0; env_vars vars_to_read[] = { #define _Q_EV(t, V, set, lset, d) \ { \ @@ -1091,7 +1091,7 @@ initialize_portage_env(void) } /* Make sure ROOT always ends in a slash */ - var = &vars_to_read[0]; + var = &vars_to_read[0]; /* ROOT */ if (var->value_len == 0 || (*var->value.s)[var->value_len - 1] != '/') { portroot = xrealloc(portroot, var->value_len + 2); portroot[var->value_len] = '/'; @@ -1134,7 +1134,7 @@ initialize_portage_env(void) setenv("NOCOLOR", "true", 1); } else { color_remap(); - unsetenv("NOCOLOR"); + setenv("NOCOLOR", "false", 1); } } @@ -1151,7 +1151,11 @@ int main(int argc, char **argv) bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale"); textdomain(argv0); + /* note: setting nocolor here is pointless, since + * initialize_portage_env is going to re-init nocolor, so make + * sure we modify the default instead. */ twidth = 0; + nocolor = 0; if (fstat(fileno(stdout), &st) != -1) { if (!isatty(fileno(stdout))) { nocolor = 1; @@ -1162,7 +1166,10 @@ int main(int argc, char **argv) if (ioctl(0, TIOCGWINSZ, &winsz) == 0 && winsz.ws_col > 0) twidth = (int)winsz.ws_col; } + } else { + nocolor = 1; } + vars_to_read[7].default_value = (char *)nocolor; /* NOCOLOR */ initialize_portage_env(); optind = 0;