tree-wide: replace ANSI_XYZ with ansi_xyz()

Continuation of f0484e096c.
This commit is contained in:
Yu Watanabe
2024-12-11 10:11:53 +09:00
parent dfe79b9ed2
commit 17e6e4d6b6
7 changed files with 40 additions and 30 deletions
+3 -3
View 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,
+1 -1
View 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,
+9 -9
View 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);
+10 -1
View 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);
+4 -4
View 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);
+10 -10
View 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();
}
}
+3 -2
View 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);