[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] prompt: when asking for Yes/No/All, recognize also
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] prompt: when asking for Yes/No/All, recognize also UTF-8 letters |
Date: |
Mon, 7 May 2018 12:57:27 +0200 |
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.
---
src/prompt.c | 34 ++++++++++++++++++++++++----------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/prompt.c b/src/prompt.c
index e7cb7418..eeb16ba7 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -659,15 +659,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];
@@ -710,16 +711,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)
+#if defined(ENABLE_UTF8) && defined(ENABLE_NLS)
+ letter[index++] = (unsigned char)kbinput;
+
+ /* 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);
+ }
+
+ 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_UTF8 && ENABLE_NLS */
if (strchr("Yy", kbinput) != NULL)
response = 1;
else if (strchr("Nn", kbinput) != NULL)
--
2.17.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH] prompt: when asking for Yes/No/All, recognize also UTF-8 letters,
Benno Schulenberg <=