summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-09-09 22:48:35 +0200
committerSven Eden <yamakuzure@gmx.net>2017-09-09 22:48:35 +0200
commit351eb5dc200ace8bc0b06fafb99a2934c35058d8 (patch)
tree9a9a648e53284ed8ebccffdf85fe8c81a85e4d5e /src
parentbd4dae01104127b8b92410ea8a126d8d8d0dfcf2 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/basic/terminal-util.c16
-rw-r--r--src/basic/terminal-util.h22
2 files changed, 32 insertions, 6 deletions
diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c
index c81aa400b..6de772117 100644
--- a/src/basic/terminal-util.c
+++ b/src/basic/terminal-util.c
@@ -1241,6 +1241,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;
diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h
index 5d37a4477..f710eac38 100644
--- a/src/basic/terminal-util.h
+++ b/src/basic/terminal-util.h
@@ -100,6 +100,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) { \
@@ -107,19 +108,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);