watch: Consume outstanding input before allowing termination due to -e

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Roman Žilka 2023-07-05 16:40:49 +02:00 committed by Craig Small
parent 54c531de6a
commit 1b8626ec54

View File

@ -38,6 +38,7 @@
#include <errno.h>
#include <getopt.h>
#include <locale.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
@ -921,6 +922,12 @@ static bool run_command(const char *command, char *const *restrict command_argv)
if (flags & WATCH_BEEP)
beep();
if (flags & WATCH_ERREXIT) {
int stdinfl = fcntl(0, F_GETFL);
if (stdinfl >= 0 && fcntl(0, F_SETFL, stdinfl|O_NONBLOCK) >= 0) {
while (getchar() != EOF) ;
fcntl(0, F_SETFL, stdinfl);
}
// TODO: add a few spaces to the end of the string to separate it
// from the cmd output that may already be on the line
mvaddstr(height - 1, 0,