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.
This commit is contained in:
Benno Schulenberg 2020-08-08 07:40:33 +02:00
parent b0e3767af5
commit 5fab1e6754
1 changed files with 10 additions and 0 deletions

View File

@ -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) {