Skip to content

Commit

Permalink
fix(linenoise): Skip 0x00 to 0x1F character in dump mode
Browse files Browse the repository at this point in the history
Skipping through the non printable character assures that
in dumb mode, any special keys will not lead to the cursor
movement.
  • Loading branch information
SoucheSouche committed Jun 25, 2024
1 parent ac2491a commit 302881e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 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,9 +1117,7 @@ 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--;
Expand All @@ -1131,6 +1130,10 @@ static int linenoiseDumb(char* buf, size_t buflen, const char* prompt) {
continue;
}

} 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 302881e

Please # to comment.