From 0bd36f25422a0a40d1eeededabfe9f434e164c06 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 28 Mar 2017 11:31:16 +1000 Subject: [PATCH] test: add color to litest verbose output Signed-off-by: Peter Hutterer --- src/libinput-util.h | 4 ++++ test/litest.c | 29 +++++++++++++++++++++++++---- tools/shared.c | 3 --- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/libinput-util.h b/src/libinput-util.h index d86ff123..73af6898 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -53,6 +53,10 @@ /* The HW DPI rate we normalize to before calculating pointer acceleration */ #define DEFAULT_MOUSE_DPI 1000 +#define ANSI_HIGHLIGHT "\x1B[0;1;39m" +#define ANSI_RED "\x1B[0;31m" +#define ANSI_NORMAL "\x1B[0m" + #define CASE_RETURN_STRING(a) case a: return #a /* diff --git a/test/litest.c b/test/litest.c index f9797b7b..d91a5242 100644 --- a/test/litest.c +++ b/test/litest.c @@ -785,19 +785,40 @@ litest_log_handler(struct libinput *libinput, const char *format, va_list args) { + static int is_tty = -1; const char *priority = NULL; + const char *color; + + if (is_tty == -1) + is_tty = isatty(STDERR_FILENO); switch(pri) { - case LIBINPUT_LOG_PRIORITY_INFO: priority = "info "; break; - case LIBINPUT_LOG_PRIORITY_ERROR: priority = "error"; break; - case LIBINPUT_LOG_PRIORITY_DEBUG: priority = "debug"; break; + case LIBINPUT_LOG_PRIORITY_INFO: + priority = "info "; + color = ANSI_HIGHLIGHT; + break; + case LIBINPUT_LOG_PRIORITY_ERROR: + priority = "error"; + color = ANSI_RED; + break; + case LIBINPUT_LOG_PRIORITY_DEBUG: + priority = "debug"; + color = ANSI_NORMAL; + break; default: abort(); } - fprintf(stderr, "litest %s ", priority); + if (!is_tty) + color = ""; + + fprintf(stderr, "%slitest %s ", color, priority); + vfprintf(stderr, format, args); + if (is_tty) + fprintf(stderr, ANSI_NORMAL); + if (strstr(format, "client bug: ") || strstr(format, "libinput bug: ")) litest_abort_msg("libinput bug triggered, aborting.\n"); diff --git a/tools/shared.c b/tools/shared.c index c4f19f83..830e0cb4 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -73,9 +73,6 @@ log_handler(struct libinput *li, const char *format, va_list args) { -#define ANSI_HIGHLIGHT "\x1B[0;1;39m" -#define ANSI_RED "\x1B[0;31m" -#define ANSI_NORMAL "\x1B[0m" static int is_tty = -1; if (is_tty == -1)