]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
terminal-util: add macro for adding underline to existing formats
authorLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2023 11:05:42 +0000 (12:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2023 12:00:43 +0000 (13:00 +0100)
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.

src/basic/terminal-util.h

index 2a7d48b95da8af1e03002591203ca7a656622269..cae42887c44a89659bde1d92c435f7cbe08813b0 100644 (file)
@@ -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 :  \