History

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.

Sam Ravnborg committed 20 years ago

Commit f3cbcdc1 parent 2982de68 files · +76 −30Browse files

Showing the changes to scripts (8 of 8 files). Show all

Unified · Split

8 files
  1. scripts/kconfig/lxdialog/checklist.c +6 −4
  2. scripts/kconfig/lxdialog/dialog.h +3 −1
  3. scripts/kconfig/lxdialog/inputbox.c +6 −4
  4. scripts/kconfig/lxdialog/menubox.c +6 −4
  5. scripts/kconfig/lxdialog/textbox.c +4 −3
  6. scripts/kconfig/lxdialog/util.c +33 −0
  7. scripts/kconfig/lxdialog/yesno.c +4 −3
  8. scripts/kconfig/mconf.c +14 −11
scripts/kconfig/lxdialog/checklist.c+6−4
@@ -192,7 +192,7 @@ int dialog_checklist(const char *title, const char *prompt, int height, · 191 unmodified lines
192192 wnoutrefresh(list);
193193 doupdate();
194194
195− while (key != ESC) {
195+ while (key != KEY_ESC) {
196196 key = wgetch(dialog);
197197
198198 for (i = 0; i < max_choice; i++) {
@@ -298,8 +298,10 @@ int dialog_checklist(const char *title, const char *prompt, int height, · 99 unmodified lines
298298 break;
299299 case 'X':
300300 case 'x':
301− key = ESC;
302− case ESC:
301+ key = KEY_ESC;
302+ break;
303+ case KEY_ESC:
304+ key = on_key_esc(dialog);
303305 break;
304306 }
305307
@@ -308,5 +310,5 @@ int dialog_checklist(const char *title, const char *prompt, int height, · 2 unmodified lines
308310 }
309311 delwin(list);
310312 delwin(dialog);
311− return 255; /* ESC pressed */
313+ return key; /* ESC pressed */
312314 }
scripts/kconfig/lxdialog/dialog.h+3−1
@@ -48,7 +48,7 @@ · 47 unmodified lines
4848
4949 #define TR(params) _tracef params
5050
51−#define ESC 27
51+#define KEY_ESC 27
5252 #define TAB 9
5353 #define MAX_LEN 2048
5454 #define BUF_SIZE (10*1024)
@@ -179,6 +179,8 @@ int item_is_tag(char tag); · 124 unmodified lines
179179 for (item_cur = item_head ? item_head: item_cur; \
180180 item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
181181
182+/* generic key handlers */
183+int on_key_esc(WINDOW *win);
182184
183185 void init_dialog(const char *backtitle);
184186 void reset_dialog(void);
scripts/kconfig/lxdialog/inputbox.c+6−4
@@ -106,7 +106,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width · 105 unmodified lines
106106
107107 wrefresh(dialog);
108108
109− while (key != ESC) {
109+ while (key != KEY_ESC) {
110110 key = wgetch(dialog);
111111
112112 if (button == -1) { /* Input box selected */
@@ -215,12 +215,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width · 102 unmodified lines
215215 return (button == -1 ? 0 : button);
216216 case 'X':
217217 case 'x':
218− key = ESC;
219− case ESC:
218+ key = KEY_ESC;
219+ break;
220+ case KEY_ESC:
221+ key = on_key_esc(dialog);
220222 break;
221223 }
222224 }
223225
224226 delwin(dialog);
225− return 255; /* ESC pressed */
227+ return KEY_ESC; /* ESC pressed */
226228 }
scripts/kconfig/lxdialog/menubox.c+6−4
@@ -263,7 +263,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 262 unmodified lines
263263 wmove(menu, choice, item_x + 1);
264264 wrefresh(menu);
265265
266− while (key != ESC) {
266+ while (key != KEY_ESC) {
267267 key = wgetch(menu);
268268
269269 if (key < 256 && isalpha(key))
@@ -402,12 +402,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, · 132 unmodified lines
402402 return button;
403403 case 'e':
404404 case 'x':
405− key = ESC;
406− case ESC:
405+ key = KEY_ESC;
406+ break;
407+ case KEY_ESC:
408+ key = on_key_esc(menu);
407409 break;
408410 }
409411 }
410412 delwin(menu);
411413 delwin(dialog);
412− return 255; /* ESC pressed */
414+ return key; /* ESC pressed */
413415 }
scripts/kconfig/lxdialog/textbox.c+4−3
@@ -92,7 +92,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width) · 91 unmodified lines
9292 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
9393 wrefresh(dialog);
9494
95− while ((key != ESC) && (key != '\n')) {
95+ while ((key != KEY_ESC) && (key != '\n')) {
9696 key = wgetch(dialog);
9797 switch (key) {
9898 case 'E': /* Exit */
@@ -228,13 +228,14 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width) · 129 unmodified lines
228228 wmove(dialog, cur_y, cur_x);
229229 wrefresh(dialog);
230230 break;
231− case ESC:
231+ case KEY_ESC:
232+ key = on_key_esc(dialog);
232233 break;
233234 }
234235 }
235236 delwin(text);
236237 delwin(dialog);
237− return 255; /* ESC pressed */
238+ return key; /* ESC pressed */
238239 }
239240
240241 /*
scripts/kconfig/lxdialog/util.c+33−0
@@ -477,6 +477,39 @@ int first_alpha(const char *string, const char *exempt) · 476 unmodified lines
477477 return 0;
478478 }
479479
480+/*
481+ * ncurses uses ESC to detect escaped char sequences. This resutl in
482+ * a small timeout before ESC is actually delivered to the application.
483+ * lxdialog suggest <ESC> <ESC> which is correctly translated to two
484+ * times esc. But then we need to ignore the second esc to avoid stepping
485+ * out one menu too much. Filter away all escaped key sequences since
486+ * keypad(FALSE) turn off ncurses support for escape sequences - and thats
487+ * needed to make notimeout() do as expected.
488+ */
489+int on_key_esc(WINDOW *win)
490+{
491+ int key;
492+ int key2;
493+ int key3;
494+
495+ nodelay(win, TRUE);
496+ keypad(win, FALSE);
497+ key = wgetch(win);
498+ key2 = wgetch(win);
499+ do {
500+ key3 = wgetch(win);
501+ } while (key3 != ERR);
502+ nodelay(win, FALSE);
503+ keypad(win, TRUE);
504+ if (key == KEY_ESC && key2 == ERR)
505+ return KEY_ESC;
506+ else if (key != ERR && key != KEY_ESC && key2 == ERR)
507+ ungetch(key);
508+
509+ return -1;
510+}
511+
512+
480513 struct dialog_list *item_cur;
481514 struct dialog_list item_nil;
482515 struct dialog_list *item_head;
scripts/kconfig/lxdialog/yesno.c+4−3
@@ -69,7 +69,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) · 68 unmodified lines
6969
7070 print_buttons(dialog, height, width, 0);
7171
72− while (key != ESC) {
72+ while (key != KEY_ESC) {
7373 key = wgetch(dialog);
7474 switch (key) {
7575 case 'Y':
@@ -93,11 +93,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) · 17 unmodified lines
9393 case '\n':
9494 delwin(dialog);
9595 return button;
96− case ESC:
96+ case KEY_ESC:
97+ key = on_key_esc(dialog);
9798 break;
9899 }
99100 }
100101
101102 delwin(dialog);
102− return 255; /* ESC pressed */
103+ return key; /* ESC pressed */
103104 }
scripts/kconfig/mconf.c+14−11
@@ -608,7 +608,7 @@ static void conf(struct menu *menu) · 607 unmodified lines
608608 _(menu_instructions),
609609 rows, cols, rows - 10,
610610 active_menu, &s_scroll);
611− if (res == 1 || res == 255)
611+ if (res == 1 || res == KEY_ESC)
612612 break;
613613 if (!item_activate_selected())
614614 continue;
@@ -754,7 +754,7 @@ static void conf_choice(struct menu *menu) · 139 unmodified lines
754754 } else
755755 show_help(menu);
756756 break;
757− case 255:
757+ case KEY_ESC:
758758 return;
759759 }
760760 }
@@ -794,7 +794,7 @@ static void conf_string(struct menu *menu) · 33 unmodified lines
794794 case 1:
795795 show_help(menu);
796796 break;
797− case 255:
797+ case KEY_ESC:
798798 return;
799799 }
800800 }
@@ -819,7 +819,7 @@ static void conf_load(void) · 18 unmodified lines
819819 case 1:
820820 show_helptext(_("Load Alternate Configuration"), load_config_help);
821821 break;
822− case 255:
822+ case KEY_ESC:
823823 return;
824824 }
825825 }
@@ -843,7 +843,7 @@ static void conf_save(void) · 17 unmodified lines
843843 case 1:
844844 show_helptext(_("Save Alternate Configuration"), save_config_help);
845845 break;
846− case 255:
846+ case KEY_ESC:
847847 return;
848848 }
849849 }
@@ -883,12 +883,15 @@ int main(int ac, char **av) · 33 unmodified lines
883883 init_wsize();
884884 reset_dialog();
885885 init_dialog(menu_backtitle);
886− conf(&rootmenu);
887− reset_dialog();
888− res = dialog_yesno(NULL,
889− _("Do you wish to save your "
890− "new kernel configuration?"),
891− 5, 60);
886+ do {
887+ conf(&rootmenu);
888+ reset_dialog();
889+ res = dialog_yesno(NULL,
890+ _("Do you wish to save your "
891+ "new kernel configuration?\n"
892+ "<ESC><ESC> to continue."),
893+ 6, 60);
894+ } while (res == KEY_ESC);
892895 end_dialog();
893896 if (res == 0) {
894897 if (conf_write(NULL)) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t