From e8d24f818be5c3e4b9616ce310cc4cafeb1707b0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 28 Jul 2025 09:29:31 +1000 Subject: [PATCH] util: add two macros for clearing a line Part-of: --- src/util-macros.h | 3 +++ tools/libinput-debug-tablet.c | 14 +++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/util-macros.h b/src/util-macros.h index 8f7e32ac..268a15fe 100644 --- a/src/util-macros.h +++ b/src/util-macros.h @@ -98,6 +98,9 @@ #define ANSI_RGB(r, g, b) "\x1B[38;2;" #r ";" #g ";" #b "m" #define ANSI_RGB_BG(r, g, b) "\x1B[48;2;" #r ";" #g ";" #b "m" +#define ANSI_CLEAR_LINE "\x1B[2K" +#define ANSI_CLEAR_EOL "\x1B[0K" + #define CASE_RETURN_STRING(a) case a: return #a /** diff --git a/tools/libinput-debug-tablet.c b/tools/libinput-debug-tablet.c index c5089df0..0d478751 100644 --- a/tools/libinput-debug-tablet.c +++ b/tools/libinput-debug-tablet.c @@ -78,18 +78,14 @@ LIBINPUT_ATTRIBUTE_PRINTF(1, 2) static void print_line(const char *format, ...) { - char empty[] = - " "; - const int width = 80; - int n; + char buf[256]; + va_list args; - - printf("\r"); - va_start(args, format); - n = vprintf(format, args); + vsnprintf(buf, sizeof(buf), format, args); va_end(args); - printf("%.*s\n", width - n, empty); + + printf(ANSI_CLEAR_LINE "%s\n", buf); } static void