tree-wide: avoid direct use of color macros
This commit is contained in:
parent
c4fea19abb
commit
25e4608b8b
|
@ -404,7 +404,7 @@ static int write_to_console(
|
||||||
if (show_location) {
|
if (show_location) {
|
||||||
const char *lon = "", *loff = "";
|
const char *lon = "", *loff = "";
|
||||||
if (log_get_show_color()) {
|
if (log_get_show_color()) {
|
||||||
lon = ANSI_HIGHLIGHT_YELLOW4;
|
lon = ansi_highlight_yellow4();
|
||||||
loff = ANSI_NORMAL;
|
loff = ANSI_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -165,8 +165,7 @@ int ask_char(char *ret, const char *replies, const char *fmt, ...) {
|
||||||
char c;
|
char c;
|
||||||
bool need_nl = true;
|
bool need_nl = true;
|
||||||
|
|
||||||
if (colors_enabled())
|
fputs(ansi_highlight(), stdout);
|
||||||
fputs(ANSI_HIGHLIGHT, stdout);
|
|
||||||
|
|
||||||
putchar('\r');
|
putchar('\r');
|
||||||
|
|
||||||
|
@ -174,8 +173,7 @@ int ask_char(char *ret, const char *replies, const char *fmt, ...) {
|
||||||
vprintf(fmt, ap);
|
vprintf(fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (colors_enabled())
|
fputs(ansi_normal(), stdout);
|
||||||
fputs(ANSI_NORMAL, stdout);
|
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
@ -214,15 +212,13 @@ int ask_string(char **ret, const char *text, ...) {
|
||||||
assert(ret);
|
assert(ret);
|
||||||
assert(text);
|
assert(text);
|
||||||
|
|
||||||
if (colors_enabled())
|
fputs(ansi_highlight(), stdout);
|
||||||
fputs(ANSI_HIGHLIGHT, stdout);
|
|
||||||
|
|
||||||
va_start(ap, text);
|
va_start(ap, text);
|
||||||
vprintf(text, ap);
|
vprintf(text, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (colors_enabled())
|
fputs(ansi_normal(), stdout);
|
||||||
fputs(ANSI_NORMAL, stdout);
|
|
||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
|
@ -1384,7 +1380,7 @@ void get_log_colors(int priority, const char **on, const char **off, const char
|
||||||
|
|
||||||
if (priority <= LOG_ERR) {
|
if (priority <= LOG_ERR) {
|
||||||
if (on)
|
if (on)
|
||||||
*on = ANSI_HIGHLIGHT_RED;
|
*on = ansi_highlight_red();
|
||||||
if (off)
|
if (off)
|
||||||
*off = ANSI_NORMAL;
|
*off = ANSI_NORMAL;
|
||||||
if (highlight)
|
if (highlight)
|
||||||
|
@ -1392,7 +1388,7 @@ void get_log_colors(int priority, const char **on, const char **off, const char
|
||||||
|
|
||||||
} else if (priority <= LOG_WARNING) {
|
} else if (priority <= LOG_WARNING) {
|
||||||
if (on)
|
if (on)
|
||||||
*on = ANSI_HIGHLIGHT_YELLOW;
|
*on = ansi_highlight_yellow();
|
||||||
if (off)
|
if (off)
|
||||||
*off = ANSI_NORMAL;
|
*off = ANSI_NORMAL;
|
||||||
if (highlight)
|
if (highlight)
|
||||||
|
@ -1404,14 +1400,14 @@ void get_log_colors(int priority, const char **on, const char **off, const char
|
||||||
if (off)
|
if (off)
|
||||||
*off = ANSI_NORMAL;
|
*off = ANSI_NORMAL;
|
||||||
if (highlight)
|
if (highlight)
|
||||||
*highlight = ANSI_HIGHLIGHT_RED;
|
*highlight = ansi_highlight_red();
|
||||||
|
|
||||||
} else if (priority >= LOG_DEBUG) {
|
} else if (priority >= LOG_DEBUG) {
|
||||||
if (on)
|
if (on)
|
||||||
*on = ANSI_GREY;
|
*on = ansi_grey();
|
||||||
if (off)
|
if (off)
|
||||||
*off = ANSI_NORMAL;
|
*off = ANSI_NORMAL;
|
||||||
if (highlight)
|
if (highlight)
|
||||||
*highlight = ANSI_HIGHLIGHT_RED;
|
*highlight = ansi_highlight_red();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,6 +208,7 @@ DEFINE_ANSI_FUNC(highlight_black, HIGHLIGHT_BLACK);
|
||||||
DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
|
DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
|
||||||
DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
|
DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
|
||||||
DEFINE_ANSI_FUNC_256(highlight_yellow, HIGHLIGHT_YELLOW, HIGHLIGHT_YELLOW_FALLBACK);
|
DEFINE_ANSI_FUNC_256(highlight_yellow, HIGHLIGHT_YELLOW, HIGHLIGHT_YELLOW_FALLBACK);
|
||||||
|
DEFINE_ANSI_FUNC_256(highlight_yellow4, HIGHLIGHT_YELLOW4, HIGHLIGHT_YELLOW_FALLBACK);
|
||||||
DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
|
DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
|
||||||
DEFINE_ANSI_FUNC(highlight_magenta, HIGHLIGHT_MAGENTA);
|
DEFINE_ANSI_FUNC(highlight_magenta, HIGHLIGHT_MAGENTA);
|
||||||
DEFINE_ANSI_FUNC(highlight_cyan, HIGHLIGHT_CYAN);
|
DEFINE_ANSI_FUNC(highlight_cyan, HIGHLIGHT_CYAN);
|
||||||
|
|
|
@ -41,7 +41,9 @@ static void draw_progress(uint64_t p, usec_t *last_usec) {
|
||||||
|
|
||||||
fputs("\r", stdout);
|
fputs("\r", stdout);
|
||||||
if (colors_enabled())
|
if (colors_enabled())
|
||||||
fputs("\x1B[?25l" ANSI_HIGHLIGHT_GREEN, stdout);
|
fputs("\x1B[?25l", stdout);
|
||||||
|
|
||||||
|
fputs(ansi_highlight_green(), stdout);
|
||||||
|
|
||||||
for (i = 0; i < j; i++)
|
for (i = 0; i < j; i++)
|
||||||
fputs("\xe2\x96\x88", stdout);
|
fputs("\xe2\x96\x88", stdout);
|
||||||
|
|
|
@ -481,7 +481,7 @@ int ask_password_tty(
|
||||||
|
|
||||||
if (!(flags & ASK_PASSWORD_SILENT) && !(flags & ASK_PASSWORD_ECHO)) {
|
if (!(flags & ASK_PASSWORD_SILENT) && !(flags & ASK_PASSWORD_ECHO)) {
|
||||||
if (use_color)
|
if (use_color)
|
||||||
(void) loop_write(ttyfd, ANSI_GREY, STRLEN(ANSI_GREY), false);
|
(void) loop_write(ttyfd, ansi_grey(), strlen(ansi_grey()), false);
|
||||||
(void) loop_write(ttyfd, PRESS_TAB, strlen(PRESS_TAB), false);
|
(void) loop_write(ttyfd, PRESS_TAB, strlen(PRESS_TAB), false);
|
||||||
press_tab_visible = true;
|
press_tab_visible = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1495,7 +1495,7 @@ static void json_format_string(FILE *f, const char *q, JsonFormatFlags flags) {
|
||||||
fputc('"', f);
|
fputc('"', f);
|
||||||
|
|
||||||
if (flags & JSON_FORMAT_COLOR)
|
if (flags & JSON_FORMAT_COLOR)
|
||||||
fputs(ANSI_GREEN, f);
|
fputs(ansi_green(), f);
|
||||||
|
|
||||||
for (; *q; q++)
|
for (; *q; q++)
|
||||||
switch (*q) {
|
switch (*q) {
|
||||||
|
@ -1557,7 +1557,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
|
||||||
return -errno;
|
return -errno;
|
||||||
|
|
||||||
if (flags & JSON_FORMAT_COLOR)
|
if (flags & JSON_FORMAT_COLOR)
|
||||||
fputs(ANSI_HIGHLIGHT_BLUE, f);
|
fputs(ansi_highlight_blue(), f);
|
||||||
|
|
||||||
fprintf(f, "%.*Le", DECIMAL_DIG, json_variant_real(v));
|
fprintf(f, "%.*Le", DECIMAL_DIG, json_variant_real(v));
|
||||||
|
|
||||||
|
@ -1570,7 +1570,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
|
||||||
|
|
||||||
case JSON_VARIANT_INTEGER:
|
case JSON_VARIANT_INTEGER:
|
||||||
if (flags & JSON_FORMAT_COLOR)
|
if (flags & JSON_FORMAT_COLOR)
|
||||||
fputs(ANSI_HIGHLIGHT_BLUE, f);
|
fputs(ansi_highlight_blue(), f);
|
||||||
|
|
||||||
fprintf(f, "%" PRIdMAX, json_variant_integer(v));
|
fprintf(f, "%" PRIdMAX, json_variant_integer(v));
|
||||||
|
|
||||||
|
@ -1580,7 +1580,7 @@ static int json_format(FILE *f, JsonVariant *v, JsonFormatFlags flags, const cha
|
||||||
|
|
||||||
case JSON_VARIANT_UNSIGNED:
|
case JSON_VARIANT_UNSIGNED:
|
||||||
if (flags & JSON_FORMAT_COLOR)
|
if (flags & JSON_FORMAT_COLOR)
|
||||||
fputs(ANSI_HIGHLIGHT_BLUE, f);
|
fputs(ansi_highlight_blue(), f);
|
||||||
|
|
||||||
fprintf(f, "%" PRIuMAX, json_variant_unsigned(v));
|
fprintf(f, "%" PRIuMAX, json_variant_unsigned(v));
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ static int print_catalog(FILE *f, sd_journal *j) {
|
||||||
prefix = "--";
|
prefix = "--";
|
||||||
|
|
||||||
if (colors_enabled())
|
if (colors_enabled())
|
||||||
newline = strjoina(ANSI_NORMAL "\n" ANSI_GREY, prefix, ANSI_NORMAL " " ANSI_GREEN);
|
newline = strjoina(ANSI_NORMAL "\n", ansi_grey(), prefix, ANSI_NORMAL " ", ansi_green());
|
||||||
else
|
else
|
||||||
newline = strjoina("\n", prefix, " ");
|
newline = strjoina("\n", prefix, " ");
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ static int print_catalog(FILE *f, sd_journal *j) {
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
if (colors_enabled())
|
if (colors_enabled())
|
||||||
fprintf(f, ANSI_GREY "%s" ANSI_NORMAL " " ANSI_GREEN, prefix);
|
fprintf(f, "%s%s %s%s", ansi_grey(), prefix, ANSI_NORMAL, ansi_green());
|
||||||
else
|
else
|
||||||
fprintf(f, "%s ", prefix);
|
fprintf(f, "%s ", prefix);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue