[PATCH 1/5] readkey: wait for the rest of an escape sequence
Ahmad Fatoum
a.fatoum at barebox.org
Sun Nov 8 01:32:03 PST 2026
Since commit 68d07f38e8e8 ("readkey: handle standalone ESC keypress
with timeout"), read_key() waits at most 50ms for each of the two
characters after an ESC. The gap after the ESC is what tells a bare ESC
from an escape sequence, but once the next character is a [ or an O,
the rest of the sequence is on its way. When it arrives later, e.g.
because it went into the next packet or the next batch of an emulator,
the ESC and the [ are dropped, and the line editor inserts the rest:
the up arrow types an A.
Wait for the rest of a sequence without a timeout, as read_key() did
before and still does for the digits in ESC [ 1 ~ and the like. Any
other character after an ESC can't start a sequence we know, so return
right away then instead of waiting for one more.
Fixes: 68d07f38e8e8 ("readkey: handle standalone ESC keypress with timeout")
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
lib/readkey.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/readkey.c b/lib/readkey.c
index 71f9b41c5055..fed2f70418b0 100644
--- a/lib/readkey.c
+++ b/lib/readkey.c
@@ -80,9 +80,11 @@ int read_key(void)
if (poll_key_into_buf(&esc[i++]))
return '\e';
- if (poll_key_into_buf(&esc[i++]))
+ if (esc[0] != '[' && esc[0] != 'O')
return -1;
+ esc[i++] = getchar();
+
if (isdigit(esc[1])) {
while(1) {
esc[i] = getchar();
--
2.47.3
More information about the barebox
mailing list