Commit 778de19a2bd850e57db50b44572118bd2c9403f0

Pieter Noordhuis 2010-11-29T20:35:20

Show original buffer when completion is aborted

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
diff --git a/linenoise.c b/linenoise.c
index 0ebef2e..b6f4d4f 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -243,10 +243,14 @@ static int completeLine(int fd, const char *prompt, char *buf, size_t buflen, si
                     if (i == lc.len) beep();
                     break;
                 case 27: /* escape */
+                    /* Re-show original buffer */
+                    if (i < lc.len) {
+                        refreshLine(fd,prompt,buf,*len,*pos,cols);
+                    }
                     stop = 1;
                     break;
                 default:
-                    /* update buffer and return */
+                    /* Update buffer and return */
                     if (i < lc.len) {
                         nwritten = snprintf(buf,buflen,"%s",lc.cvec[i]);
                         *len = *pos = nwritten;