Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/
Date: Mon, 26 Mar 2018 18:41:09
Message-Id: 1522089643.09dad6bdeb1e750ce0bbb25c6123f3ad23ca3d3a.grobian@gentoo
1 commit: 09dad6bdeb1e750ce0bbb25c6123f3ad23ca3d3a
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Mon Mar 26 18:40:43 2018 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Mon Mar 26 18:40:43 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=09dad6bd
7
8 colors: add support for color=color mappings
9
10 This patch is based on the work by Pavel Balaev <pascal <AT> unixdev.ru>.
11
12 Add support for color=color mappings. While at it, make color remapping
13 independent of the order in which they are defined in color.map.
14
15 Bug: https://bugs.gentoo.org/651546
16
17 libq/colors.c | 65 ++++++++++++++++++++++++++++++++++++++++-------------------
18 1 file changed, 44 insertions(+), 21 deletions(-)
19
20 diff --git a/libq/colors.c b/libq/colors.c
21 index 33f6d89..5f252b6 100644
22 --- a/libq/colors.c
23 +++ b/libq/colors.c
24 @@ -21,29 +21,34 @@ static const char *WHITE = _MAKE_COLOR("01", "38");
25 static const char *COLOR_MAP = CONFIG_EPREFIX "etc/portage/color.map";
26
27 #define COLOR _MAKE_COLOR
28 +#define CPAIR_VALUE_LEN 16
29
30 typedef struct {
31 const char *name;
32 - char value[16];
33 + char value[CPAIR_VALUE_LEN];
34 + char origval[CPAIR_VALUE_LEN];
35 } cpairtype;
36
37 +#define X2(X) X, X
38 static cpairtype color_pairs[] = {
39 - {"blue", COLOR("34", "01") },
40 - {"brown", COLOR("00", "33") },
41 - {"darkblue", COLOR("00", "34") },
42 - {"darkgreen", COLOR("00", "32") },
43 - {"darkred", COLOR("00", "31") },
44 - {"faint", COLOR("00", "02") },
45 - {"fuchsia", COLOR("35", "01") },
46 - {"green", COLOR("32", "01") },
47 - {"purple", COLOR("00", "35") },
48 - {"red", COLOR("31", "01") },
49 - {"teal", COLOR("00", "36") },
50 - {"turquoise", COLOR("36", "01") },
51 - {"yellow", COLOR("01", "33") },
52 - {"white", COLOR("01", "38") },
53 - {"eol", COLOR("00", "00") },
54 + {"blue", X2(COLOR("34", "01")) },
55 + {"brown", X2(COLOR("00", "33")) },
56 + {"darkblue", X2(COLOR("00", "34")) },
57 + {"darkgreen", X2(COLOR("00", "32")) },
58 + {"darkred", X2(COLOR("00", "31")) },
59 + {"faint", X2(COLOR("00", "02")) },
60 + {"fuchsia", X2(COLOR("35", "01")) },
61 + {"green", X2(COLOR("32", "01")) },
62 + {"purple", X2(COLOR("00", "35")) },
63 + {"red", X2(COLOR("31", "01")) },
64 + {"teal", X2(COLOR("00", "36")) },
65 + {"turquoise", X2(COLOR("36", "01")) },
66 + {"yellow", X2(COLOR("01", "33")) },
67 + {"white", X2(COLOR("01", "38")) },
68 + {"lightgray", X2(COLOR("00", "37")) },
69 + {"eol", X2(COLOR("00", "00")) },
70 };
71 +#undef X2
72
73 static void
74 color_remap(void)
75 @@ -73,13 +78,31 @@ color_remap(void)
76 continue;
77
78 *p++ = 0; /* split the pair */
79 - for (i = 0; i < ARRAY_SIZE(color_pairs); ++i)
80 + for (i = 0; i < ARRAY_SIZE(color_pairs); ++i) {
81 if (strcmp(buf, color_pairs[i].name) == 0) {
82 - if (strncmp(p, "0x", 2) == 0)
83 - warn("[%s=%s] RGB values in color map are not supported on line %d of %s", buf, p, lineno, COLOR_MAP);
84 - else
85 - snprintf(color_pairs[i].value, sizeof(color_pairs[i].value), "\e[%s", p);
86 + if (strncmp(p, "0x", 2) == 0) {
87 + warn("[%s=%s] RGB values in color map are not "
88 + "supported on line %d of %s",
89 + buf, p, lineno, COLOR_MAP);
90 + } else {
91 + /* color=color format support */
92 + size_t n;
93 + int found = 0;
94 + for (n = 0; n < ARRAY_SIZE(color_pairs); n++) {
95 + if (strcmp(color_pairs[n].name, p) == 0) {
96 + strncpy(color_pairs[i].value,
97 + color_pairs[n].origval, CPAIR_VALUE_LEN);
98 + found = 1;
99 + break;
100 + }
101 + }
102 +
103 + if (!found)
104 + snprintf(color_pairs[i].value,
105 + sizeof(color_pairs[i].origval), "\e[%s", p);
106 + }
107 }
108 + }
109 }
110
111 free(buf);