Commit a05ab23df6f670303eceabb9f33e205ee3485613

antirez 2014-03-12T23:25:27

Use the two-reads fix for the additional escapes as well. See commit e153bd8 for more information. The gist is that slow terminals may return a short read of 1 byte.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
diff --git a/linenoise.c b/linenoise.c
index 3a4c90b..f0b1c63 100644
--- a/linenoise.c
+++ b/linenoise.c
@@ -754,7 +754,8 @@ static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, 
                                            LINENOISE_HISTORY_NEXT);
             } else if (seq[0] == ARROW_PREFIX && seq[1] > 48 && seq[1] < 55) {
                 /* extended escape, read additional two bytes. */
-                if (read(l.ifd,seq2,2) == -1) break;
+                if (read(l.ifd,seq2,1) == -1) break;
+                if (read(l.ifd,seq2+1,1) == -1) break;
                 if (seq[1] == 51 && seq2[0] == 126) {
                     /* Delete key. */
                     linenoiseEditDelete(&l);