From 0b5a519c89b5fb48ec7a3cfbd9c02283ae0f23ac Mon Sep 17 00:00:00 2001 From: Daniel Schaal Date: Fri, 2 Aug 2013 07:59:02 +0200 Subject: 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.] --- src/shared/util.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/shared') 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); -- cgit v1.2.3-54-g00ecf