summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorDaniel Schaal <farbing@web.de>2013-08-02 07:59:02 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-08-04 08:33:02 -0400
commit0b5a519c89b5fb48ec7a3cfbd9c02283ae0f23ac (patch)
treef97494aceb6e7feb68c2ef554f4fa59485f6e7f1 /src/shared
parent92d700dea651e2a09ee75c7713b8387f11435cec (diff)
systemd-delta: Only print colors when on a tty
This make systemd-delta follow the behaviour of systemctl and journalctl. https://bugs.freedesktop.org/show_bug.cgi?id=67656 [zj: unify color query methods between those three programs.]
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index ac999c624c..3be692ec33 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -374,6 +374,22 @@ void columns_lines_cache_reset(int _unused_ signum);
bool on_tty(void);
+static inline const char *ansi_highlight(void) {
+ return on_tty() ? ANSI_HIGHLIGHT_ON : "";
+}
+
+static inline const char *ansi_highlight_red(void) {
+ return on_tty() ? ANSI_HIGHLIGHT_RED_ON : "";
+}
+
+static inline const char *ansi_highlight_green(void) {
+ return on_tty() ? ANSI_HIGHLIGHT_GREEN_ON : "";
+}
+
+static inline const char *ansi_highlight_off(void) {
+ return on_tty() ? ANSI_HIGHLIGHT_OFF : "";
+}
+
int running_in_chroot(void);
char *ellipsize(const char *s, size_t length, unsigned percent);