commit: 09e2ac80fc030013031135bc3ffad19360920d6f Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Mon May 10 09:11:25 2021 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Mon May 10 09:11:25 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=09e2ac80
libq/colors: add color_clear() allow calling color_clear()/color_remap() repeatedly to disable/enable colour escapes (this is necessary for the delayed argument handling by the applets) Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> libq/colors.c | 92 +++++++++++++++++++++++++++++++++++++++-------------------- libq/colors.h | 3 +- 2 files changed, 63 insertions(+), 32 deletions(-) diff --git a/libq/colors.c b/libq/colors.c index 9a48e2e..6f3d7f1 100644 --- a/libq/colors.c +++ b/libq/colors.c @@ -1,5 +1,5 @@ /* - * 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 - <so...@gentoo.org> @@ -17,24 +17,22 @@ #else # define _MAKE_COLOR(c,b) "\e[" c ";" b "m" #endif -const char *BOLD = _MAKE_COLOR("00", "01"); -const char *NORM = _MAKE_COLOR("00", "00"); -const char *BLUE = _MAKE_COLOR("36", "01"); -const char *DKBLUE = _MAKE_COLOR("34", "01"); -const char *CYAN = _MAKE_COLOR("00", "36"); -const char *GREEN = _MAKE_COLOR("32", "01"); -const char *DKGREEN = _MAKE_COLOR("00", "32"); -const char *MAGENTA = _MAKE_COLOR("00", "35"); -const char *RED = _MAKE_COLOR("31", "01"); -const char *YELLOW = _MAKE_COLOR("33", "01"); -const char *BRYELLOW = _MAKE_COLOR("01", "33"); -const char *WHITE = _MAKE_COLOR("01", "38"); +const char *NORM; +const char *BLUE; +const char *BOLD; +const char *BRYELLOW; +const char *CYAN; +const char *DKBLUE; +const char *DKGREEN; +const char *GREEN; +const char *MAGENTA; +const char *RED; +const char *WHITE; +const char *YELLOW; static const char *COLOR_MAP = CONFIG_EPREFIX "etc/portage/color.map"; -#define COLOR _MAKE_COLOR #define CPAIR_VALUE_LEN 16 - typedef struct { const char *name; char value[CPAIR_VALUE_LEN]; @@ -43,22 +41,22 @@ typedef struct { #define X2(X) X, X static cpairtype color_pairs[] = { - {"blue", X2(COLOR("34", "01")) }, - {"brown", X2(COLOR("00", "33")) }, - {"darkblue", X2(COLOR("00", "34")) }, - {"darkgreen", X2(COLOR("00", "32")) }, - {"darkred", X2(COLOR("00", "31")) }, - {"faint", X2(COLOR("00", "02")) }, - {"fuchsia", X2(COLOR("35", "01")) }, - {"green", X2(COLOR("32", "01")) }, - {"purple", X2(COLOR("00", "35")) }, - {"red", X2(COLOR("31", "01")) }, - {"teal", X2(COLOR("00", "36")) }, - {"turquoise", X2(COLOR("36", "01")) }, - {"yellow", X2(COLOR("01", "33")) }, - {"white", X2(COLOR("01", "38")) }, - {"lightgray", X2(COLOR("00", "37")) }, - {"eol", X2(COLOR("00", "00")) }, + {"blue", X2(_MAKE_COLOR("34", "01")) }, + {"brown", X2(_MAKE_COLOR("00", "33")) }, + {"darkblue", X2(_MAKE_COLOR("00", "34")) }, + {"darkgreen", X2(_MAKE_COLOR("00", "32")) }, + {"darkred", X2(_MAKE_COLOR("00", "31")) }, + {"faint", X2(_MAKE_COLOR("00", "02")) }, + {"fuchsia", X2(_MAKE_COLOR("35", "01")) }, + {"green", X2(_MAKE_COLOR("32", "01")) }, + {"lightgray", X2(_MAKE_COLOR("00", "37")) }, + {"purple", X2(_MAKE_COLOR("00", "35")) }, + {"red", X2(_MAKE_COLOR("31", "01")) }, + {"teal", X2(_MAKE_COLOR("00", "36")) }, + {"turquoise", X2(_MAKE_COLOR("36", "01")) }, + {"white", X2(_MAKE_COLOR("01", "38")) }, + {"yellow", X2(_MAKE_COLOR("01", "33")) }, + {"eol", X2(_MAKE_COLOR("00", "00")) }, }; #undef X2 @@ -73,6 +71,21 @@ color_remap(void) char *p; unsigned int lineno = 0; + /* set q's defaults, if there's no colormap, or the file is empty, + * or it doesn't match things, we at least got some defaults */ + NORM = _MAKE_COLOR("00", "00"); + BLUE = _MAKE_COLOR("36", "01"); + BOLD = _MAKE_COLOR("00", "01"); + BRYELLOW = _MAKE_COLOR("01", "33"); + CYAN = _MAKE_COLOR("00", "36"); + DKBLUE = _MAKE_COLOR("34", "01"); + DKGREEN = _MAKE_COLOR("00", "32"); + GREEN = _MAKE_COLOR("32", "01"); + MAGENTA = _MAKE_COLOR("00", "35"); + RED = _MAKE_COLOR("31", "01"); + WHITE = _MAKE_COLOR("01", "38"); + YELLOW = _MAKE_COLOR("33", "01"); + if ((fp = fopen(COLOR_MAP, "r")) == NULL) return; @@ -141,3 +154,20 @@ color_remap(void) CYAN = color_pairs[i].value; } } + +void +color_clear(void) +{ + NORM = ""; + BLUE = ""; + BOLD = ""; + BRYELLOW = ""; + CYAN = ""; + DKBLUE = ""; + DKGREEN = ""; + GREEN = ""; + MAGENTA = ""; + RED = ""; + WHITE = ""; + YELLOW = ""; +} diff --git a/libq/colors.h b/libq/colors.h index 9947bc1..2c3de9b 100644 --- a/libq/colors.h +++ b/libq/colors.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2021 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2019- Fabian Groffen - <grob...@gentoo.org> @@ -22,5 +22,6 @@ extern const char *BRYELLOW; extern const char *WHITE; void color_remap(void); +void color_clear(void); #endif