nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 10c49edd3b7c904a05219c087fdf11586b41dc14
parent 2d5c917b1aa61bb958d7cb56c9312478763a4a1c
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon,  7 May 2018 11:44:01 +0200

prompt: when asking for Yes/No/All, recognize also UTF-8 letters

Letters in other scripts than English often consist of multiple bytes.
When in a UTF-8 locale, correctly gather these bytes from the input and
put them together as the single letter that they are, before comparing
this letter against the translated "Yy", "Nn" and "Aa" strings.

Diffstat:
Msrc/prompt.c | 32+++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/src/prompt.c b/src/prompt.c @@ -670,15 +670,16 @@ int do_prompt(bool allow_tabs, bool allow_files, int do_yesno_prompt(bool all, const char *msg) { int response = -2, width = 16; - /* TRANSLATORS: For the next three strings, specify the single-byte - * starting letters of the translations for "Yes", "No", and "All". - * Of each string, the first letter is shown in the help lines. */ + /* TRANSLATORS: For the next three strings, specify the starting letters + * of the translations for "Yes"/"No"/"All". The first letter of each of + * these strings MUST be a single-byte letter; others may be multi-byte. */ const char *yesstr = _("Yy"); const char *nostr = _("Nn"); const char *allstr = _("Aa"); while (response == -2) { - int kbinput; + char letter[MAXCHARLEN + 1]; + int kbinput, index = 0; if (!ISSET(NO_HELP)) { char shortstr[MAXCHARLEN + 2]; @@ -721,16 +722,29 @@ int do_yesno_prompt(bool all, const char *msg) /* When not replacing, show the cursor while waiting for a key. */ kbinput = get_kbinput(bottomwin, !all); - /* See if the pressed key is in the Yes, No, or All strings. */ #ifdef ENABLE_NLS - if (strchr(yesstr, kbinput) != NULL) + letter[index++] = (unsigned char)kbinput; +#ifdef ENABLE_UTF8 + /* If the received code is a UTF-8 starter byte, get also the + * continuation bytes and assemble them into one letter. */ + if (using_utf8() && 0xC0 <= kbinput && kbinput <= 0xF7) { + int extras = (kbinput / 16) % 4 + (kbinput <= 0xCF ? 1 : 0); + + while (extras <= get_key_buffer_len() && extras-- > 0) + letter[index++] = (unsigned char)get_kbinput(bottomwin, !all); + } +#endif + letter[index] = '\0'; + + /* See if the typed letter is in the Yes, No, or All strings. */ + if (strstr(yesstr, letter) != NULL) response = 1; - else if (strchr(nostr, kbinput) != NULL) + else if (strstr(nostr, letter) != NULL) response = 0; - else if (all && strchr(allstr, kbinput) != NULL) + else if (all && strstr(allstr, letter) != NULL) response = 2; else -#endif +#endif /* ENABLE_NLS */ if (strchr("Yy", kbinput) != NULL) response = 1; else if (strchr("Nn", kbinput) != NULL)