tools: libinput-record: print a progress bar when recording to a file

To let users know something is happening.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2018-03-15 08:44:19 +10:00
parent 056a5eb64a
commit a1ba6186e7

View file

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