]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: replace ANSI_XYZ with ansi_xyz()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 10 Dec 2024 14:45:59 +0000 (23:45 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 11 Dec 2024 01:11:53 +0000 (10:11 +0900)
Continuation of f0484e096c9cfc22ae99f7452a366e2545255e30.

src/analyze/analyze-architectures.c
src/analyze/analyze-pcrs.c
src/analyze/analyze-security.c
src/libsystemd/sd-varlink/sd-varlink-idl.c
src/pcrlock/pcrlock.c
src/shared/logs-show.c
src/shared/pretty-print.c

index 2d155d57c1fcff10fa0af25d0c1ee1387f992ddf..08c62e628594d3efa08941856b5c5f2da3a6dc08 100644 (file)
@@ -12,10 +12,10 @@ static int add_arch(Table *t, Architecture a) {
 
         if (a == native_architecture()) {
                 c = "native";
-                color = ANSI_HIGHLIGHT_GREEN;
+                color = ansi_highlight_green();
         } else if (a == uname_architecture()) {
                 c = "uname";
-                color = ANSI_HIGHLIGHT;
+                color = ansi_highlight();
 #ifdef ARCHITECTURE_SECONDARY
         } else if (a == ARCHITECTURE_SECONDARY) {
                 c = "secondary";
@@ -23,7 +23,7 @@ static int add_arch(Table *t, Architecture a) {
 #endif
         } else {
                 c = "foreign";
-                color = ANSI_GREY;
+                color = ansi_grey();
         }
 
         r = table_add_many(t,
index 0848f8e5b491d72f10a43766fc24596364830432..fb67a733ddf5f8497b940240f010e99cd821d7c8 100644 (file)
@@ -77,7 +77,7 @@ static int add_pcr_to_table(Table *table, const char *alg, uint32_t pcr) {
                 /* Grey out PCRs that are not sensibly initialized */
                 if (memeqbyte(0, buf, bufsize) ||
                     memeqbyte(0xFFU, buf, bufsize))
-                        color = ANSI_GREY;
+                        color = ansi_grey();
         }
 
         r = table_add_many(table,
index aefd4f6122eb6654a794a644f73e79bedeb2b514..adbc72308ffbf419646cdf3c56543c6e88c99d7d 100644 (file)
@@ -1724,16 +1724,16 @@ static int assess(const SecurityInfo *info,
         static const struct {
                 uint64_t exposure;
                 const char *name;
-                const char *color;
+                const char* (*color)(void);
                 SpecialGlyph smiley;
         } badness_table[] = {
-                { 100, "DANGEROUS", ANSI_HIGHLIGHT_RED,    SPECIAL_GLYPH_DEPRESSED_SMILEY        },
-                { 90,  "UNSAFE",    ANSI_HIGHLIGHT_RED,    SPECIAL_GLYPH_UNHAPPY_SMILEY          },
-                { 75,  "EXPOSED",   ANSI_HIGHLIGHT_YELLOW, SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY },
+                { 100, "DANGEROUS", ansi_highlight_red,    SPECIAL_GLYPH_DEPRESSED_SMILEY        },
+                { 90,  "UNSAFE",    ansi_highlight_red,    SPECIAL_GLYPH_UNHAPPY_SMILEY          },
+                { 75,  "EXPOSED",   ansi_highlight_yellow, SPECIAL_GLYPH_SLIGHTLY_UNHAPPY_SMILEY },
                 { 50,  "MEDIUM",    NULL,                  SPECIAL_GLYPH_NEUTRAL_SMILEY          },
-                { 10,  "OK",        ANSI_HIGHLIGHT_GREEN,  SPECIAL_GLYPH_SLIGHTLY_HAPPY_SMILEY   },
-                { 1,   "SAFE",      ANSI_HIGHLIGHT_GREEN,  SPECIAL_GLYPH_HAPPY_SMILEY            },
-                { 0,   "PERFECT",   ANSI_HIGHLIGHT_GREEN,  SPECIAL_GLYPH_ECSTATIC_SMILEY         },
+                { 10,  "OK",        ansi_highlight_green,  SPECIAL_GLYPH_SLIGHTLY_HAPPY_SMILEY   },
+                { 1,   "SAFE",      ansi_highlight_green,  SPECIAL_GLYPH_HAPPY_SMILEY            },
+                { 0,   "PERFECT",   ansi_highlight_green,  SPECIAL_GLYPH_ECSTATIC_SMILEY         },
         };
 
         uint64_t badness_sum = 0, weight_sum = 0, exposure;
@@ -1911,7 +1911,7 @@ static int assess(const SecurityInfo *info,
                        ansi_highlight(),
                        name,
                        ansi_normal(),
-                       colors_enabled() ? strempty(badness_table[i].color) : "",
+                       badness_table[i].color ? badness_table[i].color() : "",
                        exposure / 10, exposure % 10,
                        badness_table[i].name,
                        ansi_normal(),
@@ -1938,7 +1938,7 @@ static int assess(const SecurityInfo *info,
                                    TABLE_STRING, buf,
                                    TABLE_SET_ALIGN_PERCENT, 100,
                                    TABLE_STRING, badness_table[i].name,
-                                   TABLE_SET_COLOR, strempty(badness_table[i].color),
+                                   TABLE_SET_COLOR, badness_table[i].color ? badness_table[i].color() : "",
                                    TABLE_STRING, special_glyph(badness_table[i].smiley));
                 if (r < 0)
                         return table_log_add_error(r);
index 58edcf02f769eea6f6515f672328043a92d8a3b5..19bd10f126ba4885f80c61e5147360a284e25fcb 100644 (file)
@@ -491,6 +491,15 @@ _public_ int sd_varlink_idl_dump(FILE *f, const sd_varlink_interface *interface,
                 [COLOR_COMMENT]     = ANSI_GREY,
         };
 
+        static const char* const color_16_table[_COLOR_MAX] = {
+                [COLOR_SYMBOL_TYPE] = ANSI_HIGHLIGHT_GREEN,
+                [COLOR_FIELD_TYPE]  = ANSI_HIGHLIGHT_BLUE,
+                [COLOR_IDENTIFIER]  = ANSI_NORMAL,
+                [COLOR_MARKS]       = ANSI_HIGHLIGHT_MAGENTA,
+                [COLOR_RESET]       = ANSI_NORMAL,
+                [COLOR_COMMENT]     = ANSI_BRIGHT_BLACK,
+        };
+
         static const char* const color_off[_COLOR_MAX] = {
                 "", "", "", "", "", "",
         };
@@ -505,7 +514,7 @@ _public_ int sd_varlink_idl_dump(FILE *f, const sd_varlink_interface *interface,
         bool use_colors = FLAGS_SET(flags, SD_VARLINK_IDL_FORMAT_COLOR) ||
                 (FLAGS_SET(flags, SD_VARLINK_IDL_FORMAT_COLOR_AUTO) && colors_enabled());
 
-        const char *const *colors = use_colors ? color_table : color_off;
+        const char *const *colors = use_colors ? (get_color_mode() == COLOR_16 ? color_16_table : color_table) : color_off;
 
         /* First output interface comments */
         r = varlink_idl_format_all_symbols(f, interface, _SD_VARLINK_INTERFACE_COMMENT, colors, cols);
index 25d76151b10b4d3a81c46f6501e650d76469c9a2..03611d507c4f021e5586a17834431ce0333df80d 100644 (file)
@@ -2297,7 +2297,7 @@ static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) {
                 for (size_t i = 0; i < el->n_algorithms; i++) {
                         const char *color;
 
-                        color = is_unset_pcr(el->registers[pcr].banks[i].calculated.buffer, el->registers[pcr].banks[i].calculated.size) ? ANSI_GREY : NULL;
+                        color = is_unset_pcr(el->registers[pcr].banks[i].calculated.buffer, el->registers[pcr].banks[i].calculated.size) ? ansi_grey() : NULL;
 
                         if (el->registers[pcr].banks[i].calculated.size > 0) {
                                 _cleanup_free_ char *hex = NULL;
@@ -2325,8 +2325,8 @@ static int show_pcr_table(EventLog *el, sd_json_variant **ret_variant) {
                         if (!hex)
                                 return log_oom();
 
-                        color = !hash_match ? ANSI_HIGHLIGHT_RED :
-                                is_unset_pcr(el->registers[pcr].banks[i].observed.buffer, el->registers[pcr].banks[i].observed.size) ? ANSI_GREY : NULL;
+                        color = !hash_match ? ansi_highlight_red() :
+                                is_unset_pcr(el->registers[pcr].banks[i].observed.buffer, el->registers[pcr].banks[i].observed.size) ? ansi_grey() : NULL;
 
                         r = table_add_many(table,
                                            TABLE_STRING, hex,
@@ -2638,7 +2638,7 @@ static int verb_list_components(int argc, char *argv[], void *userdata) {
                         if (marker) {
                                 r = table_add_many(table,
                                                    TABLE_STRING, marker,
-                                                   TABLE_SET_COLOR, ANSI_GREY,
+                                                   TABLE_SET_COLOR, ansi_grey(),
                                                    TABLE_EMPTY);
                                 if (r < 0)
                                         return table_log_add_error(r);
index 2289b83a1506414ab9f503e3295e67216d5c6231..4e7ed0be6fa09518da7fb6adb927c64050b81453 100644 (file)
@@ -230,8 +230,8 @@ static bool print_multiline(
                 get_log_colors(priority, &color_on, &color_off, &highlight_on);
 
                 if (audit && strempty(color_on)) {
-                        color_on = ANSI_BLUE;
-                        color_off = ANSI_NORMAL;
+                        color_on = ansi_blue();
+                        color_off = ansi_normal();
                 }
         }
 
@@ -827,12 +827,12 @@ static int output_verbose(
         timestamp = format_timestamp_style(buf, sizeof buf, usec,
                                            flags & OUTPUT_UTC ? TIMESTAMP_US_UTC : TIMESTAMP_US);
         fprintf(f, "%s%s%s %s[%s]%s\n",
-                timestamp && (flags & OUTPUT_COLOR) ? ANSI_UNDERLINE : "",
+                timestamp && (flags & OUTPUT_COLOR) ? ansi_underline() : "",
                 timestamp ?: "(no timestamp)",
-                timestamp && (flags & OUTPUT_COLOR) ? ANSI_NORMAL : "",
-                (flags & OUTPUT_COLOR) ? ANSI_GREY : "",
+                timestamp && (flags & OUTPUT_COLOR) ? ansi_normal() : "",
+                (flags & OUTPUT_COLOR) ? ansi_grey() : "",
                 cursor,
-                (flags & OUTPUT_COLOR) ? ANSI_NORMAL : "");
+                (flags & OUTPUT_COLOR) ? ansi_grey() : "");
 
         JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
                 _cleanup_free_ char *urlified = NULL;
@@ -859,8 +859,8 @@ static int output_verbose(
 
                 if (flags & OUTPUT_COLOR) {
                         if (startswith(data, "MESSAGE=")) {
-                                on = ANSI_HIGHLIGHT;
-                                off = ANSI_NORMAL;
+                                on = ansi_highlight();
+                                off = ansi_normal();
                         } else if (startswith(data, "CONFIG_FILE=")) {
                                 _cleanup_free_ char *u = NULL;
 
@@ -875,8 +875,8 @@ static int output_verbose(
 
                         } else if (startswith(data, "_")) {
                                 /* Highlight trusted data as such */
-                                on = ANSI_GREEN;
-                                off = ANSI_NORMAL;
+                                on = ansi_green();
+                                off = ansi_normal();
                         }
                 }
 
index 4e38e60775f4e496e580671e050621fe3c246aef..97fea7ac9ad0b7efc75cee0c0901f448cf2269c0 100644 (file)
@@ -293,12 +293,13 @@ void print_separator(void) {
                 size_t c = columns();
 
                 flockfile(stdout);
-                fputs_unlocked(ANSI_GREY_UNDERLINE, stdout);
+                fputs_unlocked(ansi_grey_underline(), stdout);
 
                 for (size_t i = 0; i < c; i++)
                         fputc_unlocked(' ', stdout);
 
-                fputs_unlocked(ANSI_NORMAL "\n\n", stdout);
+                fputs_unlocked(ansi_normal(), stdout);
+                fputs_unlocked("\n\n", stdout);
                 funlockfile(stdout);
         } else
                 fputs("\n\n", stdout);