Commit graph

3 commits

Author SHA1 Message Date
Simon Glass
17b45e684a cli: Correct several bugs in cli_getch()
This function does not behave as expected when unknown escape sequences
are sent to it:

- it fails to store (and thus echo) the last character of the invalid
  sequence
- it fails to set esc_len to 0 when it finishes emitting the invalid
  sequence, meaning that the following character will appear to be part
  of a new escape sequence
- it processes the first character of the rejected sequence as a valid
  character, just starting the sequence all over again

The last two bugs conspire to produce an "impossible condition #876"
message which is the main symptom of this behaviour.

Fix these bugs and add a test to verify the behaviour.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2023-03-28 09:25:51 -04:00
Simon Glass
32bab0eae5 menu: Make use of CLI character processing
Avoid duplicating some of the escape-sequence processing here and use the
CLI function instead.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-16 14:14:11 -05:00
Simon Glass
b08e9d4b66 cli: Move readline character-processing to a state machine
The current cread_line() function is very long. It handles the escape
processing inline. The menu command does similar processing but at the
character level, so there is some duplication.

Split the character processing into a new function cli_ch_process() which
processes individual characters and returns the resulting input character,
taking account of escape sequences. It requires the caller to set up and
maintain its state.

Update cread_line() to use this new function.

The only intended functional change is that an invalid escape sequence
does not add invalid/control characters into the input buffer, but instead
discards these.

Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-16 14:14:11 -05:00