From 0c8cc0722c0a5eb13ea39aa6ef5c7a80ff16a1bd Mon Sep 17 00:00:00 2001 From: Steve Bennett Date: Wed, 10 Nov 2010 12:02:00 +1000 Subject: Linenoise improvement for ^D Use default readline/bash behaviour of deleting char to the right, unless the line is empty. Then it is EOF. Signed-off-by: Steve Bennett --- linenoise.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'linenoise.c') diff --git a/linenoise.c b/linenoise.c index a2c0255..2c83960 100644 --- a/linenoise.c +++ b/linenoise.c @@ -521,14 +521,23 @@ static int linenoisePrompt(const char *prompt, struct current *current) { process_char: if (c == -1) return current->len; switch(c) { - case ctrl('D'): /* ctrl-d */ case '\r': /* enter */ history_len--; free(history[history_len]); - if (current->len == 0 && c == ctrl('D')) { + return current->len; + + case ctrl('D'): /* ctrl-d */ + if (current->len == 0) { + /* Empty line, so EOF */ + history_len--; + free(history[history_len]); return -1; } - return current->len; + /* Otherwise delete char to right of cursor */ + if (remove_char(current, current->pos)) { + refreshLine(prompt, current); + } + break; case ctrl('C'): /* ctrl-c */ errno = EAGAIN; @@ -594,7 +603,7 @@ process_char: } skipsame = 1; } - else if (c == CTRL('N') || c == SPECIAL_DOWN) { + else if (c == ctrl('N') || c == SPECIAL_DOWN) { /* Search for the next (later) match */ if (searchpos < history_len) { searchpos++; -- cgit v1.1