test: add color to litest verbose output

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2017-03-28 11:31:16 +10:00
parent 937541cb82
commit 0bd36f2542
3 changed files with 29 additions and 7 deletions

View file

@ -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
/*

View file

@ -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");

View file

@ -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)