Re: nano hangs when pasting five characters
Benno Schulenberg <[email protected]>
| Newsgroups | gmane.editors.nano.devel |
|---|---|
| Message-ID | <[email protected]> |
Hello Doug,
Op 01-03-2025 om 01:47 schreef Doug Smythies:
> + if (input == ERR) {
> + napms(20); /* check for sender slower than here */
> + input = wgetch(frame); /* check again */
> + if (input == ERR)
> + break;
> + }
> But it turns out that it works fine if the sleep is 29 mSec instead of 20.
> 28 mSec and below doesn't work. 29 mSec and above works.
Interesting. The other modification (with the 2 ms delay for each byte)
resulted in a 32 ms delay for the entire paste minus the final tilde,
which is also just enough to see the tilde.
Anyway, I have re-reported this issue on Savannah [1] and have attached
a workaround. Are you okay with its form?
[1] https://savannah.gnu.org/bugs/?66858
Benno
0001-input-wait-a-bit-for-when-bracketed-paste-sequence-i.patch
(text/x-patch, 2.3 KB)
From 1aa0830218a8c41b6bccf505538e269b0c5e56e2 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg <[email protected]> Date: Thu, 27 Feb 2025 12:01:58 +0100 Subject: [PATCH] input: wait a bit for "~" when bracketed-paste sequence is incomplete When pasting something into nano over OpenSSH_for_Windows, the final tilde of the end-of-paste sequence can lag some 29 ms behind the rest of the sequence, causing ncurses to split it off into a next batch of bytes. Accommodate for this by noticing the missing tilde and then waiting at most 200 ms for it to arrive. This prevents the tilde from appearing spuriously in the buffer after the paste. This addresses https://savannah.gnu.org/bugs/?66858. Reported-by: Doug Smythies <[email protected]> --- src/winio.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/winio.c b/src/winio.c index 2fff0d9e..e002219b 100644 --- a/src/winio.c +++ b/src/winio.c @@ -724,10 +724,30 @@ int convert_CSI_sequence(const int *seq, size_t length, int *consumed) /* Esc [ 2 n ; 2 ~ == F21...F24 on some terminals. */ *consumed = 5; #ifndef NANO_TINY - else if (length > 3 && seq[1] == '0' && seq[3] == '~') { + else { /* Esc [ 2 0 0 ~ == start of a bracketed paste, * Esc [ 2 0 1 ~ == end of a bracketed paste. */ - *consumed = 4; + int trailer = 0; + + if (length > 3 && seq[1] == '0' && seq[3] == '~') { + trailer = '~'; + *consumed = 4; + } else if (length == 3 && seq[1] == '0') { + /* Wait at most 200 ms for the missing '~' character. */ + halfdelay(2); + disable_kb_interrupt(); + trailer = getch(); + *consumed = 3; + raw(); + } + + if (trailer != '~') { + /* Broken -- assume a truncated end-of-paste sequence. */ + bracketed_paste = FALSE; + *consumed = length; + return ERR; + } + if (seq[2] == '0') { bracketed_paste = TRUE; return BRACKETED_PASTE_MARKER; @@ -735,12 +755,6 @@ int convert_CSI_sequence(const int *seq, size_t length, int *consumed) bracketed_paste = FALSE; return BRACKETED_PASTE_MARKER; } - } else { - /* When invalid, assume it's a truncated end-of-paste sequence, - * in order to avoid a hang -- https://sv.gnu.org/bugs/?64996. */ - bracketed_paste = FALSE; - *consumed = length; - return ERR; } #endif break; -- 2.48.1
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAmfC8xMFAwAAAAAACgkQUUu+Lrjhlh+p DQ/+MMgTNq8z+d5+LQFJ7p+h/5/SC9zyQm/OJLztSb7cWRkKyfNN+I9sgEdFmYU11mh7srnoQR7I vOpSget/FE+ladPk7UkUyYBT9t95+ndRmgCgSYYoyIMib3/oQUmQYdebF48tSnNcQ/zqc5JeMqGo o3qA7Mbcc41gUcg73ISMpag8Tg1L31z4lgcodz93DQwm9O0z5kNJCbuAn5tN5mxSLx3qZShZ0ATJ ljakT1r32qGQ9Uh953IDn8XZCWiSDb9yWt4zFPiXoRa34imsjBmK/bzi2RQ8dRixc/fsRBYmevpY pRYuXXSwMPB0W5Si5SNcaJS+O5XwdriTj0neKrHfmfu/Xbpvl12iIeqsg0yp4cAS5+jojCW4vTau cUzdX99S4fmTXJ3jSljvnfxK2T3Pvv4sIE/Ia8lCUeaPkWYBSM3MFg1g+zaTo3dDLHM41P+ndccI rELY68z3GtDrCrT9wBWwI/15MPwZbb4sfqrrTmi2+kcBBIJFawKOUHW2xlssWg43X9Zit1XZdgn/ hi39mCd/6vxEj/fDMqvja+3watB+iRCXmWgYa0lf8fg0VQR9q0C5/7Ded3qhY8eEJfsQjjsYM2US rQUesvyGlTh4lXvDDYO1gjG+BMF8iVfOOoA7WRn02X2VtgrU/TUBKHmuXvDgUjh+Rq1VyDzSW4/e 3pE= =OniT -----END PGP SIGNATURE-----