1
0
mirror of https://git.zap.org.au/git/trader.git synced 2025-01-03 14:57:41 -05:00

Parameterise answer_yesno() so that the input keycodes can be localised

This commit is contained in:
John Zaitseff 2011-08-17 22:07:31 +10:00
parent 1c4cac2ba1
commit 75503ab103

View File

@ -2327,39 +2327,47 @@ int gettxlong (WINDOW *win, long int *restrict result, long int min,
bool answer_yesno (WINDOW *win) bool answer_yesno (WINDOW *win)
{ {
int key; static char *keys_yes;
bool done; static char *keys_no;
bool ret;
chtype oldattr = getattrs(win); chtype oldattr = getattrs(win);
chtype oldbkgd = getbkgd(win); chtype oldbkgd = getbkgd(win);
if (keys_yes == NULL) {
/* TRANSLATORS: The strings with msgctxt "input|Yes" and
"input|No" contain the keycodes used to determine whether a
user is answering "Yes" or "No" in response to some question.
Both upper and lower-case versions should be present. */
keys_yes = xstrdup(pgettext("input|Yes", "Yy"));
keys_no = xstrdup(pgettext("input|No", "Nn"));
}
keypad(win, true); keypad(win, true);
meta(win, true); meta(win, true);
wtimeout(win, -1); wtimeout(win, -1);
curs_set(CURS_ON); curs_set(CURS_ON);
done = false; while (true) {
while (! done) { int key = wgetch(win);
key = wgetch(win);
switch (key) { if (strchr(keys_yes, key) != NULL) {
case 'Y': ret = true;
case 'y':
case 'N':
case 'n':
key = toupper(key);
done = true;
break; break;
} else if (strchr(keys_no, key) != NULL) {
ret = false;
break;
} else
#ifdef HANDLE_RESIZE_EVENTS #ifdef HANDLE_RESIZE_EVENTS
case KEY_RESIZE: if (key == KEY_RESIZE) {
txresize(); txresize();
break; } else
#endif // HANDLE_RESIZE_EVENTS #endif // HANDLE_RESIZE_EVENTS
{
default:
beep(); beep();
} }
} }
@ -2367,7 +2375,7 @@ bool answer_yesno (WINDOW *win)
curs_set(CURS_OFF); curs_set(CURS_OFF);
wattron(win, A_BOLD); wattron(win, A_BOLD);
if (key == 'Y') { if (ret) {
/* TRANSLATORS: The strings "Yes" and "No" are printed as a /* TRANSLATORS: The strings "Yes" and "No" are printed as a
response to user input in answer to questions like "Are you response to user input in answer to questions like "Are you
sure? [Y/N] " */ sure? [Y/N] " */
@ -2380,7 +2388,7 @@ bool answer_yesno (WINDOW *win)
wattrset(win, oldattr); wattrset(win, oldattr);
wrefresh(win); wrefresh(win);
return (key == 'Y'); return ret;
} }