From a1ba6186e70b102344ea6b17696b8ef7002ed6a2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 15 Mar 2018 08:44:19 +1000 Subject: [PATCH] tools: libinput-record: print a progress bar when recording to a file To let users know something is happening. Signed-off-by: Peter Hutterer --- tools/libinput-record.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/libinput-record.c b/tools/libinput-record.c index d8ab4977..21954327 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -1334,6 +1334,19 @@ open_output_file(struct record_context *ctx, bool is_prefix) return true; } +static inline void +print_progress_bar(void) +{ + static uint8_t foo = 0; + + if (!isatty(STDERR_FILENO)) + return; + + if (++foo > 20) + foo = 1; + fprintf(stderr, "\rReceiving events: [%*s%*s]", foo, "*", 21 - foo, " "); +} + static int mainloop(struct record_context *ctx) { @@ -1393,7 +1406,7 @@ mainloop(struct record_context *ctx) ctx->output_file); break; } - fprintf(stderr, "recording to '%s'\n", ctx->output_file); + fprintf(stderr, "Recording to '%s'.\n", ctx->output_file); print_header(ctx); if (autorestart) @@ -1465,6 +1478,9 @@ mainloop(struct record_context *ctx) rc--; } + if (ctx->out_fd != STDOUT_FILENO) + print_progress_bar(); + } indent_pop(ctx); /* events: */