summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-07-11 11:02:28 +0200
committerLennart Poettering <lennart@poettering.net>2024-07-19 11:44:04 +0200
commitb7120388f8dd638aec33dc640f273d1a9016d676 (patch)
tree121d10495834fd4dcdf9d03d88f61e7080e9b56e
parentterminal-util: remove terminal_vhangup() because apparently unused (diff)
downloadsystemd-b7120388f8dd638aec33dc640f273d1a9016d676.tar.xz
systemd-b7120388f8dd638aec33dc640f273d1a9016d676.zip
terminal-util: split out color macros/helpers into its own header
This is a lot of stuff, and sometimes quite wild, let's turn this into its own header. All stuff color-related that just generates sequences is now in ansi-color.h (no .c file!), and everything more complex that probes/ineracts with terminals remains in termina-util.[ch]
-rw-r--r--src/basic/ansi-color.h162
-rw-r--r--src/basic/build.c1
-rw-r--r--src/basic/log.c1
-rw-r--r--src/basic/terminal-util.c1
-rw-r--r--src/basic/terminal-util.h158
-rw-r--r--src/core/emergency-action.c1
-rw-r--r--src/core/job.c1
-rw-r--r--src/core/transaction.c1
-rw-r--r--src/core/unit.c1
-rw-r--r--src/cryptenroll/cryptenroll-recovery.c1
-rw-r--r--src/home/homectl-recovery-key.c1
-rw-r--r--src/import/export.c1
-rw-r--r--src/import/import-fs.c1
-rw-r--r--src/import/import.c1
-rw-r--r--src/import/pull.c1
-rw-r--r--src/journal/journalctl-authenticate.c1
-rw-r--r--src/journal/journalctl-show.c1
-rw-r--r--src/libsystemd/sd-bus/bus-dump.c1
-rw-r--r--src/libsystemd/sd-journal/journal-verify.c1
-rw-r--r--src/libsystemd/sd-journal/test-journal-verify.c1
-rw-r--r--src/libsystemd/sd-json/sd-json.c1
-rw-r--r--src/libsystemd/sd-varlink/sd-varlink-idl.c1
-rw-r--r--src/shared/ask-password-api.c1
-rw-r--r--src/shared/blockdev-list.c1
-rw-r--r--src/shared/bus-unit-procs.c1
-rw-r--r--src/shared/cgroup-show.c1
-rw-r--r--src/shared/pretty-print.h1
-rw-r--r--src/shared/ptyfwd.c1
-rw-r--r--src/shared/qrcode-util.c1
-rw-r--r--src/systemctl/systemctl-list-dependencies.c1
-rw-r--r--src/systemctl/systemctl-list-jobs.c1
-rw-r--r--src/systemctl/systemctl-list-machines.c1
-rw-r--r--src/systemctl/systemctl-list-unit-files.c1
-rw-r--r--src/systemctl/systemctl-list-units.c1
-rw-r--r--src/systemctl/systemctl-start-unit.c1
-rw-r--r--src/sysupdate/sysupdate-update-set-flags.c1
-rw-r--r--src/sysupdate/sysupdate-update-set.c1
-rw-r--r--src/test/test-ellipsize.c1
-rw-r--r--src/test/test-terminal-util.c1
-rw-r--r--src/udev/udevadm-info.c1
-rw-r--r--src/udev/udevadm-test.c1
41 files changed, 201 insertions, 158 deletions
diff --git a/src/basic/ansi-color.h b/src/basic/ansi-color.h
new file mode 100644
index 0000000000..efc1dea131
--- /dev/null
+++ b/src/basic/ansi-color.h
@@ -0,0 +1,162 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+#include "terminal-util.h"
+
+/* Regular colors */
+#define ANSI_BLACK "\x1B[0;30m" /* Some type of grey usually. */
+#define ANSI_RED "\x1B[0;31m"
+#define ANSI_GREEN "\x1B[0;32m"
+#define ANSI_YELLOW "\x1B[0;33m"
+#define ANSI_BLUE "\x1B[0;34m"
+#define ANSI_MAGENTA "\x1B[0;35m"
+#define ANSI_CYAN "\x1B[0;36m"
+#define ANSI_WHITE "\x1B[0;37m" /* This is actually rendered as light grey, legible even on a white
+ * background. See ANSI_HIGHLIGHT_WHITE for real white. */
+
+#define ANSI_BRIGHT_BLACK "\x1B[0;90m"
+#define ANSI_BRIGHT_RED "\x1B[0;91m"
+#define ANSI_BRIGHT_GREEN "\x1B[0;92m"
+#define ANSI_BRIGHT_YELLOW "\x1B[0;93m"
+#define ANSI_BRIGHT_BLUE "\x1B[0;94m"
+#define ANSI_BRIGHT_MAGENTA "\x1B[0;95m"
+#define ANSI_BRIGHT_CYAN "\x1B[0;96m"
+#define ANSI_BRIGHT_WHITE "\x1B[0;97m"
+
+#define ANSI_GREY "\x1B[0;38;5;245m"
+
+/* Bold/highlighted */
+#define ANSI_HIGHLIGHT_BLACK "\x1B[0;1;30m"
+#define ANSI_HIGHLIGHT_RED "\x1B[0;1;31m"
+#define ANSI_HIGHLIGHT_GREEN "\x1B[0;1;32m"
+#define _ANSI_HIGHLIGHT_YELLOW "\x1B[0;1;33m" /* This yellow is currently not displayed well by some terminals */
+#define ANSI_HIGHLIGHT_BLUE "\x1B[0;1;34m"
+#define ANSI_HIGHLIGHT_MAGENTA "\x1B[0;1;35m"
+#define ANSI_HIGHLIGHT_CYAN "\x1B[0;1;36m"
+#define ANSI_HIGHLIGHT_WHITE "\x1B[0;1;37m"
+#define ANSI_HIGHLIGHT_YELLOW4 "\x1B[0;1;38:5:100m"
+#define ANSI_HIGHLIGHT_KHAKI3 "\x1B[0;1;38:5:185m"
+#define ANSI_HIGHLIGHT_GREY "\x1B[0;1;38:5:245m"
+
+#define ANSI_HIGHLIGHT_YELLOW ANSI_HIGHLIGHT_KHAKI3 /* Replacement yellow that is more legible */
+
+/* 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"
+#define ANSI_HIGHLIGHT_BLUE_UNDERLINE "\x1B[0;1;4;34m"
+#define ANSI_HIGHLIGHT_MAGENTA_UNDERLINE "\x1B[0;1;4;35m"
+#define ANSI_HIGHLIGHT_GREY_UNDERLINE "\x1B[0;1;4;38:5:245m"
+
+/* 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"
+
+/* Fallback colors: 256 → 16 */
+#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"
+
+/* Background colors */
+#define ANSI_BACKGROUND_BLUE "\x1B[44m"
+
+/* Reset/clear ANSI styles */
+#define ANSI_NORMAL "\x1B[0m"
+
+#define DEFINE_ANSI_FUNC(name, NAME) \
+ static inline const char* ansi_##name(void) { \
+ return colors_enabled() ? ANSI_##NAME : ""; \
+ }
+
+#define DEFINE_ANSI_FUNC_256(name, NAME, FALLBACK) \
+ static inline const char* ansi_##name(void) { \
+ switch (get_color_mode()) { \
+ case COLOR_OFF: return ""; \
+ case COLOR_16: return ANSI_##FALLBACK; \
+ default : return ANSI_##NAME; \
+ } \
+ }
+
+static inline const char* ansi_underline(void) {
+ return underline_enabled() ? ANSI_UNDERLINE : "";
+}
+
+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 : \
+ colors_enabled() ? ANSI_##NAME : ""; \
+ }
+
+
+#define DEFINE_ANSI_FUNC_UNDERLINE_256(name, NAME, FALLBACK) \
+ static inline const char* ansi_##name(void) { \
+ switch (get_color_mode()) { \
+ case COLOR_OFF: return ""; \
+ case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK##_UNDERLINE : ANSI_##FALLBACK; \
+ default : return underline_enabled() ? ANSI_##NAME##_UNDERLINE: ANSI_##NAME; \
+ } \
+ }
+
+DEFINE_ANSI_FUNC(normal, NORMAL);
+DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
+DEFINE_ANSI_FUNC(black, BLACK);
+DEFINE_ANSI_FUNC(red, RED);
+DEFINE_ANSI_FUNC(green, GREEN);
+DEFINE_ANSI_FUNC(yellow, YELLOW);
+DEFINE_ANSI_FUNC(blue, BLUE);
+DEFINE_ANSI_FUNC(magenta, MAGENTA);
+DEFINE_ANSI_FUNC(cyan, CYAN);
+DEFINE_ANSI_FUNC(white, WHITE);
+DEFINE_ANSI_FUNC_256(grey, GREY, BRIGHT_BLACK);
+
+DEFINE_ANSI_FUNC(bright_black, BRIGHT_BLACK);
+DEFINE_ANSI_FUNC(bright_red, BRIGHT_RED);
+DEFINE_ANSI_FUNC(bright_green, BRIGHT_GREEN);
+DEFINE_ANSI_FUNC(bright_yellow, BRIGHT_YELLOW);
+DEFINE_ANSI_FUNC(bright_blue, BRIGHT_BLUE);
+DEFINE_ANSI_FUNC(bright_magenta, BRIGHT_MAGENTA);
+DEFINE_ANSI_FUNC(bright_cyan, BRIGHT_CYAN);
+DEFINE_ANSI_FUNC(bright_white, BRIGHT_WHITE);
+
+DEFINE_ANSI_FUNC(highlight_black, HIGHLIGHT_BLACK);
+DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
+DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
+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_magenta, HIGHLIGHT_MAGENTA);
+DEFINE_ANSI_FUNC(highlight_cyan, HIGHLIGHT_CYAN);
+DEFINE_ANSI_FUNC_256(highlight_grey, HIGHLIGHT_GREY, HIGHLIGHT_GREY_FALLBACK);
+DEFINE_ANSI_FUNC(highlight_white, HIGHLIGHT_WHITE);
+
+static inline const char* _ansi_highlight_yellow(void) {
+ return colors_enabled() ? _ANSI_HIGHLIGHT_YELLOW : "";
+}
+
+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);
+DEFINE_ANSI_FUNC_UNDERLINE(highlight_green_underline, HIGHLIGHT_GREEN);
+DEFINE_ANSI_FUNC_UNDERLINE_256(highlight_yellow_underline, HIGHLIGHT_YELLOW, HIGHLIGHT_YELLOW_FALLBACK);
+DEFINE_ANSI_FUNC_UNDERLINE(highlight_blue_underline, HIGHLIGHT_BLUE);
+DEFINE_ANSI_FUNC_UNDERLINE(highlight_magenta_underline, HIGHLIGHT_MAGENTA);
+DEFINE_ANSI_FUNC_UNDERLINE_256(highlight_grey_underline, HIGHLIGHT_GREY, HIGHLIGHT_GREY_FALLBACK);
+
+static inline const char* ansi_highlight_green_red(bool b) {
+ return b ? ansi_highlight_green() : ansi_highlight_red();
+}
diff --git a/src/basic/build.c b/src/basic/build.c
index 488ed20713..50e975e80d 100644
--- a/src/basic/build.c
+++ b/src/basic/build.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "build.h"
#include "extract-word.h"
#include "macro.h"
diff --git a/src/basic/log.c b/src/basic/log.c
index 50b405b843..a8056d2635 100644
--- a/src/basic/log.c
+++ b/src/basic/log.c
@@ -16,6 +16,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "argv-util.h"
#include "env-util.h"
#include "errno-util.h"
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index 698d39d180..ffd687c898 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -21,6 +21,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "constants.h"
#include "devnum-util.h"
#include "env-util.h"
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index f03e3985c6..16f749f75c 100644
--- a/src/basic/terminal-util.h
+++ b/src/basic/terminal-util.h
@@ -11,72 +11,6 @@
#include "macro.h"
#include "time-util.h"
-/* Regular colors */
-#define ANSI_BLACK "\x1B[0;30m" /* Some type of grey usually. */
-#define ANSI_RED "\x1B[0;31m"
-#define ANSI_GREEN "\x1B[0;32m"
-#define ANSI_YELLOW "\x1B[0;33m"
-#define ANSI_BLUE "\x1B[0;34m"
-#define ANSI_MAGENTA "\x1B[0;35m"
-#define ANSI_CYAN "\x1B[0;36m"
-#define ANSI_WHITE "\x1B[0;37m" /* This is actually rendered as light grey, legible even on a white
- * background. See ANSI_HIGHLIGHT_WHITE for real white. */
-
-#define ANSI_BRIGHT_BLACK "\x1B[0;90m"
-#define ANSI_BRIGHT_RED "\x1B[0;91m"
-#define ANSI_BRIGHT_GREEN "\x1B[0;92m"
-#define ANSI_BRIGHT_YELLOW "\x1B[0;93m"
-#define ANSI_BRIGHT_BLUE "\x1B[0;94m"
-#define ANSI_BRIGHT_MAGENTA "\x1B[0;95m"
-#define ANSI_BRIGHT_CYAN "\x1B[0;96m"
-#define ANSI_BRIGHT_WHITE "\x1B[0;97m"
-
-#define ANSI_GREY "\x1B[0;38;5;245m"
-
-/* Bold/highlighted */
-#define ANSI_HIGHLIGHT_BLACK "\x1B[0;1;30m"
-#define ANSI_HIGHLIGHT_RED "\x1B[0;1;31m"
-#define ANSI_HIGHLIGHT_GREEN "\x1B[0;1;32m"
-#define _ANSI_HIGHLIGHT_YELLOW "\x1B[0;1;33m" /* This yellow is currently not displayed well by some terminals */
-#define ANSI_HIGHLIGHT_BLUE "\x1B[0;1;34m"
-#define ANSI_HIGHLIGHT_MAGENTA "\x1B[0;1;35m"
-#define ANSI_HIGHLIGHT_CYAN "\x1B[0;1;36m"
-#define ANSI_HIGHLIGHT_WHITE "\x1B[0;1;37m"
-#define ANSI_HIGHLIGHT_YELLOW4 "\x1B[0;1;38:5:100m"
-#define ANSI_HIGHLIGHT_KHAKI3 "\x1B[0;1;38:5:185m"
-#define ANSI_HIGHLIGHT_GREY "\x1B[0;1;38:5:245m"
-
-#define ANSI_HIGHLIGHT_YELLOW ANSI_HIGHLIGHT_KHAKI3 /* Replacement yellow that is more legible */
-
-/* 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"
-#define ANSI_HIGHLIGHT_BLUE_UNDERLINE "\x1B[0;1;4;34m"
-#define ANSI_HIGHLIGHT_MAGENTA_UNDERLINE "\x1B[0;1;4;35m"
-#define ANSI_HIGHLIGHT_GREY_UNDERLINE "\x1B[0;1;4;38:5:245m"
-
-/* 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"
-
-/* Fallback colors: 256 -> 16 */
-#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"
-
-/* Background colors */
-#define ANSI_BACKGROUND_BLUE "\x1B[44m"
-
-/* Reset/clear ANSI styles */
-#define ANSI_NORMAL "\x1B[0m"
-
/* Erase characters until the end of the line */
#define ANSI_ERASE_TO_END_OF_LINE "\x1B[K"
@@ -176,94 +110,6 @@ static inline bool colors_enabled(void) {
return get_color_mode() != COLOR_OFF;
}
-#define DEFINE_ANSI_FUNC(name, NAME) \
- static inline const char *ansi_##name(void) { \
- return colors_enabled() ? ANSI_##NAME : ""; \
- }
-
-#define DEFINE_ANSI_FUNC_256(name, NAME, FALLBACK) \
- static inline const char *ansi_##name(void) { \
- switch (get_color_mode()) { \
- case COLOR_OFF: return ""; \
- case COLOR_16: return ANSI_##FALLBACK; \
- default : return ANSI_##NAME; \
- } \
- }
-
-static inline const char* ansi_underline(void) {
- return underline_enabled() ? ANSI_UNDERLINE : "";
-}
-
-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 : \
- colors_enabled() ? ANSI_##NAME : ""; \
- }
-
-
-#define DEFINE_ANSI_FUNC_UNDERLINE_256(name, NAME, FALLBACK) \
- static inline const char *ansi_##name(void) { \
- switch (get_color_mode()) { \
- case COLOR_OFF: return ""; \
- case COLOR_16: return underline_enabled() ? ANSI_##FALLBACK##_UNDERLINE : ANSI_##FALLBACK; \
- default : return underline_enabled() ? ANSI_##NAME##_UNDERLINE: ANSI_##NAME; \
- } \
- }
-
-DEFINE_ANSI_FUNC(normal, NORMAL);
-DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
-DEFINE_ANSI_FUNC(black, BLACK);
-DEFINE_ANSI_FUNC(red, RED);
-DEFINE_ANSI_FUNC(green, GREEN);
-DEFINE_ANSI_FUNC(yellow, YELLOW);
-DEFINE_ANSI_FUNC(blue, BLUE);
-DEFINE_ANSI_FUNC(magenta, MAGENTA);
-DEFINE_ANSI_FUNC(cyan, CYAN);
-DEFINE_ANSI_FUNC(white, WHITE);
-DEFINE_ANSI_FUNC_256(grey, GREY, BRIGHT_BLACK);
-
-DEFINE_ANSI_FUNC(bright_black, BRIGHT_BLACK);
-DEFINE_ANSI_FUNC(bright_red, BRIGHT_RED);
-DEFINE_ANSI_FUNC(bright_green, BRIGHT_GREEN);
-DEFINE_ANSI_FUNC(bright_yellow, BRIGHT_YELLOW);
-DEFINE_ANSI_FUNC(bright_blue, BRIGHT_BLUE);
-DEFINE_ANSI_FUNC(bright_magenta, BRIGHT_MAGENTA);
-DEFINE_ANSI_FUNC(bright_cyan, BRIGHT_CYAN);
-DEFINE_ANSI_FUNC(bright_white, BRIGHT_WHITE);
-
-DEFINE_ANSI_FUNC(highlight_black, HIGHLIGHT_BLACK);
-DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
-DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
-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_magenta, HIGHLIGHT_MAGENTA);
-DEFINE_ANSI_FUNC(highlight_cyan, HIGHLIGHT_CYAN);
-DEFINE_ANSI_FUNC_256(highlight_grey, HIGHLIGHT_GREY, HIGHLIGHT_GREY_FALLBACK);
-DEFINE_ANSI_FUNC(highlight_white, HIGHLIGHT_WHITE);
-
-static inline const char* _ansi_highlight_yellow(void) {
- return colors_enabled() ? _ANSI_HIGHLIGHT_YELLOW : "";
-}
-
-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);
-DEFINE_ANSI_FUNC_UNDERLINE(highlight_green_underline, HIGHLIGHT_GREEN);
-DEFINE_ANSI_FUNC_UNDERLINE_256(highlight_yellow_underline, HIGHLIGHT_YELLOW, HIGHLIGHT_YELLOW_FALLBACK);
-DEFINE_ANSI_FUNC_UNDERLINE(highlight_blue_underline, HIGHLIGHT_BLUE);
-DEFINE_ANSI_FUNC_UNDERLINE(highlight_magenta_underline, HIGHLIGHT_MAGENTA);
-DEFINE_ANSI_FUNC_UNDERLINE_256(highlight_grey_underline, HIGHLIGHT_GREY, HIGHLIGHT_GREY_FALLBACK);
-
int get_ctty_devnr(pid_t pid, dev_t *ret);
int get_ctty(pid_t, dev_t *ret_devnr, char **ret);
@@ -281,10 +127,6 @@ int vt_release(int fd, bool restore_vt);
void get_log_colors(int priority, const char **on, const char **off, const char **highlight);
-static inline const char* ansi_highlight_green_red(bool b) {
- return b ? ansi_highlight_green() : ansi_highlight_red();
-}
-
/* This assumes there is a 'tty' group */
#define TTY_MODE 0620
diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c
index dbda6e5457..75c26df52f 100644
--- a/src/core/emergency-action.c
+++ b/src/core/emergency-action.c
@@ -2,6 +2,7 @@
#include <sys/reboot.h>
+#include "ansi-color.h"
#include "bus-error.h"
#include "bus-util.h"
#include "emergency-action.h"
diff --git a/src/core/job.c b/src/core/job.c
index a877f9f06f..21083497c0 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -6,6 +6,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "async.h"
#include "cgroup.h"
#include "dbus-job.h"
diff --git a/src/core/transaction.c b/src/core/transaction.c
index ab6e699d33..9d48768d87 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -4,6 +4,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "dbus-unit.h"
diff --git a/src/core/unit.c b/src/core/unit.c
index c281a29391..2d750b7ef4 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -10,6 +10,7 @@
#include "all-units.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "bpf-firewall.h"
#include "bpf-foreign.h"
#include "bpf-socket-bind.h"
diff --git a/src/cryptenroll/cryptenroll-recovery.c b/src/cryptenroll/cryptenroll-recovery.c
index c4bf1fab95..0b1e380e06 100644
--- a/src/cryptenroll/cryptenroll-recovery.c
+++ b/src/cryptenroll/cryptenroll-recovery.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "cryptenroll-recovery.h"
#include "glyph-util.h"
#include "json-util.h"
diff --git a/src/home/homectl-recovery-key.c b/src/home/homectl-recovery-key.c
index 015d265435..b5c57e14a8 100644
--- a/src/home/homectl-recovery-key.c
+++ b/src/home/homectl-recovery-key.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "errno-util.h"
#include "glyph-util.h"
#include "homectl-recovery-key.h"
diff --git a/src/import/export.c b/src/import/export.c
index cdb1d6246a..1e82e84d7d 100644
--- a/src/import/export.c
+++ b/src/import/export.c
@@ -7,6 +7,7 @@
#include "sd-id128.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "build.h"
#include "discover-image.h"
#include "export-raw.h"
diff --git a/src/import/import-fs.c b/src/import/import-fs.c
index 44fc5be8a5..e74d36288a 100644
--- a/src/import/import-fs.c
+++ b/src/import/import-fs.c
@@ -4,6 +4,7 @@
#include <locale.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "build.h"
#include "btrfs-util.h"
#include "discover-image.h"
diff --git a/src/import/import.c b/src/import/import.c
index 889cd63ff0..97db0b836a 100644
--- a/src/import/import.c
+++ b/src/import/import.c
@@ -7,6 +7,7 @@
#include "sd-id128.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "build.h"
#include "discover-image.h"
#include "env-util.h"
diff --git a/src/import/pull.c b/src/import/pull.c
index 7c838a5307..46055ce5e7 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -7,6 +7,7 @@
#include "sd-id128.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "build.h"
#include "discover-image.h"
#include "env-util.h"
diff --git a/src/journal/journalctl-authenticate.c b/src/journal/journalctl-authenticate.c
index 10630f5e6c..8167aef7f5 100644
--- a/src/journal/journalctl-authenticate.c
+++ b/src/journal/journalctl-authenticate.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "chattr-util.h"
#include "errno-util.h"
#include "fd-util.h"
diff --git a/src/journal/journalctl-show.c b/src/journal/journalctl-show.c
index e8ffc72bb8..9f07facad4 100644
--- a/src/journal/journalctl-show.c
+++ b/src/journal/journalctl-show.c
@@ -4,6 +4,7 @@
#include "sd-event.h"
+#include "ansi-color.h"
#include "fileio.h"
#include "journalctl.h"
#include "journalctl-filter.h"
diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c
index aa46fec91b..5fc3614afb 100644
--- a/src/libsystemd/sd-bus/bus-dump.c
+++ b/src/libsystemd/sd-bus/bus-dump.c
@@ -3,6 +3,7 @@
#include <sys/time.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "bus-dump.h"
#include "bus-internal.h"
#include "bus-message.h"
diff --git a/src/libsystemd/sd-journal/journal-verify.c b/src/libsystemd/sd-journal/journal-verify.c
index e852591a89..0fb93340a6 100644
--- a/src/libsystemd/sd-journal/journal-verify.c
+++ b/src/libsystemd/sd-journal/journal-verify.c
@@ -6,6 +6,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "compress.h"
#include "fd-util.h"
#include "fileio.h"
diff --git a/src/libsystemd/sd-journal/test-journal-verify.c b/src/libsystemd/sd-journal/test-journal-verify.c
index 396ebe192c..dde40bf377 100644
--- a/src/libsystemd/sd-journal/test-journal-verify.c
+++ b/src/libsystemd/sd-journal/test-journal-verify.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <unistd.h>
+#include "ansi-color.h"
#include "chattr-util.h"
#include "fd-util.h"
#include "iovec-util.h"
diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c
index 2219bf26cc..98ffe4db54 100644
--- a/src/libsystemd/sd-json/sd-json.c
+++ b/src/libsystemd/sd-json/sd-json.c
@@ -10,6 +10,7 @@
#include "sd-messages.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "errno-util.h"
#include "escape.h"
#include "ether-addr-util.h"
diff --git a/src/libsystemd/sd-varlink/sd-varlink-idl.c b/src/libsystemd/sd-varlink/sd-varlink-idl.c
index 181e6c193d..76a2499561 100644
--- a/src/libsystemd/sd-varlink/sd-varlink-idl.c
+++ b/src/libsystemd/sd-varlink/sd-varlink-idl.c
@@ -2,6 +2,7 @@
#include "sd-varlink-idl.h"
+#include "ansi-color.h"
#include "json-util.h"
#include "memstream-util.h"
#include "set.h"
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index bf79dc2633..778b31274d 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -19,6 +19,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "ask-password-api.h"
#include "creds-util.h"
#include "fd-util.h"
diff --git a/src/shared/blockdev-list.c b/src/shared/blockdev-list.c
index 2e6ed362f2..120f7201df 100644
--- a/src/shared/blockdev-list.c
+++ b/src/shared/blockdev-list.c
@@ -2,6 +2,7 @@
#include "sd-device.h"
+#include "ansi-color.h"
#include "blockdev-list.h"
#include "blockdev-util.h"
#include "device-util.h"
diff --git a/src/shared/bus-unit-procs.c b/src/shared/bus-unit-procs.c
index 8b462b5627..4d6f2be3c4 100644
--- a/src/shared/bus-unit-procs.c
+++ b/src/shared/bus-unit-procs.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "bus-locator.h"
#include "bus-unit-procs.h"
#include "glyph-util.h"
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 87177316da..33fe222730 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -7,6 +7,7 @@
#include <stdlib.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "bus-error.h"
#include "bus-util.h"
#include "cgroup-show.h"
diff --git a/src/shared/pretty-print.h b/src/shared/pretty-print.h
index 9eb1611905..2c97c354ef 100644
--- a/src/shared/pretty-print.h
+++ b/src/shared/pretty-print.h
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include "ansi-color.h"
#include "glyph-util.h"
#include "terminal-util.h"
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index 83eef7f7d8..3e11ba456f 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -17,6 +17,7 @@
#include "sd-event.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "env-util.h"
#include "errno-util.h"
#include "extract-word.h"
diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c
index 10ed542df2..36cd5dcd7c 100644
--- a/src/shared/qrcode-util.c
+++ b/src/shared/qrcode-util.c
@@ -5,6 +5,7 @@
#if HAVE_QRENCODE
#include <qrencode.h>
+#include "ansi-color.h"
#include "dlfcn-util.h"
#include "locale-util.h"
#include "log.h"
diff --git a/src/systemctl/systemctl-list-dependencies.c b/src/systemctl/systemctl-list-dependencies.c
index a9121f1035..3df9b7abdf 100644
--- a/src/systemctl/systemctl-list-dependencies.c
+++ b/src/systemctl/systemctl-list-dependencies.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "locale-util.h"
#include "sort-util.h"
#include "special.h"
diff --git a/src/systemctl/systemctl-list-jobs.c b/src/systemctl/systemctl-list-jobs.c
index fcfe2ac561..2fecf61317 100644
--- a/src/systemctl/systemctl-list-jobs.c
+++ b/src/systemctl/systemctl-list-jobs.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "locale-util.h"
diff --git a/src/systemctl/systemctl-list-machines.c b/src/systemctl/systemctl-list-machines.c
index 4407d2598a..1fffceb38e 100644
--- a/src/systemctl/systemctl-list-machines.c
+++ b/src/systemctl/systemctl-list-machines.c
@@ -4,6 +4,7 @@
#include "sd-login.h"
+#include "ansi-color.h"
#include "bus-map-properties.h"
#include "hostname-util.h"
#include "locale-util.h"
diff --git a/src/systemctl/systemctl-list-unit-files.c b/src/systemctl/systemctl-list-unit-files.c
index 943d7ffec5..975b3ebc54 100644
--- a/src/systemctl/systemctl-list-unit-files.c
+++ b/src/systemctl/systemctl-list-unit-files.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "sort-util.h"
diff --git a/src/systemctl/systemctl-list-units.c b/src/systemctl/systemctl-list-units.c
index 184468ed61..b4ccc8ebd7 100644
--- a/src/systemctl/systemctl-list-units.c
+++ b/src/systemctl/systemctl-list-units.c
@@ -2,6 +2,7 @@
#include "sd-login.h"
+#include "ansi-color.h"
#include "bus-error.h"
#include "bus-locator.h"
#include "format-table.h"
diff --git a/src/systemctl/systemctl-start-unit.c b/src/systemctl/systemctl-start-unit.c
index 8068d77d1c..909f051cde 100644
--- a/src/systemctl/systemctl-start-unit.c
+++ b/src/systemctl/systemctl-start-unit.c
@@ -2,6 +2,7 @@
#include "sd-bus.h"
+#include "ansi-color.h"
#include "bus-common-errors.h"
#include "bus-error.h"
#include "bus-locator.h"
diff --git a/src/sysupdate/sysupdate-update-set-flags.c b/src/sysupdate/sysupdate-update-set-flags.c
index 66b3d340bb..d9232e4a17 100644
--- a/src/sysupdate/sysupdate-update-set-flags.c
+++ b/src/sysupdate/sysupdate-update-set-flags.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "glyph-util.h"
#include "sysupdate-update-set-flags.h"
#include "terminal-util.h"
diff --git a/src/sysupdate/sysupdate-update-set.c b/src/sysupdate/sysupdate-update-set.c
index 53bcc5d965..0756dff04b 100644
--- a/src/sysupdate/sysupdate-update-set.c
+++ b/src/sysupdate/sysupdate-update-set.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include "ansi-color.h"
#include "alloc-util.h"
#include "string-util.h"
#include "sysupdate-update-set.h"
diff --git a/src/test/test-ellipsize.c b/src/test/test-ellipsize.c
index f1814768fd..d70b727cee 100644
--- a/src/test/test-ellipsize.c
+++ b/src/test/test-ellipsize.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "constants.h"
#include "escape.h"
#include "string-util.h"
diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c
index fdd590107e..e7cfeab6d0 100644
--- a/src/test/test-terminal-util.c
+++ b/src/test/test-terminal-util.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include "alloc-util.h"
+#include "ansi-color.h"
#include "fd-util.h"
#include "fs-util.h"
#include "macro.h"
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 1d105047c9..2cdc3bd305 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -13,6 +13,7 @@
#include "sd-json.h"
#include "alloc-util.h"
+#include "ansi-color.h"
#include "device-enumerator-private.h"
#include "device-private.h"
#include "device-util.h"
diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c
index c8c23e811a..ff4625c3be 100644
--- a/src/udev/udevadm-test.c
+++ b/src/udev/udevadm-test.c
@@ -14,6 +14,7 @@
#include "sd-device.h"
+#include "ansi-color.h"
#include "device-private.h"
#include "device-util.h"
#include "format-util.h"