Re: nano hangs when pasting five characters
Benno Schulenberg <[email protected]>
| Newsgroups | gmane.editors.nano.devel |
|---|---|
| Message-ID | <[email protected]> |
Op 26-02-2025 om 17:36 schreef Doug Smythies: > The patch seems to work. It leaves the spurious "~" character in the pasted > text. But rings the bell and has a clear error message. The spurious "~" surprises me. Are you sure you applied the patch to a clean git checkout or cleanly unpacked tarball (apart from the commenting of the #ifdef/#endif)? > 7 character paste buffer: > Sequence of hex codes: 102 > Sequence of hex codes: 1b 5b 32 30 30 7e 31 32 33 34 35 36 37 1b 5b 32 30 31 7e > Sequence of hex codes: 18 > Sequence of hex codes: 6e > > 10 character paste buffer: > Sequence of hex codes: 102 > Sequence of hex codes: 1b 5b 32 30 30 7e 31 32 33 34 35 36 37 38 39 30 > Sequence of hex codes: 1b 5b 32 30 31 7e > Sequence of hex codes: 18 > Sequence of hex codes: 6e Now I'm curious what happens for an 8 and 9 character paste. Because the above seems to suggest that OpenSSH_for_Windows /does/ know not to break escape sequences, but that the logic is faulty and goes wrong sometimes. Anyway, please try the attached patch. Make sure to apply it to a freshly unpacked and fully unmodified 8.3 tarball. Both hunks should apply cleanly. Then compile and run the new nano and paste five characters, a dozen or so times. There should be no spurious tildes, no warnings, no bell. Benno
wait-200ms.patch
(text/x-patch, 1.5 KB)
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;
OpenPGP_signature.asc
(application/pgp-signature, 840 B)
-----BEGIN PGP SIGNATURE----- wsF5BAABCAAjFiEEFo5vQpe/16ea/USWUUu+Lrjhlh8FAmfARsYFAwAAAAAACgkQUUu+Lrjhlh+N vw//fRIvF0Wuadw/hYh1I2izfQXyi0UcZ2sGO8Wu8AQTEt/rT7kkw/zwGcgZrDi7FA1bJucVd/fw BhUp+RFK3IeUaOGDlCswL1tls4M5SrVKCPbOf2x3UuyJahArLmezpdWoU1QxChfbOykaLa25XdOt UFlNAwFhLYXb0+DA1ZdS53ZB/qvdUQfHrNm5aYZuibvZ9IGgUPZ52G7V5vkK2BU0Tu5Pq8Ljh+wz AJ+Ojj2S2xlBB7+xZWpPxWuAU4kaF/0fG7fubRswVo62d+58nUcxVVSOD7lkVqkeLRPIYEh4kFtG 8NB5bdHXm9FbFLyPN/qL5usVOv53sAPj5LcyE6a/HjQS4ASnwl8HSCn1S0KXHzzVyh9I+DFYhPPu N8wGOLRR9JnuyH8VnEJiYmEnz5MW3vXXyhEdDw84AHHHgYJrHTjL/QKizwBiJXQgHa+GrzACQDpA CMqhTuWURaCLMpP8Z1ODiA0xVaqGlpus8ctiCaNgIBd9LLDe5hzaTzrhCEaVg7jwUNfuLGfmtMPG nCnyGWxMNR+kQglooi72qlfW3Cc0ZMLBRbFMl5whNLiVHd2Ps7oDW2L6qjFM5GNJ4vmWSz4AE0Pq hX7AbUjYd87paEUgAP1BhEsVZCqMbpYGVcWujcGeGHEsf9AXcLOyC7v0e7EjNWzibF+Wmdt5LEiT Gcw= =RyQZ -----END PGP SIGNATURE-----