From 43a5c8768263a63febe0653ff4aac395c2adbefe Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 16 Jul 2017 13:14:16 +0200 Subject: [PATCH] suspension: prevent entering an invalid byte upon resume (with S-Lang) For some reason, when returning from suspension, SLang will produce either a clipped error code (0xFF instead of 0xFFFF, when returning from an externally induced suspension), or it will clip the code of first subsequent keystroke to a single byte (when returning from a normal, in-editor suspension: ^Z). Side-step this by ignoring the clipped error code, and by using an undefined control code as the first fake keystroke. Ignoring the clipped error code is not possible when using a single-byte locale, otherwise the user would not be able to type the character with code 0xFF (although it could still be entered with Esc Esc 255). This fixes https://savannah.gnu.org/bugs/?51477. --- src/nano.c | 2 +- src/nano.h | 9 +++++++++ src/winio.c | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nano.c b/src/nano.c index 25601058..b82245a5 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1288,7 +1288,7 @@ RETSIGTYPE do_continue(int signal) terminal_init(); #endif /* Tickle the input routine so it will update the screen. */ - ungetch(KEY_F0); + ungetch(KEY_FLUSH); } #ifndef NANO_TINY diff --git a/src/nano.h b/src/nano.h index 2c1aef2a..c6ea016d 100644 --- a/src/nano.h +++ b/src/nano.h @@ -576,6 +576,15 @@ enum #define SHIFT_HOME 0x40f #define SHIFT_END 0x410 +#ifdef USE_SLANG +#ifdef ENABLE_UTF8 +#define KEY_BAD 0xFF /* Clipped error code. */ +#endif +#define KEY_FLUSH 0x91 /* User-definable control code. */ +#else +#define KEY_FLUSH KEY_F0 /* Nonexistent function key. */ +#endif + #ifndef NANO_TINY /* An imaginary key for when we get a SIGWINCH (window resize). */ #define KEY_WINCH -2 diff --git a/src/winio.c b/src/winio.c index fc058ac0..d9bde426 100644 --- a/src/winio.c +++ b/src/winio.c @@ -704,7 +704,10 @@ int parse_kbinput(WINDOW *win) /* Slang and SunOS 5.7-5.9 don't support KEY_RESIZE. */ case KEY_RESIZE: #endif - case KEY_F0: +#if defined(USE_SLANG) && defined(ENABLE_UTF8) + case KEY_BAD: +#endif + case KEY_FLUSH: return ERR; }