<ESC><ESC> is used to step one back in the dialogs.
When lxdialog became built-in pressing <ESC> once would cause one step back
and pressing <ESC><ESC> would cause two steps back.
This patch - based on concept from Roman Zippel <zippel@linux-m68k.org> -
makes one <ESC> a noop and pressing <ESC><ESC> will cause one step backward.
In addition the final yes/no dialog now has the option to go back to the
the kernel configuration. So if you get too far out you can now go back
to configuring the kernel without saving and starting all over again.
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
wnoutrefresh(list);
doupdate();
- while (key != ESC) {
+ while (key != KEY_ESC) {
key = wgetch(dialog);
for (i = 0; i < max_choice; i++) {
break;
case 'X':
case 'x':
- key = ESC;
- case ESC:
+ key = KEY_ESC;
+ break;
+ case KEY_ESC:
+ key = on_key_esc(dialog);
break;
}
}
delwin(list);
delwin(dialog);
- return 255; /* ESC pressed */
+ return key; /* ESC pressed */
}
#define TR(params) _tracef params
-#define ESC 27
+#define KEY_ESC 27
#define TAB 9
#define MAX_LEN 2048
#define BUF_SIZE (10*1024)
for (item_cur = item_head ? item_head: item_cur; \
item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
+/* generic key handlers */
+int on_key_esc(WINDOW *win);
void init_dialog(const char *backtitle);
void reset_dialog(void);
wrefresh(dialog);
- while (key != ESC) {
+ while (key != KEY_ESC) {
key = wgetch(dialog);
if (button == -1) { /* Input box selected */
return (button == -1 ? 0 : button);
case 'X':
case 'x':
- key = ESC;
- case ESC:
+ key = KEY_ESC;
+ break;
+ case KEY_ESC:
+ key = on_key_esc(dialog);
break;
}
}
delwin(dialog);
- return 255; /* ESC pressed */
+ return KEY_ESC; /* ESC pressed */
}
wmove(menu, choice, item_x + 1);
wrefresh(menu);
- while (key != ESC) {
+ while (key != KEY_ESC) {
key = wgetch(menu);
if (key < 256 && isalpha(key))
return button;
case 'e':
case 'x':
- key = ESC;
- case ESC:
+ key = KEY_ESC;
+ break;
+ case KEY_ESC:
+ key = on_key_esc(menu);
break;
}
}
delwin(menu);
delwin(dialog);
- return 255; /* ESC pressed */
+ return key; /* ESC pressed */
}
wmove(dialog, cur_y, cur_x); /* Restore cursor position */
wrefresh(dialog);
- while ((key != ESC) && (key != '\n')) {
+ while ((key != KEY_ESC) && (key != '\n')) {
key = wgetch(dialog);
switch (key) {
case 'E': /* Exit */
wmove(dialog, cur_y, cur_x);
wrefresh(dialog);
break;
- case ESC:
+ case KEY_ESC:
+ key = on_key_esc(dialog);
break;
}
}
delwin(text);
delwin(dialog);
- return 255; /* ESC pressed */
+ return key; /* ESC pressed */
}
/*
return 0;
}
+/*
+ * ncurses uses ESC to detect escaped char sequences. This resutl in
+ * a small timeout before ESC is actually delivered to the application.
+ * lxdialog suggest <ESC> <ESC> which is correctly translated to two
+ * times esc. But then we need to ignore the second esc to avoid stepping
+ * out one menu too much. Filter away all escaped key sequences since
+ * keypad(FALSE) turn off ncurses support for escape sequences - and thats
+ * needed to make notimeout() do as expected.
+ */
+int on_key_esc(WINDOW *win)
+{
+ int key;
+ int key2;
+ int key3;
+
+ nodelay(win, TRUE);
+ keypad(win, FALSE);
+ key = wgetch(win);
+ key2 = wgetch(win);
+ do {
+ key3 = wgetch(win);
+ } while (key3 != ERR);
+ nodelay(win, FALSE);
+ keypad(win, TRUE);
+ if (key == KEY_ESC && key2 == ERR)
+ return KEY_ESC;
+ else if (key != ERR && key != KEY_ESC && key2 == ERR)
+ ungetch(key);
+
+ return -1;
+}
+
+
struct dialog_list *item_cur;
struct dialog_list item_nil;
struct dialog_list *item_head;
print_buttons(dialog, height, width, 0);
- while (key != ESC) {
+ while (key != KEY_ESC) {
key = wgetch(dialog);
switch (key) {
case 'Y':
case '\n':
delwin(dialog);
return button;
- case ESC:
+ case KEY_ESC:
+ key = on_key_esc(dialog);
break;
}
}
delwin(dialog);
- return 255; /* ESC pressed */
+ return key; /* ESC pressed */
}
_(menu_instructions),
rows, cols, rows - 10,
active_menu, &s_scroll);
- if (res == 1 || res == 255)
+ if (res == 1 || res == KEY_ESC)
break;
if (!item_activate_selected())
continue;
} else
show_help(menu);
break;
- case 255:
+ case KEY_ESC:
return;
}
}
case 1:
show_help(menu);
break;
- case 255:
+ case KEY_ESC:
return;
}
}
case 1:
show_helptext(_("Load Alternate Configuration"), load_config_help);
break;
- case 255:
+ case KEY_ESC:
return;
}
}
case 1:
show_helptext(_("Save Alternate Configuration"), save_config_help);
break;
- case 255:
+ case KEY_ESC:
return;
}
}
init_wsize();
reset_dialog();
init_dialog(menu_backtitle);
- conf(&rootmenu);
- reset_dialog();
- res = dialog_yesno(NULL,
- _("Do you wish to save your "
- "new kernel configuration?"),
- 5, 60);
+ do {
+ conf(&rootmenu);
+ reset_dialog();
+ res = dialog_yesno(NULL,
+ _("Do you wish to save your "
+ "new kernel configuration?\n"
+ "<ESC><ESC> to continue."),
+ 6, 60);
+ } while (res == KEY_ESC);
end_dialog();
if (res == 0) {
if (conf_write(NULL)) {