Commit f3cbcdc9 authored by Sam Ravnborg's avatar Sam Ravnborg Committed by Sam Ravnborg

kconfig/lxdialog: let <ESC><ESC> behave as expected

<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: default avatarSam Ravnborg <sam@ravnborg.org>
parent 2982de69
...@@ -192,7 +192,7 @@ int dialog_checklist(const char *title, const char *prompt, int height, ...@@ -192,7 +192,7 @@ int dialog_checklist(const char *title, const char *prompt, int height,
wnoutrefresh(list); wnoutrefresh(list);
doupdate(); doupdate();
while (key != ESC) { while (key != KEY_ESC) {
key = wgetch(dialog); key = wgetch(dialog);
for (i = 0; i < max_choice; i++) { for (i = 0; i < max_choice; i++) {
...@@ -298,8 +298,10 @@ int dialog_checklist(const char *title, const char *prompt, int height, ...@@ -298,8 +298,10 @@ int dialog_checklist(const char *title, const char *prompt, int height,
break; break;
case 'X': case 'X':
case 'x': case 'x':
key = ESC; key = KEY_ESC;
case ESC: break;
case KEY_ESC:
key = on_key_esc(dialog);
break; break;
} }
...@@ -308,5 +310,5 @@ int dialog_checklist(const char *title, const char *prompt, int height, ...@@ -308,5 +310,5 @@ int dialog_checklist(const char *title, const char *prompt, int height,
} }
delwin(list); delwin(list);
delwin(dialog); delwin(dialog);
return 255; /* ESC pressed */ return key; /* ESC pressed */
} }
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
#define TR(params) _tracef params #define TR(params) _tracef params
#define ESC 27 #define KEY_ESC 27
#define TAB 9 #define TAB 9
#define MAX_LEN 2048 #define MAX_LEN 2048
#define BUF_SIZE (10*1024) #define BUF_SIZE (10*1024)
...@@ -179,6 +179,8 @@ int item_is_tag(char tag); ...@@ -179,6 +179,8 @@ int item_is_tag(char tag);
for (item_cur = item_head ? item_head: item_cur; \ for (item_cur = item_head ? item_head: item_cur; \
item_cur && (item_cur != &item_nil); item_cur = item_cur->next) 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 init_dialog(const char *backtitle);
void reset_dialog(void); void reset_dialog(void);
......
...@@ -106,7 +106,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width ...@@ -106,7 +106,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
wrefresh(dialog); wrefresh(dialog);
while (key != ESC) { while (key != KEY_ESC) {
key = wgetch(dialog); key = wgetch(dialog);
if (button == -1) { /* Input box selected */ if (button == -1) { /* Input box selected */
...@@ -215,12 +215,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width ...@@ -215,12 +215,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
return (button == -1 ? 0 : button); return (button == -1 ? 0 : button);
case 'X': case 'X':
case 'x': case 'x':
key = ESC; key = KEY_ESC;
case ESC: break;
case KEY_ESC:
key = on_key_esc(dialog);
break; break;
} }
} }
delwin(dialog); delwin(dialog);
return 255; /* ESC pressed */ return KEY_ESC; /* ESC pressed */
} }
...@@ -263,7 +263,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -263,7 +263,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
wmove(menu, choice, item_x + 1); wmove(menu, choice, item_x + 1);
wrefresh(menu); wrefresh(menu);
while (key != ESC) { while (key != KEY_ESC) {
key = wgetch(menu); key = wgetch(menu);
if (key < 256 && isalpha(key)) if (key < 256 && isalpha(key))
...@@ -402,12 +402,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, ...@@ -402,12 +402,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
return button; return button;
case 'e': case 'e':
case 'x': case 'x':
key = ESC; key = KEY_ESC;
case ESC: break;
case KEY_ESC:
key = on_key_esc(menu);
break; break;
} }
} }
delwin(menu); delwin(menu);
delwin(dialog); delwin(dialog);
return 255; /* ESC pressed */ return key; /* ESC pressed */
} }
...@@ -92,7 +92,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width) ...@@ -92,7 +92,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
wmove(dialog, cur_y, cur_x); /* Restore cursor position */ wmove(dialog, cur_y, cur_x); /* Restore cursor position */
wrefresh(dialog); wrefresh(dialog);
while ((key != ESC) && (key != '\n')) { while ((key != KEY_ESC) && (key != '\n')) {
key = wgetch(dialog); key = wgetch(dialog);
switch (key) { switch (key) {
case 'E': /* Exit */ case 'E': /* Exit */
...@@ -228,13 +228,14 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width) ...@@ -228,13 +228,14 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
wmove(dialog, cur_y, cur_x); wmove(dialog, cur_y, cur_x);
wrefresh(dialog); wrefresh(dialog);
break; break;
case ESC: case KEY_ESC:
key = on_key_esc(dialog);
break; break;
} }
} }
delwin(text); delwin(text);
delwin(dialog); delwin(dialog);
return 255; /* ESC pressed */ return key; /* ESC pressed */
} }
/* /*
......
...@@ -477,6 +477,39 @@ int first_alpha(const char *string, const char *exempt) ...@@ -477,6 +477,39 @@ int first_alpha(const char *string, const char *exempt)
return 0; 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_cur;
struct dialog_list item_nil; struct dialog_list item_nil;
struct dialog_list *item_head; struct dialog_list *item_head;
......
...@@ -69,7 +69,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) ...@@ -69,7 +69,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
print_buttons(dialog, height, width, 0); print_buttons(dialog, height, width, 0);
while (key != ESC) { while (key != KEY_ESC) {
key = wgetch(dialog); key = wgetch(dialog);
switch (key) { switch (key) {
case 'Y': case 'Y':
...@@ -93,11 +93,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) ...@@ -93,11 +93,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
case '\n': case '\n':
delwin(dialog); delwin(dialog);
return button; return button;
case ESC: case KEY_ESC:
key = on_key_esc(dialog);
break; break;
} }
} }
delwin(dialog); delwin(dialog);
return 255; /* ESC pressed */ return key; /* ESC pressed */
} }
...@@ -608,7 +608,7 @@ static void conf(struct menu *menu) ...@@ -608,7 +608,7 @@ static void conf(struct menu *menu)
_(menu_instructions), _(menu_instructions),
rows, cols, rows - 10, rows, cols, rows - 10,
active_menu, &s_scroll); active_menu, &s_scroll);
if (res == 1 || res == 255) if (res == 1 || res == KEY_ESC)
break; break;
if (!item_activate_selected()) if (!item_activate_selected())
continue; continue;
...@@ -754,7 +754,7 @@ static void conf_choice(struct menu *menu) ...@@ -754,7 +754,7 @@ static void conf_choice(struct menu *menu)
} else } else
show_help(menu); show_help(menu);
break; break;
case 255: case KEY_ESC:
return; return;
} }
} }
...@@ -794,7 +794,7 @@ static void conf_string(struct menu *menu) ...@@ -794,7 +794,7 @@ static void conf_string(struct menu *menu)
case 1: case 1:
show_help(menu); show_help(menu);
break; break;
case 255: case KEY_ESC:
return; return;
} }
} }
...@@ -819,7 +819,7 @@ static void conf_load(void) ...@@ -819,7 +819,7 @@ static void conf_load(void)
case 1: case 1:
show_helptext(_("Load Alternate Configuration"), load_config_help); show_helptext(_("Load Alternate Configuration"), load_config_help);
break; break;
case 255: case KEY_ESC:
return; return;
} }
} }
...@@ -843,7 +843,7 @@ static void conf_save(void) ...@@ -843,7 +843,7 @@ static void conf_save(void)
case 1: case 1:
show_helptext(_("Save Alternate Configuration"), save_config_help); show_helptext(_("Save Alternate Configuration"), save_config_help);
break; break;
case 255: case KEY_ESC:
return; return;
} }
} }
...@@ -883,12 +883,15 @@ int main(int ac, char **av) ...@@ -883,12 +883,15 @@ int main(int ac, char **av)
init_wsize(); init_wsize();
reset_dialog(); reset_dialog();
init_dialog(menu_backtitle); init_dialog(menu_backtitle);
conf(&rootmenu); do {
reset_dialog(); conf(&rootmenu);
res = dialog_yesno(NULL, reset_dialog();
_("Do you wish to save your " res = dialog_yesno(NULL,
"new kernel configuration?"), _("Do you wish to save your "
5, 60); "new kernel configuration?\n"
"<ESC><ESC> to continue."),
6, 60);
} while (res == KEY_ESC);
end_dialog(); end_dialog();
if (res == 0) { if (res == 0) {
if (conf_write(NULL)) { if (conf_write(NULL)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment