Support UTF-8 encoded characters in user choices
Translations (in po-files) of texts that are used for alternative choices (e.g. [dwmy]), may use UTF-8 encoded Unicode characters (e.g. [éãüå]). Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
7078556f9d
commit
500b0c080e
35
src/utils.c
35
src/utils.c
@ -192,7 +192,7 @@ void status_mesg(const char *msg1, const char *msg2)
|
|||||||
/*
|
/*
|
||||||
* Prompts the user to make a choice between named alternatives.
|
* Prompts the user to make a choice between named alternatives.
|
||||||
*
|
*
|
||||||
* The available choices are described by a string of the form
|
* The available choices are described (in po-files) by a string of the form
|
||||||
* "[ynp]". The first and last char are ignored (they are only here to
|
* "[ynp]". The first and last char are ignored (they are only here to
|
||||||
* make the translators' life easier), and every other char indicates
|
* make the translators' life easier), and every other char indicates
|
||||||
* a key the user is allowed to press.
|
* a key the user is allowed to press.
|
||||||
@ -203,25 +203,36 @@ void status_mesg(const char *msg1, const char *msg2)
|
|||||||
int status_ask_choice(const char *message, const char choice[],
|
int status_ask_choice(const char *message, const char choice[],
|
||||||
int nb_choice)
|
int nb_choice)
|
||||||
{
|
{
|
||||||
/* "[4/2/f/t/w/.../Z] " */
|
/* Turn "[42w...Z]" into * "[4/2/w/.../Z]". */
|
||||||
char avail_choice[2 * nb_choice + 3];
|
char avail_choice[nb_choice * UTF8_MAXLEN + nb_choice + 1];
|
||||||
int i, ch;
|
int ichoice[nb_choice];
|
||||||
|
int i, j, k, n, ch;
|
||||||
|
|
||||||
avail_choice[0] = '[';
|
avail_choice[0] = '[';
|
||||||
for (i = 1; i <= nb_choice; i++) {
|
for (n = 0, i = 1, j = 1; n < nb_choice; n++, i += k) {
|
||||||
avail_choice[i * 2 - 1] = choice[i];
|
for (k = 0; k < UTF8_LENGTH(choice[i]); k++) {
|
||||||
avail_choice[i * 2] = '/';
|
avail_choice[j] = choice[i + k];
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
avail_choice[nb_choice * 2] = ']';
|
avail_choice[j] = '/';
|
||||||
avail_choice[nb_choice * 2 + 1] = '\0';
|
j++;
|
||||||
|
}
|
||||||
|
avail_choice[j - 1] = ']';
|
||||||
|
avail_choice[j] = '\0';
|
||||||
|
|
||||||
status_mesg(message, avail_choice);
|
status_mesg(message, avail_choice);
|
||||||
|
|
||||||
|
/* Convert the character choices to internal integer codes. */
|
||||||
|
for (n = 0, i = 1; n < nb_choice; n++, i += j) {
|
||||||
|
j = UTF8_LENGTH(choice[i]);
|
||||||
|
ichoice[n] = utf8_decode(choice + i) + (j > 1 ? KEY_MAX : 0);
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ch = keys_wgetch(win[KEY].p);
|
ch = keys_wgetch(win[KEY].p);
|
||||||
for (i = 1; i <= nb_choice; i++)
|
for (i = 0; i < nb_choice; i++)
|
||||||
if (ch == choice[i])
|
if (ch == ichoice[i])
|
||||||
return i;
|
return i + 1;
|
||||||
if (ch == ESCAPE)
|
if (ch == ESCAPE)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (resize) {
|
if (resize) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user