diff options
author | Benjamin Poirier <bpoirier@suse.de> | 2012-08-23 14:55:04 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-09-27 12:08:14 -0400 |
commit | 537ddae75c0f41343928d39f308f3ca670f000a8 (patch) | |
tree | 623517db039bdc4d5b49bfb83ef8647428421ad2 /scripts | |
parent | b9d29abd98a2bbeb3a6c49c1607348c92bc80105 (diff) |
menuconfig: Extend dialog_textbox so that it can exit on arbitrary keypresses
The caller will be able to perform actions based on hotkeys in the displayed
text.
Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/kconfig/lxdialog/dialog.h | 3 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/textbox.c | 31 | ||||
-rw-r--r-- | scripts/kconfig/mconf.c | 12 |
3 files changed, 33 insertions, 13 deletions
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index 43a58ec09cd4..35ca0286d105 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h | |||
@@ -210,7 +210,8 @@ int first_alpha(const char *string, const char *exempt); | |||
210 | int dialog_yesno(const char *title, const char *prompt, int height, int width); | 210 | int dialog_yesno(const char *title, const char *prompt, int height, int width); |
211 | int dialog_msgbox(const char *title, const char *prompt, int height, | 211 | int dialog_msgbox(const char *title, const char *prompt, int height, |
212 | int width, int pause); | 212 | int width, int pause); |
213 | int dialog_textbox(const char *title, const char *file, int height, int width); | 213 | int dialog_textbox(const char *title, const char *file, int height, int width, |
214 | int *keys); | ||
214 | int dialog_menu(const char *title, const char *prompt, | 215 | int dialog_menu(const char *title, const char *prompt, |
215 | const void *selected, int *s_scroll); | 216 | const void *selected, int *s_scroll); |
216 | int dialog_checklist(const char *title, const char *prompt, int height, | 217 | int dialog_checklist(const char *title, const char *prompt, int height, |
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c index 264a2b9f320c..eb4ee92ad2b3 100644 --- a/scripts/kconfig/lxdialog/textbox.c +++ b/scripts/kconfig/lxdialog/textbox.c | |||
@@ -47,14 +47,16 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, | |||
47 | 47 | ||
48 | /* | 48 | /* |
49 | * Display text from a file in a dialog box. | 49 | * Display text from a file in a dialog box. |
50 | * | ||
51 | * keys is a null-terminated array | ||
50 | */ | 52 | */ |
51 | int dialog_textbox(const char *title, const char *tbuf, | 53 | int dialog_textbox(const char *title, const char *tbuf, int initial_height, |
52 | int initial_height, int initial_width) | 54 | int initial_width, int *keys) |
53 | { | 55 | { |
54 | int i, x, y, cur_x, cur_y, key = 0; | 56 | int i, x, y, cur_x, cur_y, key = 0; |
55 | int height, width, boxh, boxw; | 57 | int height, width, boxh, boxw; |
56 | int passed_end; | ||
57 | WINDOW *dialog, *box; | 58 | WINDOW *dialog, *box; |
59 | bool done = false; | ||
58 | 60 | ||
59 | begin_reached = 1; | 61 | begin_reached = 1; |
60 | end_reached = 0; | 62 | end_reached = 0; |
@@ -122,7 +124,7 @@ do_resize: | |||
122 | attr_clear(box, boxh, boxw, dlg.dialog.atr); | 124 | attr_clear(box, boxh, boxw, dlg.dialog.atr); |
123 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); | 125 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); |
124 | 126 | ||
125 | while ((key != KEY_ESC) && (key != '\n')) { | 127 | while (!done) { |
126 | key = wgetch(dialog); | 128 | key = wgetch(dialog); |
127 | switch (key) { | 129 | switch (key) { |
128 | case 'E': /* Exit */ | 130 | case 'E': /* Exit */ |
@@ -130,9 +132,9 @@ do_resize: | |||
130 | case 'X': | 132 | case 'X': |
131 | case 'x': | 133 | case 'x': |
132 | case 'q': | 134 | case 'q': |
133 | delwin(box); | 135 | case '\n': |
134 | delwin(dialog); | 136 | done = true; |
135 | return 0; | 137 | break; |
136 | case 'g': /* First page */ | 138 | case 'g': /* First page */ |
137 | case KEY_HOME: | 139 | case KEY_HOME: |
138 | if (!begin_reached) { | 140 | if (!begin_reached) { |
@@ -156,6 +158,8 @@ do_resize: | |||
156 | case 'k': | 158 | case 'k': |
157 | case KEY_UP: | 159 | case KEY_UP: |
158 | if (!begin_reached) { | 160 | if (!begin_reached) { |
161 | int passed_end = 0; | ||
162 | |||
159 | back_lines(page_length + 1); | 163 | back_lines(page_length + 1); |
160 | 164 | ||
161 | /* We don't call print_page() here but use | 165 | /* We don't call print_page() here but use |
@@ -169,7 +173,6 @@ do_resize: | |||
169 | wscrl(box, -1); /* Scroll box region down one line */ | 173 | wscrl(box, -1); /* Scroll box region down one line */ |
170 | scrollok(box, FALSE); | 174 | scrollok(box, FALSE); |
171 | page_length = 0; | 175 | page_length = 0; |
172 | passed_end = 0; | ||
173 | for (i = 0; i < boxh; i++) { | 176 | for (i = 0; i < boxh; i++) { |
174 | if (!i) { | 177 | if (!i) { |
175 | /* print first line of page */ | 178 | /* print first line of page */ |
@@ -252,7 +255,8 @@ do_resize: | |||
252 | cur_y, cur_x); | 255 | cur_y, cur_x); |
253 | break; | 256 | break; |
254 | case KEY_ESC: | 257 | case KEY_ESC: |
255 | key = on_key_esc(dialog); | 258 | if (on_key_esc(dialog) == KEY_ESC) |
259 | done = true; | ||
256 | break; | 260 | break; |
257 | case KEY_RESIZE: | 261 | case KEY_RESIZE: |
258 | back_lines(height); | 262 | back_lines(height); |
@@ -260,11 +264,18 @@ do_resize: | |||
260 | delwin(dialog); | 264 | delwin(dialog); |
261 | on_key_resize(); | 265 | on_key_resize(); |
262 | goto do_resize; | 266 | goto do_resize; |
267 | default: | ||
268 | for (i = 0; keys[i]; i++) { | ||
269 | if (key == keys[i]) { | ||
270 | done = true; | ||
271 | break; | ||
272 | } | ||
273 | } | ||
263 | } | 274 | } |
264 | } | 275 | } |
265 | delwin(box); | 276 | delwin(box); |
266 | delwin(dialog); | 277 | delwin(dialog); |
267 | return key; /* ESC pressed */ | 278 | return key; |
268 | } | 279 | } |
269 | 280 | ||
270 | /* | 281 | /* |
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index d856d40869e6..e097efb9c3ef 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c | |||
@@ -279,6 +279,8 @@ static void conf_choice(struct menu *menu); | |||
279 | static void conf_string(struct menu *menu); | 279 | static void conf_string(struct menu *menu); |
280 | static void conf_load(void); | 280 | static void conf_load(void); |
281 | static void conf_save(void); | 281 | static void conf_save(void); |
282 | static int show_textbox_ext(const char *title, const char *text, int r, int c, | ||
283 | int *keys); | ||
282 | static void show_textbox(const char *title, const char *text, int r, int c); | 284 | static void show_textbox(const char *title, const char *text, int r, int c); |
283 | static void show_helptext(const char *title, const char *text); | 285 | static void show_helptext(const char *title, const char *text); |
284 | static void show_help(struct menu *menu); | 286 | static void show_help(struct menu *menu); |
@@ -618,10 +620,16 @@ static void conf(struct menu *menu) | |||
618 | } | 620 | } |
619 | } | 621 | } |
620 | 622 | ||
621 | static void show_textbox(const char *title, const char *text, int r, int c) | 623 | static int show_textbox_ext(const char *title, const char *text, int r, int c, |
624 | int *keys) | ||
622 | { | 625 | { |
623 | dialog_clear(); | 626 | dialog_clear(); |
624 | dialog_textbox(title, text, r, c); | 627 | return dialog_textbox(title, text, r, c, keys); |
628 | } | ||
629 | |||
630 | static void show_textbox(const char *title, const char *text, int r, int c) | ||
631 | { | ||
632 | show_textbox_ext(title, text, r, c, (int []) {0}); | ||
625 | } | 633 | } |
626 | 634 | ||
627 | static void show_helptext(const char *title, const char *text) | 635 | static void show_helptext(const char *title, const char *text) |