X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/bc8ffafeb9bb5b272e118400df55157db41ad897..4eddb121563a9e50cf2ee66e2a0ff7c186dd696a:/deps/linenoise/linenoise.c diff --git a/deps/linenoise/linenoise.c b/deps/linenoise/linenoise.c index dd434136..18a15cc4 100644 --- a/deps/linenoise/linenoise.c +++ b/deps/linenoise/linenoise.c @@ -279,7 +279,9 @@ static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, si } void linenoiseClearScreen(void) { - write(STDIN_FILENO,"\x1b[H\x1b[2J",7); + if (write(STDIN_FILENO,"\x1b[H\x1b[2J",7) <= 0) { + /* nothing to do, just to avoid warning. */ + } } static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt) { @@ -318,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; @@ -335,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];