support for delete key, thanks to jgriffiths (on github)
diff --git a/linenoise.c b/linenoise.c
index b7c6b73..045862e 100644
--- a/linenoise.c
+++ b/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 @@ up_down_arrow:
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: