summaryrefslogtreecommitdiff
path: root/src/basic/terminal-util.c
diff options
context:
space:
mode:
authorJan Synacek <jsynacek@redhat.com>2016-01-19 10:17:19 +0100
committerJan Synacek <jsynacek@redhat.com>2016-01-20 10:12:41 +0100
commit40c9fe4c0862114dab390c8ed16f78cf056b9140 (patch)
tree04bb1f55765a432bb0495963871eaf6dcd10faaf /src/basic/terminal-util.c
parentd619a0c4a5bf4f9d5796bcac77160a14e4e24cb6 (diff)
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.
Diffstat (limited to 'src/basic/terminal-util.c')
-rw-r--r--src/basic/terminal-util.c13
1 files changed, 13 insertions, 0 deletions
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;
+}