commit 5fab1e675410faaf88fcee0d6c80818c9d56966a
parent b0e3767af50df5a5d6885c23fa77c7c3583f09bf
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 8 Aug 2020 07:40:33 +0200
verbatim: pause a little after an ESC, to not miss a succeeding code
When we get an ESC from the keyboard, it might be the start of an
escape sequence, but the keyboard routines will need a little time
(tens of microseconds, probably) to get these codes to ncurses.
So, when doing verbatim input, pause a moment after an ESC.
This completes the fix for https://savannah.gnu.org/bugs/?58909.
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/winio.c b/src/winio.c
@@ -49,6 +49,8 @@ static bool waiting_mode = TRUE;
/* Whether getting a character will wait for a key to be pressed. */
static bool reveal_cursor = FALSE;
/* Whether the cursor should be shown when waiting for input. */
+static bool linger_after_escape = FALSE;
+ /* Whether to give ncurses some time to get the next code. */
static int statusblank = 0;
/* The number of keystrokes left before we blank the status bar. */
#ifdef USING_OLD_NCURSES
@@ -222,6 +224,11 @@ void read_keys_from(WINDOW *win)
/* Read in the remaining characters using non-blocking input. */
nodelay(win, TRUE);
+ /* When taking verbatim input, pause a moment after receiving an ESC,
+ * to give the keyboard some time to bring the next code to ncurses. */
+ if (linger_after_escape && input == ESC_CODE)
+ napms(20);
+
while (TRUE) {
#ifndef NANO_TINY
if (recording)
@@ -1371,10 +1378,13 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
int *kbinput;
reveal_cursor = TRUE;
+ linger_after_escape = TRUE;
/* Read in the first code. */
kbinput = get_input(win, 1);
+ linger_after_escape = FALSE;
+
#ifndef NANO_TINY
/* When the window was resized, abort and return nothing. */
if (*kbinput == KEY_WINCH) {