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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B7F2B1382C5 for ; Mon, 10 May 2021 09:16:03 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D98F5E07B3; Mon, 10 May 2021 09:16:02 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B7ECDE07AE for ; Mon, 10 May 2021 09:16:02 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6EA3A33FEDE for ; Mon, 10 May 2021 09:16:01 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 0CB4A729 for ; Mon, 10 May 2021 09:16:00 +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: <1620637963.03c2d27602bc94aaa1660da7b084d40a9cf70f5d.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: 03c2d27602bc94aaa1660da7b084d40a9cf70f5d X-VCS-Branch: master Date: Mon, 10 May 2021 09:16:00 +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: fa64db35-57c3-4124-9dce-ff54a7bbc30c X-Archives-Hash: 831626147d49a196c8f5c20352f4292b commit: 03c2d27602bc94aaa1660da7b084d40a9cf70f5d Author: Fabian Groffen gentoo org> AuthorDate: Mon May 10 09:12:43 2021 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Mon May 10 09:12:43 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=03c2d276 main: add global option --color to force colour output allow override for colouring to be enabled, this reorganises the code a bit because argument handling is done by the applets, and not by the main process, e.g. total colour handling can unfortunately not be done in a single place. Bug: https://bugs.gentoo.org/769929 Signed-off-by: Fabian Groffen gentoo.org> applets.h | 10 +++++++--- main.c | 23 +++++++++-------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/applets.h b/applets.h index 956ab67..8918ff0 100644 --- a/applets.h +++ b/applets.h @@ -1,9 +1,10 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - * Copyright 2005-2014 Mike Frysinger - + * Copyright 2019- Fabian Groffen - */ #ifndef _APPLETS_H_ @@ -133,6 +134,7 @@ static const struct applet_t { {"verbose", no_argument, NULL, 'v'}, \ {"quiet", no_argument, NULL, 'q'}, \ {"nocolor", no_argument, NULL, 'C'}, \ + {"color", no_argument, NULL, 0x2}, \ {"help", no_argument, NULL, 'h'}, \ {"version", no_argument, NULL, 'V'}, \ {NULL, no_argument, NULL, 0x0} @@ -141,6 +143,7 @@ static const struct applet_t { "Report full package versions, emit more elaborate output", \ "Tighter output; suppress warnings", \ "Don't output color", \ + "Force color in output", \ "Print this help and exit", \ "Print version and exit", \ NULL @@ -150,8 +153,9 @@ static const struct applet_t { case 'q': setup_quiet(); break; \ case 'V': version_barf(); break; \ case 'h': applet ## _usage(EXIT_SUCCESS); break; \ - case 'C': no_colors(); break; \ - default: applet ## _usage(EXIT_FAILURE); break; + case 'C': color_clear(); setenv("NOCOLOR", "true", 1); break; \ + case 0x2: color_remap(); unsetenv("NOCOLOR"); break; \ + default: applet ## _usage(EXIT_FAILURE); break; extern char *portarch; extern char *portroot; diff --git a/main.c b/main.c index ceab587..01b2542 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2020 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2008 Ned Ludd - @@ -70,14 +70,6 @@ init_coredumps(void) } #endif -void -no_colors(void) -{ - BOLD = NORM = BLUE = DKBLUE = CYAN = GREEN = DKGREEN = \ - MAGENTA = RED = YELLOW = BRYELLOW = WHITE = ""; - setenv("NOCOLOR", "true", 1); -} - void setup_quiet(void) { @@ -1041,10 +1033,13 @@ initialize_portage_env(void) if (getenv("PORTAGE_QUIET") != NULL) setup_quiet(); - if (nocolor) - no_colors(); - else + if (nocolor) { + color_clear(); + setenv("NOCOLOR", "true", 1); + } else { color_remap(); + unsetenv("NOCOLOR"); + } } int main(int argc, char **argv) @@ -1063,11 +1058,11 @@ int main(int argc, char **argv) twidth = 0; if (fstat(fileno(stdout), &st) != -1) { if (!isatty(fileno(stdout))) { - no_colors(); + nocolor = 1; } else { if ((getenv("TERM") == NULL) || (strcmp(getenv("TERM"), "dumb") == 0)) - no_colors(); + nocolor = 1; if (ioctl(0, TIOCGWINSZ, &winsz) == 0 && winsz.ws_col > 0) twidth = (int)winsz.ws_col; }