commit 7effd7e7013dd385bf4cd6d4fbaea28475ab4886
parent 0408127d9db566364530dc8690081a9c3d133bca
Author: Tom Schwindl <schwindl@posteo.de>
Date: Mon, 22 Aug 2022 22:28:37 +0200
lchat: flush earlier to make sure the initial prompt is displayed
The first fflush(3) occurs when the first character is read. In case we
need to wait a bit longer for this to happen, the initial prompt isn't
printed immediately and the program looks like it hung up.
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lchat.c b/lchat.c
@@ -335,6 +335,9 @@ main(int argc, char *argv[])
fputs(prompt, stdout);
for (;;) {
+ if (fflush(stdout) == EOF)
+ err(EXIT_FAILURE, "fflush");
+
errno = 0;
if (poll(pfd, nfds, INFTIM) == -1 && errno != EINTR)
err(EXIT_FAILURE, "poll");
@@ -445,9 +448,6 @@ main(int argc, char *argv[])
if (sl->rcur + prompt_len > 0)
printf("\033[%zuC", sl->rcur + prompt_len);
}
-
- if (fflush(stdout) == EOF)
- err(EXIT_FAILURE, "fflush");
}
return EXIT_SUCCESS;
}