summaryrefslogtreecommitdiffstats
path: root/src/basic/terminal-util.h
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2023-07-12 10:42:43 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2023-07-12 20:05:20 +0200
commit25077313747218f977e72bcd26af19ff477e3a7f (patch)
treeb7a0ab3462e86f6d5c91011ad8a885a1b47fdb7a /src/basic/terminal-util.h
parentdevice-util: Declare iterator variables inline (diff)
downloadsystemd-25077313747218f977e72bcd26af19ff477e3a7f.tar.xz
systemd-25077313747218f977e72bcd26af19ff477e3a7f.zip
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.
Diffstat (limited to 'src/basic/terminal-util.h')
-rw-r--r--src/basic/terminal-util.h18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index 1723de34fa..0fa01dbdf8 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);