From e12f397140d2e643139730d1ab1c736cda251235 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 17 Sep 2020 16:40:07 +0200 Subject: [PATCH] build: do not let Slang translate escape sequences to key codes Slang fails to translate the longer sequences, and then truncates these sequences to just four bytes, effectively destroying them. Therefore, when built with --with-slang, always activate --raw-sequences. This avoids https://savannah.gnu.org/bugs/?49771. Bug was visible since version 2.5.0, since bindings for Ctrl+Left/Ctrl+Right were added. --- src/nano.c | 14 ++++++++++++++ src/winio.c | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/nano.c b/src/nano.c index 6b849b33..f1679a1a 100644 --- a/src/nano.c +++ b/src/nano.c @@ -430,11 +430,13 @@ void window_init(void) /* In case the terminal shrunk, make sure the status line is clear. */ wipe_statusbar(); +#ifndef USE_SLANG /* When not disabled, turn escape-sequence translation on. */ if (!ISSET(RAW_SEQUENCES)) { keypad(edit, TRUE); keypad(bottomwin, TRUE); } +#endif #ifdef ENABLED_WRAPORJUSTIFY /* Set up the wrapping point, accounting for screen width when negative. */ @@ -534,8 +536,10 @@ void usage(void) print_opt(_("-J "), _("--guidestripe="), N_("Show a guiding bar at this column")); #endif +#ifndef USE_SLANG print_opt("-K", "--rawsequences", N_("Fix numeric keypad key confusion problem")); +#endif #ifndef NANO_TINY print_opt("-L", "--nonewlines", N_("Don't add an automatic newline")); @@ -1690,7 +1694,9 @@ int main(int argc, char **argv) #ifdef ENABLE_NANORC {"ignorercfiles", 0, NULL, 'I'}, #endif +#ifndef USE_SLANG {"rawsequences", 0, NULL, 'K'}, +#endif #ifdef ENABLED_WRAPORJUSTIFY {"trimblanks", 0, NULL, 'M'}, #endif @@ -1871,9 +1877,11 @@ int main(int argc, char **argv) } break; #endif +#ifndef USE_SLANG case 'K': SET(RAW_SEQUENCES); break; +#endif #ifndef NANO_TINY case 'L': SET(NO_NEWLINES); @@ -2192,9 +2200,15 @@ int main(int argc, char **argv) #endif } +#ifdef USE_SLANG + /* When using Slang, do not let Slang translate escape sequences to + * key codes, because it does it wrong for the longer sequences. */ + SET(RAW_SEQUENCES); +#else /* When getting untranslated escape sequences, the mouse cannot be used. */ if (ISSET(RAW_SEQUENCES)) UNSET(USE_MOUSE); +#endif #ifdef ENABLE_HISTORIES /* Initialize the pointers for the Search/Replace/Execute histories. */ diff --git a/src/winio.c b/src/winio.c index 168e96bf..2bb1a56b 100644 --- a/src/winio.c +++ b/src/winio.c @@ -1447,9 +1447,10 @@ char *get_verbatim_kbinput(WINDOW *win, size_t *count) * don't get extended keypad values. */ if (ISSET(PRESERVE)) disable_flow_control(); +#ifndef USE_SLANG if (!ISSET(RAW_SEQUENCES)) keypad(win, FALSE); - +#endif #ifndef NANO_TINY /* Turn bracketed-paste mode off. */ printf("\x1B[?2004l"); @@ -1483,12 +1484,14 @@ char *get_verbatim_kbinput(WINDOW *win, size_t *count) * keypad back on if necessary now that we're done. */ if (ISSET(PRESERVE)) enable_flow_control(); +#ifndef USE_SLANG /* Use the global window pointers, because a resize may have freed * the data that the win parameter points to. */ if (!ISSET(RAW_SEQUENCES)) { keypad(edit, TRUE); keypad(bottomwin, TRUE); } +#endif if (*count < 999) { for (size_t i = 0; i < *count; i++)