| Date: Thu, 31 Aug 2017 18:31:52 +0200
Fix uiprompt to return NULL on error (cancelation)
Thanks to solene for spotting this!
Diffstat:
M ui_ti.c | 6 ++++--
M ui_txt.c | 7 +++++--
2 files changed, 9 insertions(+), 4 deletions(-)
--- |
| @@ -74,10 +74,12 @@ uiprompt(char *fmt, ...)
putp(tparm(restore_cursor));
fflush(stdout);
- if (r < 0)
+ if (r < 0) {
clearerr(stdin);
- else if (input[r - 1] == '\n')
+ clear(&input);
+ } else if (input[r - 1] == '\n') {
input[--r] = '\0';
+ }
return input;
} |
| @@ -99,10 +99,13 @@ uiprompt(char *fmt, ...)
fflush(stdout);
- if ((r = getline(&input, &n, stdin)) < 0)
+ if ((r = getline(&input, &n, stdin)) < 0) {
clearerr(stdin);
- else if (input[r - 1] == '\n')
+ clear(&input);
+ putchar('\n');
+ } else if (input[r - 1] == '\n') {
input[--r] = '\0';
+ }
return input;
} |