aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--applets.h14
-rw-r--r--main.c13
2 files changed, 21 insertions, 6 deletions
diff --git a/applets.h b/applets.h
index 6070fe40..16e7d9f4 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 06c52b7d..b3f2f6d8 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;