From: Daan De Meyer Date: Wed, 12 Jul 2023 08:42:43 +0000 (+0200) Subject: basic: Fix color + underline functions/macros X-Git-Tag: v254-rc2~36^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=25077313747218f977e72bcd26af19ff477e3a7f;p=thirdparty%2Fsystemd.git basic: Fix color + underline functions/macros We currently concatenate ANSI_UNDERLINE to the color of our choice in DEFINE_ANSI_FUNC_UNDERLINE() and DEFINE_ANSI_FUNC_UNDERLINE_256(). The first thing that ANSI_UNDERLINE does is reset all previous ansi escape sequences, so you just get underlining without any colors. Let's fix the issue by actually concatenating _UNDERLINE to the given color macro name so this works properly. Also add missing color macros that this uncovered. --- diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 1723de34fa2..0fa01dbdf88 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -49,6 +49,7 @@ /* Underlined */ #define ANSI_GREY_UNDERLINE "\x1B[0;4;38;5;245m" +#define ANSI_BRIGHT_BLACK_UNDERLINE "\x1B[0;4;90m" #define ANSI_HIGHLIGHT_RED_UNDERLINE "\x1B[0;1;4;31m" #define ANSI_HIGHLIGHT_GREEN_UNDERLINE "\x1B[0;1;4;32m" #define ANSI_HIGHLIGHT_YELLOW_UNDERLINE "\x1B[0;1;4;38;5;185m" @@ -62,8 +63,10 @@ #define ANSI_HIGHLIGHT_UNDERLINE "\x1B[0;1;4m" /* Fallback colors: 256 -> 16 */ -#define ANSI_HIGHLIGHT_GREY_FALLBACK "\x1B[0;1;90m" -#define ANSI_HIGHLIGHT_YELLOW_FALLBACK "\x1B[0;1;33m" +#define ANSI_HIGHLIGHT_GREY_FALLBACK "\x1B[0;1;90m" +#define ANSI_HIGHLIGHT_GREY_FALLBACK_UNDERLINE "\x1B[0;1;4;90m" +#define ANSI_HIGHLIGHT_YELLOW_FALLBACK "\x1B[0;1;33m" +#define ANSI_HIGHLIGHT_YELLOW_FALLBACK_UNDERLINE "\x1B[0;1;4;33m" /* Reset/clear ANSI styles */ #define ANSI_NORMAL "\x1B[0m" @@ -177,9 +180,13 @@ static inline bool colors_enabled(void) { } \ } +static inline const char *ansi_underline(void) { + return underline_enabled() ? ANSI_UNDERLINE : ANSI_NORMAL; +} + #define DEFINE_ANSI_FUNC_UNDERLINE(name, NAME) \ static inline const char *ansi_##name(void) { \ - return underline_enabled() ? ANSI_##NAME ANSI_UNDERLINE : \ + return underline_enabled() ? ANSI_##NAME##_UNDERLINE : \ colors_enabled() ? ANSI_##NAME : ""; \ } @@ -188,8 +195,8 @@ static inline bool colors_enabled(void) { static inline const char *ansi_##name(void) { \ switch (get_color_mode()) { \ case COLOR_OFF: return ""; \ - case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK ANSI_UNDERLINE : ANSI_##FALLBACK; \ - default : return underline_enabled() ? ANSI_##NAME ANSI_UNDERLINE: ANSI_##NAME; \ + case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK##_UNDERLINE : ANSI_##FALLBACK; \ + default : return underline_enabled() ? ANSI_##NAME##_UNDERLINE: ANSI_##NAME; \ } \ } @@ -229,7 +236,6 @@ static inline const char* _ansi_highlight_yellow(void) { return colors_enabled() ? _ANSI_HIGHLIGHT_YELLOW : ""; } -DEFINE_ANSI_FUNC_UNDERLINE(underline, NORMAL); DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT); DEFINE_ANSI_FUNC_UNDERLINE_256(grey_underline, GREY, BRIGHT_BLACK); DEFINE_ANSI_FUNC_UNDERLINE(highlight_red_underline, HIGHLIGHT_RED);