1 |
commit: 297e49f62a6520fce353b8e82f3bba430f1ea613 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Dec 23 12:53:42 2021 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Dec 23 12:53:42 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=297e49f6 |
7 |
|
8 |
main: ensure default colouring is respected |
9 |
|
10 |
Introduced in v0.93, a regression on picking up colour default. |
11 |
|
12 |
We were setting nocolor variable, but before it was acted on, it was |
13 |
overwritten with a default. So now instead set the default based on |
14 |
having a tty or not, and let profiles, env and flags override from |
15 |
there. |
16 |
|
17 |
Bug: https://bugs.gentoo.org/829837 |
18 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
19 |
|
20 |
applets.h | 14 +++++++++++--- |
21 |
main.c | 13 ++++++++++--- |
22 |
2 files changed, 21 insertions(+), 6 deletions(-) |
23 |
|
24 |
diff --git a/applets.h b/applets.h |
25 |
index 6070fe4..16e7d9f 100644 |
26 |
--- a/applets.h |
27 |
+++ b/applets.h |
28 |
@@ -153,8 +153,16 @@ static const struct applet_t { |
29 |
case 'q': setup_quiet(); break; \ |
30 |
case 'V': version_barf(); break; \ |
31 |
case 'h': applet ## _usage(EXIT_SUCCESS); break; \ |
32 |
- case 'C': color_clear(); setenv("NOCOLOR", "true", 1); break; \ |
33 |
- case 0x2: color_remap(); unsetenv("NOCOLOR"); break; \ |
34 |
+ case 'C': if (!nocolor) { \ |
35 |
+ nocolor = 1; \ |
36 |
+ color_clear(); \ |
37 |
+ setenv("NOCOLOR", "true", 1); \ |
38 |
+ } break; \ |
39 |
+ case 0x2: if (nocolor) { \ |
40 |
+ nocolor = 0; \ |
41 |
+ color_remap(); \ |
42 |
+ setenv("NOCOLOR", "false", 1); \ |
43 |
+ } break; \ |
44 |
default: applet ## _usage(EXIT_FAILURE); break; |
45 |
|
46 |
extern char *portarch; |
47 |
@@ -178,8 +186,8 @@ extern DEFINE_ARRAY(overlay_names); |
48 |
extern DEFINE_ARRAY(overlay_src); |
49 |
extern char *main_overlay; |
50 |
extern int twidth; |
51 |
+extern bool nocolor; |
52 |
|
53 |
-void no_colors(void); |
54 |
void setup_quiet(void); |
55 |
void version_barf(void); |
56 |
void usage(int status, const char *flags, struct option const opts[], |
57 |
|
58 |
diff --git a/main.c b/main.c |
59 |
index 06c52b7..b3f2f6d 100644 |
60 |
--- a/main.c |
61 |
+++ b/main.c |
62 |
@@ -30,6 +30,7 @@ char *module_name = NULL; |
63 |
int verbose = 0; |
64 |
int quiet = 0; |
65 |
int twidth; |
66 |
+bool nocolor; |
67 |
char pretend = 0; |
68 |
char *portarch; |
69 |
char *portroot; |
70 |
@@ -672,7 +673,6 @@ read_portage_profile(const char *profile, env_vars vars[], set *masks) |
71 |
read_portage_file(profile_file, PMASK_FILE, masks); |
72 |
} |
73 |
|
74 |
-static bool nocolor = 0; |
75 |
env_vars vars_to_read[] = { |
76 |
#define _Q_EV(t, V, set, lset, d) \ |
77 |
{ \ |
78 |
@@ -1091,7 +1091,7 @@ initialize_portage_env(void) |
79 |
} |
80 |
|
81 |
/* Make sure ROOT always ends in a slash */ |
82 |
- var = &vars_to_read[0]; |
83 |
+ var = &vars_to_read[0]; /* ROOT */ |
84 |
if (var->value_len == 0 || (*var->value.s)[var->value_len - 1] != '/') { |
85 |
portroot = xrealloc(portroot, var->value_len + 2); |
86 |
portroot[var->value_len] = '/'; |
87 |
@@ -1134,7 +1134,7 @@ initialize_portage_env(void) |
88 |
setenv("NOCOLOR", "true", 1); |
89 |
} else { |
90 |
color_remap(); |
91 |
- unsetenv("NOCOLOR"); |
92 |
+ setenv("NOCOLOR", "false", 1); |
93 |
} |
94 |
} |
95 |
|
96 |
@@ -1151,7 +1151,11 @@ int main(int argc, char **argv) |
97 |
bindtextdomain(argv0, CONFIG_EPREFIX "usr/share/locale"); |
98 |
textdomain(argv0); |
99 |
|
100 |
+ /* note: setting nocolor here is pointless, since |
101 |
+ * initialize_portage_env is going to re-init nocolor, so make |
102 |
+ * sure we modify the default instead. */ |
103 |
twidth = 0; |
104 |
+ nocolor = 0; |
105 |
if (fstat(fileno(stdout), &st) != -1) { |
106 |
if (!isatty(fileno(stdout))) { |
107 |
nocolor = 1; |
108 |
@@ -1162,7 +1166,10 @@ int main(int argc, char **argv) |
109 |
if (ioctl(0, TIOCGWINSZ, &winsz) == 0 && winsz.ws_col > 0) |
110 |
twidth = (int)winsz.ws_col; |
111 |
} |
112 |
+ } else { |
113 |
+ nocolor = 1; |
114 |
} |
115 |
+ vars_to_read[7].default_value = (char *)nocolor; /* NOCOLOR */ |
116 |
|
117 |
initialize_portage_env(); |
118 |
optind = 0; |