mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-04 02:50:58 +02:00
Merge branch 'fix/linenoise-arrow-usage_v5.4' into 'release/v5.4'
fix(linenoise): Read escape sequences one character at a time (v5.4) See merge request espressif/esp-idf!40691
This commit is contained in:
@@ -885,7 +885,6 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
|||||||
while(1) {
|
while(1) {
|
||||||
char c;
|
char c;
|
||||||
int nread;
|
int nread;
|
||||||
char seq[3];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To determine whether the user is pasting data or typing itself, we
|
* To determine whether the user is pasting data or typing itself, we
|
||||||
@@ -974,14 +973,18 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
|||||||
case CTRL_N: /* ctrl-n */
|
case CTRL_N: /* ctrl-n */
|
||||||
linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
|
linenoiseEditHistoryNext(&l, LINENOISE_HISTORY_NEXT);
|
||||||
break;
|
break;
|
||||||
case ESC: /* escape sequence */
|
case ESC: { /* escape sequence */
|
||||||
/* Read the next two bytes representing the escape sequence. */
|
char seq[3];
|
||||||
if (read(in_fd, seq, 2) < 2) {
|
int r = read(in_fd, seq, 1);
|
||||||
break;
|
if (r != 1) {
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ESC [ sequences. */
|
/* ESC [ sequences. */
|
||||||
if (seq[0] == '[') {
|
if (seq[0] == '[') {
|
||||||
|
int r = read(in_fd, seq + 1, 1);
|
||||||
|
if (r != 1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (seq[1] >= '0' && seq[1] <= '9') {
|
if (seq[1] >= '0' && seq[1] <= '9') {
|
||||||
/* Extended escape, read additional byte. */
|
/* Extended escape, read additional byte. */
|
||||||
if (read(in_fd, seq+2, 1) == -1) {
|
if (read(in_fd, seq+2, 1) == -1) {
|
||||||
@@ -1020,6 +1023,10 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
|||||||
|
|
||||||
/* ESC O sequences. */
|
/* ESC O sequences. */
|
||||||
else if (seq[0] == 'O') {
|
else if (seq[0] == 'O') {
|
||||||
|
int r = read(in_fd, seq + 1, 1);
|
||||||
|
if (r != 1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
switch(seq[1]) {
|
switch(seq[1]) {
|
||||||
case 'H': /* Home */
|
case 'H': /* Home */
|
||||||
linenoiseEditMoveHome(&l);
|
linenoiseEditMoveHome(&l);
|
||||||
@@ -1030,6 +1037,7 @@ static int linenoiseEdit(char *buf, size_t buflen, const char *prompt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
if (linenoiseEditInsert(&l,c)) return -1;
|
if (linenoiseEditInsert(&l,c)) return -1;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user