commit: 1f7dda98d39ec2a87a15d4c23908f16970c48393
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 20 14:03:50 2025 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Aug 20 14:03:50 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1f7dda98
libq/colors: apply colour defaults when no color.map file
In addition, nocolor is a boolean, so use it as such.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/colors.c | 6 +++---
main.c | 16 ++++++----------
2 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/libq/colors.c b/libq/colors.c
index 60da399..e7a69fe 100644
--- a/libq/colors.c
+++ b/libq/colors.c
@@ -140,13 +140,13 @@ color_remap(void)
char *p;
unsigned int lineno = 0;
- if ((fp = fopen(COLOR_MAP, "r")) == NULL)
- return;
-
/* (re)set to defaults */
for (i = 0; i < ARRAY_SIZE(colour_pairs); i++)
*(colour_pairs[i].var) = colour_pairs[i].origval;
+ if ((fp = fopen(COLOR_MAP, "r")) == NULL)
+ return;
+
buf = NULL;
while ((linelen = getline(&buf, &buflen, fp)) >= 0) {
lineno++;
diff --git a/main.c b/main.c
index 676988c..5e6cae2 100644
--- a/main.c
+++ b/main.c
@@ -787,7 +787,7 @@ env_vars vars_to_read[] = {
_Q_EVS(STR, ARCH, portarch, "")
_Q_EVS(ISTR, CONFIG_PROTECT, config_protect, "/etc")
_Q_EVS(ISTR, CONFIG_PROTECT_MASK, config_protect_mask, "")
- _Q_EVB(BOOL, NOCOLOR, nocolor, 0)
+ _Q_EVB(BOOL, NOCOLOR, nocolor, false)
_Q_EVT(ISET, FEATURES, features, NULL)
_Q_EVT(ISET, USE, ev_use, NULL)
_Q_EVS(STR, EPREFIX, eprefix, CONFIG_EPREFIX)
@@ -1261,21 +1261,21 @@ int main(int argc, char **argv)
/* disable colours when not writing to a terminal */
twidth = 0;
- nocolor = 0;
+ nocolor = false;
if (fstat(fileno(stdout), &st) != -1) {
if (!isatty(fileno(stdout))) {
- nocolor = 1;
+ nocolor = true;
} else {
if ((getenv("TERM") == NULL) ||
(strcmp(getenv("TERM"), "dumb") == 0))
- nocolor = 1;
+ nocolor = true;
if (ioctl(0, TIOCGWINSZ, &winsz) == 0 && winsz.ws_col >
0)
twidth = (int)winsz.ws_col;
}
} else {
- nocolor = 1;
+ nocolor = true;
}
- if (nocolor == 1)
+ if (nocolor)
set_portage_env_var(&vars_to_read[7], "true", "terminal"); /*
NOCOLOR */
/* We can use getopt here, but only in POSIX mode (which stops at
@@ -1320,10 +1320,6 @@ int main(int argc, char **argv)
if (getenv("PORTAGE_QUIET") != NULL)
setup_quiet();
- /* ensure color strings are initialised, early code here may use
- * e.g. warn which uses them */
- color_clear();
-
initialize_portage_env();
optind = 0;
return q_main(argc, argv);