Merge branch 'fix/prompt-erased-by-backspace-in-dumbmode' into 'master'

fix(console): bug where backspace erases the prompt in dumb mode

Closes IDFGH-12508

See merge request espressif/esp-idf!30313
pull/13557/merge
Guillaume Souchere 2024-04-19 17:30:58 +08:00
commit 1b452481b8
1 zmienionych plików z 15 dodań i 6 usunięć

Wyświetl plik

@ -178,6 +178,7 @@ enum KEY_ACTION{
CTRL_U = 21, /* Ctrl+u */
CTRL_W = 23, /* Ctrl+w */
ESC = 27, /* Escape */
UNIT_SEP = 31, /* ctrl-_ */
BACKSPACE = 127 /* Backspace */
};
@ -1131,15 +1132,23 @@ static int linenoiseDumb(char* buf, size_t buflen, const char* prompt) {
int c = fgetc(stdin);
if (c == '\n') {
break;
} else if (c >= 0x1c && c <= 0x1f){
continue; /* consume arrow keys */
} else if (c == BACKSPACE || c == 0x8) {
} else if (c == BACKSPACE || c == CTRL_H) {
if (count > 0) {
buf[count - 1] = 0;
count --;
count--;
/* Only erase symbol echoed from stdin. */
fputs("\x08 ", stdout); /* Windows CMD: erase symbol under cursor */
flushWrite();
} else {
/* Consume backspace if the command line is empty to avoid erasing the prompt */
continue;
}
fputs("\x08 ", stdout); /* Windows CMD: erase symbol under cursor */
flushWrite();
} else if (c <= UNIT_SEP) {
/* Consume all character that are non printable (the backspace
* case is handled above) */
continue;
} else {
buf[count] = c;
++count;