[PATCH v3] cli: Consume invalid escape sequences early

Yurii Monakov monakov.y at gmail.com
Tue Oct 10 18:19:34 CEST 2023


Simon,

On Tue, Oct 10, 2023 at 5:58 PM Simon Glass <sjg at google.com> wrote:
>
> On Tue, 10 Oct 2023 at 02:16, Yurii Monakov <monakov.y at gmail.com> wrote:
> >
> > Unexpected 'Esc' key presses are accumulated internally, even if it is
> > already clear that the current escape sequence is invalid. This results
> > in weird behaviour. For example, the next character after 'Esc' key
> > simply disappears from input and 'Unknown command' is printed
> > after 'Enter'.
> >
> > This commit fixes some issues with extra 'Esc' keys entered by user:
> >
> > 1. Sequence <Esc><Esc><Enter> right after autoboot stop gives:
> > =>
> > nknown command 'ry 'help'
> > =>
> > 2. Sequence <Esc><p><r><i><Enter> gives:
> > => ri
> > Unknown command 'ri' - try 'help'
> > =>
> > 3. Extra 'Esc' key presses break backspace functionality.
> >
> > Signed-off-by: Yurii Monakov <monakov.y at gmail.com>
> > ---
> > Changes for v2:
> > - add tests and reword commit message
> > Changes for v3:
> > - fix indentation
> >
> >  common/cli_getch.c  |  2 ++
> >  test/common/cread.c | 12 ++++++++++++
> >  2 files changed, 14 insertions(+)
>
> Reviewed-by: Simon Glass <sjg at chromium.org>
>
> Unfortunately this shows a design flaw, one which is hard to fix in general. But this does improve it.
>
> The flaw is that we assume that character sequences have a time gap between them, which allows figuring out when a sequence has finished.
>
> But when starting up there may be buffered output with no gaps. I don't think there is a general fix for this problem. One option is to have a special mode at the start, where escape sequences are ignored. But the user may press an arrow key on startup.
>
> So I don't have anything much to suggest here. Let's see how this fix goes. Perhaps it is enough.
>
> Regards,
> Simon

> One option is to have a special mode at the start, where escape sequences are ignored
I think that there is no reason to emit parts of invalid escape
sequences, as current code does.
There is a very little chance (at least for a human being) to input
such sequences by intent.

> But the user may press an arrow key on startup.
As a fix, autoboot code can check for 'Esc' and keep it as a part of
input string.

Best Regards,
Yurii


More information about the U-Boot mailing list