Ctrl-D exits when line is empty.

This commit is contained in:
Bruce Hill 2019-09-22 16:07:28 -07:00
parent 5d3344815d
commit 8e5b1497fa

6
ask.c
View File

@ -231,6 +231,7 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init
case '\r':
goto finished;
case KEY_CTRL_C: case KEY_ESC:
cleanup:
free(buf);
buf = NULL;
picked = NULL;
@ -283,7 +284,10 @@ static char *get_input(FILE *in, FILE *out, const char *prompt, const char *init
buf[--len] = 0;
}
break;
case KEY_DELETE: case KEY_CTRL_D:
case KEY_CTRL_D:
if (len == 0) goto cleanup;
// fallthrough
case KEY_DELETE:
if (b < len) {
memmove(buf+b, buf+b+1, (size_t)(len-b));
buf[--len] = 0;