From 40c9fe4c0862114dab390c8ed16f78cf056b9140 Mon Sep 17 00:00:00 2001 From: Jan Synacek Date: Tue, 19 Jan 2016 10:17:19 +0100 Subject: basic/terminal-util: introduce SYSTEMD_COLORS environment variable ... to determine if color output should be enabled. If the variable is not set, fall back to using on_tty(). Also, rewrite existing code to use colors_enabled() where appropriate. --- src/basic/terminal-util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/basic/terminal-util.c') diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7c9de72bb7..fedfc8a5df 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1135,3 +1135,16 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) { return receive_one_fd(pair[0], 0); } + +bool colors_enabled(void) { + const char *colors; + + colors = getenv("SYSTEMD_COLORS"); + if (!colors) { + if (streq_ptr(getenv("TERM"), "dumb")) + return false; + return on_tty(); + } + + return parse_boolean(colors) != 0; +} -- cgit v1.2.3-54-g00ecf