From: Lennart Poettering Date: Mon, 20 Nov 2023 11:05:42 +0000 (+0100) Subject: terminal-util: add macro for adding underline to existing formats X-Git-Tag: v256-rc1~1577^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ad2049dd94b62e53bddefa1be644a298ceaa21b;p=thirdparty%2Fsystemd.git terminal-util: add macro for adding underline to existing formats This is different from the existing macros that generate "underline" ANSI sequences: these ones are additive, i.e. do not reset the font to the default first. The idea is to combine these with other ansi sequences. --- diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index 2a7d48b95da..cae42887c44 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -59,6 +59,8 @@ /* Other ANSI codes */ #define ANSI_UNDERLINE "\x1B[0;4m" +#define ANSI_ADD_UNDERLINE "\x1B[4m" +#define ANSI_ADD_UNDERLINE_GREY ANSI_ADD_UNDERLINE "\x1B[58;5;245m" #define ANSI_HIGHLIGHT "\x1B[0;1;39m" #define ANSI_HIGHLIGHT_UNDERLINE "\x1B[0;1;4m" @@ -189,6 +191,15 @@ static inline const char *ansi_underline(void) { return underline_enabled() ? ANSI_UNDERLINE : ANSI_NORMAL; } +static inline const char *ansi_add_underline(void) { + return underline_enabled() ? ANSI_ADD_UNDERLINE : ""; +} + +static inline const char *ansi_add_underline_grey(void) { + return underline_enabled() ? + (colors_enabled() ? ANSI_ADD_UNDERLINE_GREY : ANSI_ADD_UNDERLINE) : ""; +} + #define DEFINE_ANSI_FUNC_UNDERLINE(name, NAME) \ static inline const char *ansi_##name(void) { \ return underline_enabled() ? ANSI_##NAME##_UNDERLINE : \