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.master
parent
2d5c917b1a
commit
10c49edd3b
32
src/prompt.c
32
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 do_yesno_prompt(bool all, const char *msg)
|
||||||
{
|
{
|
||||||
int response = -2, width = 16;
|
int response = -2, width = 16;
|
||||||
/* TRANSLATORS: For the next three strings, specify the single-byte
|
/* TRANSLATORS: For the next three strings, specify the starting letters
|
||||||
* starting letters of the translations for "Yes", "No", and "All".
|
* of the translations for "Yes"/"No"/"All". The first letter of each of
|
||||||
* Of each string, the first letter is shown in the help lines. */
|
* these strings MUST be a single-byte letter; others may be multi-byte. */
|
||||||
const char *yesstr = _("Yy");
|
const char *yesstr = _("Yy");
|
||||||
const char *nostr = _("Nn");
|
const char *nostr = _("Nn");
|
||||||
const char *allstr = _("Aa");
|
const char *allstr = _("Aa");
|
||||||
|
|
||||||
while (response == -2) {
|
while (response == -2) {
|
||||||
int kbinput;
|
char letter[MAXCHARLEN + 1];
|
||||||
|
int kbinput, index = 0;
|
||||||
|
|
||||||
if (!ISSET(NO_HELP)) {
|
if (!ISSET(NO_HELP)) {
|
||||||
char shortstr[MAXCHARLEN + 2];
|
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. */
|
/* When not replacing, show the cursor while waiting for a key. */
|
||||||
kbinput = get_kbinput(bottomwin, !all);
|
kbinput = get_kbinput(bottomwin, !all);
|
||||||
|
|
||||||
/* See if the pressed key is in the Yes, No, or All strings. */
|
|
||||||
#ifdef ENABLE_NLS
|
#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;
|
response = 1;
|
||||||
else if (strchr(nostr, kbinput) != NULL)
|
else if (strstr(nostr, letter) != NULL)
|
||||||
response = 0;
|
response = 0;
|
||||||
else if (all && strchr(allstr, kbinput) != NULL)
|
else if (all && strstr(allstr, letter) != NULL)
|
||||||
response = 2;
|
response = 2;
|
||||||
else
|
else
|
||||||
#endif
|
#endif /* ENABLE_NLS */
|
||||||
if (strchr("Yy", kbinput) != NULL)
|
if (strchr("Yy", kbinput) != NULL)
|
||||||
response = 1;
|
response = 1;
|
||||||
else if (strchr("Nn", kbinput) != NULL)
|
else if (strchr("Nn", kbinput) != NULL)
|
||||||
|
|
Loading…
Reference in New Issue