Browse files

support for delete key, thanks to jgriffiths (on github)

  • Loading branch information...
1 parent ce84546 commit 7534b88325765ab69dbb91b5a8f55b58e8844ef9 @antirez committed Sep 24, 2010
Showing with 13 additions and 1 deletion.
  1. +13 −1 linenoise.c
View
14 linenoise.c
@@ -213,7 +213,7 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt)
while(1) {
char c;
int nread;
- char seq[2];
+ char seq[2], seq2[2];
nread = read(fd,&c,1);
if (nread <= 0) return len;
@@ -294,6 +294,18 @@ static int linenoisePrompt(int fd, char *buf, size_t buflen, const char *prompt)
len = pos = strlen(buf);
refreshLine(fd,prompt,buf,len,pos,cols);
}
+ } else if (seq[0] == 91 && seq[1] > 48 && seq[1] < 55) {
+ /* extended escape */
+ if (read(fd,seq2,2) == -1) break;
+ if (seq[1] == 51 && seq2[0] == 126) {
+ /* delete */
+ if (len > 0 && pos < len) {
+ memmove(buf+pos,buf+pos+1,len-pos-1);
+ len--;
+ buf[len] = '\0';
+ refreshLine(fd,prompt,buf,len,pos,cols);
+ }
+ }
}
break;
default:

0 comments on commit 7534b88

Please sign in to comment.