From: antirez Date: Tue, 22 Feb 2011 16:38:49 +0000 (+0100) Subject: Support for ctrl-d deleting the char at right of the cursor added X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=6cdc775807e57b2c3fd64bd207814f8ee1fe35f3;p=linenoise.git Support for ctrl-d deleting the char at right of the cursor added --- diff --git a/linenoise.c b/linenoise.c index bfed5ea..18a15cc 100644 --- a/linenoise.c +++ b/linenoise.c @@ -320,10 +320,9 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) switch(c) { case 13: /* enter */ - case 4: /* ctrl-d */ history_len--; free(history[history_len]); - return (len == 0 && c == 4) ? -1 : (int)len; + return (int)len; case 3: /* ctrl-c */ errno = EAGAIN; return -1; @@ -337,6 +336,18 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) refreshLine(fd,prompt,buf,len,pos,cols); } break; + case 4: /* ctrl-d, remove char at right of cursor */ + if (len > 1 && pos < (len-1)) { + memmove(buf+pos,buf+pos+1,len-pos); + len--; + buf[len] = '\0'; + refreshLine(fd,prompt,buf,len,pos,cols); + } else if (len == 0) { + history_len--; + free(history[history_len]); + return -1; + } + break; case 20: /* ctrl-t */ if (pos > 0 && pos < len) { int aux = buf[pos-1];