aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2006-07-28 17:57:48 -0400
committerSam Ravnborg <sam@neptun.ravnborg.org>2006-09-30 05:19:20 -0400
commitf3cbcdc955d0d2c8b4c52d6b73fc536b01b68c64 (patch)
tree3619243852b54799123f0fead031b8b45abf7aca /scripts/kconfig/lxdialog
parent2982de6993e6d9944f2215d7cb9b558b465a0c99 (diff)
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: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/kconfig/lxdialog')
-rw-r--r--scripts/kconfig/lxdialog/checklist.c10
-rw-r--r--scripts/kconfig/lxdialog/dialog.h4
-rw-r--r--scripts/kconfig/lxdialog/inputbox.c10
-rw-r--r--scripts/kconfig/lxdialog/menubox.c10
-rw-r--r--scripts/kconfig/lxdialog/textbox.c7
-rw-r--r--scripts/kconfig/lxdialog/util.c33
-rw-r--r--scripts/kconfig/lxdialog/yesno.c7
7 files changed, 62 insertions, 19 deletions
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c
index 282511020bcb..39becb72444a 100644
--- a/scripts/kconfig/lxdialog/checklist.c
+++ b/scripts/kconfig/lxdialog/checklist.c
@@ -192,7 +192,7 @@ int dialog_checklist(const char *title, const char *prompt, int height,
192 wnoutrefresh(list); 192 wnoutrefresh(list);
193 doupdate(); 193 doupdate();
194 194
195 while (key != ESC) { 195 while (key != KEY_ESC) {
196 key = wgetch(dialog); 196 key = wgetch(dialog);
197 197
198 for (i = 0; i < max_choice; i++) { 198 for (i = 0; i < max_choice; i++) {
@@ -298,8 +298,10 @@ int dialog_checklist(const char *title, const char *prompt, int height,
298 break; 298 break;
299 case 'X': 299 case 'X':
300 case 'x': 300 case 'x':
301 key = ESC; 301 key = KEY_ESC;
302 case ESC: 302 break;
303 case KEY_ESC:
304 key = on_key_esc(dialog);
303 break; 305 break;
304 } 306 }
305 307
@@ -308,5 +310,5 @@ int dialog_checklist(const char *title, const char *prompt, int height,
308 } 310 }
309 delwin(list); 311 delwin(list);
310 delwin(dialog); 312 delwin(dialog);
311 return 255; /* ESC pressed */ 313 return key; /* ESC pressed */
312} 314}
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h
index 065ded0a449f..a7cfdecc2409 100644
--- a/scripts/kconfig/lxdialog/dialog.h
+++ b/scripts/kconfig/lxdialog/dialog.h
@@ -48,7 +48,7 @@
48 48
49#define TR(params) _tracef params 49#define TR(params) _tracef params
50 50
51#define ESC 27 51#define KEY_ESC 27
52#define TAB 9 52#define TAB 9
53#define MAX_LEN 2048 53#define MAX_LEN 2048
54#define BUF_SIZE (10*1024) 54#define BUF_SIZE (10*1024)
@@ -179,6 +179,8 @@ int item_is_tag(char tag);
179 for (item_cur = item_head ? item_head: item_cur; \ 179 for (item_cur = item_head ? item_head: item_cur; \
180 item_cur && (item_cur != &item_nil); item_cur = item_cur->next) 180 item_cur && (item_cur != &item_nil); item_cur = item_cur->next)
181 181
182/* generic key handlers */
183int on_key_esc(WINDOW *win);
182 184
183void init_dialog(const char *backtitle); 185void init_dialog(const char *backtitle);
184void reset_dialog(void); 186void reset_dialog(void);
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c
index 9c53098d6b74..edb7975dbaa2 100644
--- a/scripts/kconfig/lxdialog/inputbox.c
+++ b/scripts/kconfig/lxdialog/inputbox.c
@@ -106,7 +106,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
106 106
107 wrefresh(dialog); 107 wrefresh(dialog);
108 108
109 while (key != ESC) { 109 while (key != KEY_ESC) {
110 key = wgetch(dialog); 110 key = wgetch(dialog);
111 111
112 if (button == -1) { /* Input box selected */ 112 if (button == -1) { /* Input box selected */
@@ -215,12 +215,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width
215 return (button == -1 ? 0 : button); 215 return (button == -1 ? 0 : button);
216 case 'X': 216 case 'X':
217 case 'x': 217 case 'x':
218 key = ESC; 218 key = KEY_ESC;
219 case ESC: 219 break;
220 case KEY_ESC:
221 key = on_key_esc(dialog);
220 break; 222 break;
221 } 223 }
222 } 224 }
223 225
224 delwin(dialog); 226 delwin(dialog);
225 return 255; /* ESC pressed */ 227 return KEY_ESC; /* ESC pressed */
226} 228}
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c
index f39ae29f4fcc..d3305bad15c7 100644
--- a/scripts/kconfig/lxdialog/menubox.c
+++ b/scripts/kconfig/lxdialog/menubox.c
@@ -263,7 +263,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
263 wmove(menu, choice, item_x + 1); 263 wmove(menu, choice, item_x + 1);
264 wrefresh(menu); 264 wrefresh(menu);
265 265
266 while (key != ESC) { 266 while (key != KEY_ESC) {
267 key = wgetch(menu); 267 key = wgetch(menu);
268 268
269 if (key < 256 && isalpha(key)) 269 if (key < 256 && isalpha(key))
@@ -402,12 +402,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width,
402 return button; 402 return button;
403 case 'e': 403 case 'e':
404 case 'x': 404 case 'x':
405 key = ESC; 405 key = KEY_ESC;
406 case ESC: 406 break;
407 case KEY_ESC:
408 key = on_key_esc(menu);
407 break; 409 break;
408 } 410 }
409 } 411 }
410 delwin(menu); 412 delwin(menu);
411 delwin(dialog); 413 delwin(dialog);
412 return 255; /* ESC pressed */ 414 return key; /* ESC pressed */
413} 415}
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c
index 86b0770b0387..a99e1f497d67 100644
--- a/scripts/kconfig/lxdialog/textbox.c
+++ b/scripts/kconfig/lxdialog/textbox.c
@@ -92,7 +92,7 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
92 wmove(dialog, cur_y, cur_x); /* Restore cursor position */ 92 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
93 wrefresh(dialog); 93 wrefresh(dialog);
94 94
95 while ((key != ESC) && (key != '\n')) { 95 while ((key != KEY_ESC) && (key != '\n')) {
96 key = wgetch(dialog); 96 key = wgetch(dialog);
97 switch (key) { 97 switch (key) {
98 case 'E': /* Exit */ 98 case 'E': /* Exit */
@@ -228,13 +228,14 @@ int dialog_textbox(const char *title, const char *tbuf, int height, int width)
228 wmove(dialog, cur_y, cur_x); 228 wmove(dialog, cur_y, cur_x);
229 wrefresh(dialog); 229 wrefresh(dialog);
230 break; 230 break;
231 case ESC: 231 case KEY_ESC:
232 key = on_key_esc(dialog);
232 break; 233 break;
233 } 234 }
234 } 235 }
235 delwin(text); 236 delwin(text);
236 delwin(dialog); 237 delwin(dialog);
237 return 255; /* ESC pressed */ 238 return key; /* ESC pressed */
238} 239}
239 240
240/* 241/*
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index 0b3118df50df..cb21dc4dd9fc 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -477,6 +477,39 @@ int first_alpha(const char *string, const char *exempt)
477 return 0; 477 return 0;
478} 478}
479 479
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 */
489int 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
480struct dialog_list *item_cur; 513struct dialog_list *item_cur;
481struct dialog_list item_nil; 514struct dialog_list item_nil;
482struct dialog_list *item_head; 515struct dialog_list *item_head;
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c
index 9fc24492c52f..8364f9dd01c3 100644
--- a/scripts/kconfig/lxdialog/yesno.c
+++ b/scripts/kconfig/lxdialog/yesno.c
@@ -69,7 +69,7 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
69 69
70 print_buttons(dialog, height, width, 0); 70 print_buttons(dialog, height, width, 0);
71 71
72 while (key != ESC) { 72 while (key != KEY_ESC) {
73 key = wgetch(dialog); 73 key = wgetch(dialog);
74 switch (key) { 74 switch (key) {
75 case 'Y': 75 case 'Y':
@@ -93,11 +93,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width)
93 case '\n': 93 case '\n':
94 delwin(dialog); 94 delwin(dialog);
95 return button; 95 return button;
96 case ESC: 96 case KEY_ESC:
97 key = on_key_esc(dialog);
97 break; 98 break;
98 } 99 }
99 } 100 }
100 101
101 delwin(dialog); 102 delwin(dialog);
102 return 255; /* ESC pressed */ 103 return key; /* ESC pressed */
103} 104}