1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

systemctl: don't do ANSI underlining on TERM=linux (#6778)

The linux console apparently can't do underlining, hence let's not do it
on the console.

Also see: #6601
This commit is contained in:
Lennart Poettering 2017-09-09 22:48:35 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent c5aaaebced
commit 526664f627
2 changed files with 32 additions and 6 deletions

View File

@ -1228,6 +1228,22 @@ bool colors_enabled(void) {
return enabled;
}
bool underline_enabled(void) {
static int enabled = -1;
if (enabled < 0) {
/* The Linux console doesn't support underlining, turn it off, but only there. */
if (!colors_enabled())
enabled = false;
else
enabled = !streq_ptr(getenv("TERM"), "linux");
}
return enabled;
}
int vt_default_utf8(void) {
_cleanup_free_ char *b = NULL;
int r;

View File

@ -86,6 +86,7 @@ void columns_lines_cache_reset(int _unused_ signum);
bool on_tty(void);
bool terminal_is_dumb(void);
bool colors_enabled(void);
bool underline_enabled(void);
#define DEFINE_ANSI_FUNC(name, NAME) \
static inline const char *ansi_##name(void) { \
@ -93,19 +94,28 @@ bool colors_enabled(void);
} \
struct __useless_struct_to_allow_trailing_semicolon__
DEFINE_ANSI_FUNC(underline, UNDERLINE);
#define DEFINE_ANSI_FUNC_UNDERLINE(name, NAME, REPLACEMENT) \
static inline const char *ansi_##name(void) { \
return underline_enabled() ? ANSI_##NAME : \
colors_enabled() ? ANSI_##REPLACEMENT : ""; \
} \
struct __useless_struct_to_allow_trailing_semicolon__
DEFINE_ANSI_FUNC(highlight, HIGHLIGHT);
DEFINE_ANSI_FUNC(highlight_underline, HIGHLIGHT_UNDERLINE);
DEFINE_ANSI_FUNC(highlight_red, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC(highlight_green, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC(highlight_yellow, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC(highlight_blue, HIGHLIGHT_BLUE);
DEFINE_ANSI_FUNC(highlight_red_underline, HIGHLIGHT_RED_UNDERLINE);
DEFINE_ANSI_FUNC(highlight_green_underline, HIGHLIGHT_GREEN_UNDERLINE);
DEFINE_ANSI_FUNC(highlight_yellow_underline, HIGHLIGHT_YELLOW_UNDERLINE);
DEFINE_ANSI_FUNC(highlight_blue_underline, HIGHLIGHT_BLUE_UNDERLINE);
DEFINE_ANSI_FUNC(normal, NORMAL);
DEFINE_ANSI_FUNC_UNDERLINE(underline, UNDERLINE, NORMAL);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_underline, HIGHLIGHT_UNDERLINE, HIGHLIGHT);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_red_underline, HIGHLIGHT_RED_UNDERLINE, HIGHLIGHT_RED);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_green_underline, HIGHLIGHT_GREEN_UNDERLINE, HIGHLIGHT_GREEN);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_yellow_underline, HIGHLIGHT_YELLOW_UNDERLINE, HIGHLIGHT_YELLOW);
DEFINE_ANSI_FUNC_UNDERLINE(highlight_blue_underline, HIGHLIGHT_BLUE_UNDERLINE, HIGHLIGHT_BLUE);
int get_ctty_devnr(pid_t pid, dev_t *d);
int get_ctty(pid_t, dev_t *_devnr, char **r);