diff options
author | Fabian Groffen <grobian@gentoo.org> | 2021-05-10 11:12:43 +0200 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2021-05-10 11:12:43 +0200 |
commit | 03c2d27602bc94aaa1660da7b084d40a9cf70f5d (patch) | |
tree | d720cf7a9eb0eecf29e0f66bb0fe871535a6185e /main.c | |
parent | libq/colors: add color_clear() (diff) | |
download | portage-utils-03c2d27602bc94aaa1660da7b084d40a9cf70f5d.tar.gz portage-utils-03c2d27602bc94aaa1660da7b084d40a9cf70f5d.tar.bz2 portage-utils-03c2d27602bc94aaa1660da7b084d40a9cf70f5d.zip |
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 <grobian@gentoo.org>
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 23 |
1 files changed, 9 insertions, 14 deletions
@@ -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 - <solar@gentoo.org> @@ -71,14 +71,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) { /* "e" for FD_CLOEXEC */ @@ -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; } |