Skip to content

Commit

Permalink
Merge branch 'fix/prompt-erased-by-backspace-in-dumbmode_v5.2' into '…
Browse files Browse the repository at this point in the history
…release/v5.2'

fix(console): bug where backspace erases the prompt in dumb mode (backport v5.2)

See merge request espressif/esp-idf!30348
  • Loading branch information
ESP-Marius committed Jun 26, 2024
2 parents 99df25b + 302881e commit 293f868
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions components/console/linenoise/linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ enum KEY_ACTION{
CTRL_U = 21, /* Ctrl+u */
CTRL_W = 23, /* Ctrl+w */
ESC = 27, /* Escape */
UNIT_SEP = 31, /* ctrl-_ */
BACKSPACE = 127 /* Backspace */
};

Expand Down Expand Up @@ -1116,15 +1117,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;
Expand Down

0 comments on commit 293f868

Please # to comment.