diff options
author | Benjamin Poirier <bpoirier@suse.de> | 2012-08-23 14:55:08 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2012-09-27 12:09:24 -0400 |
commit | 95ac9b3b585d20df116c5bea1511d9eb5758ac81 (patch) | |
tree | c106d3003823ecbda997f295c75974385d560b9e /scripts/kconfig/lxdialog | |
parent | 1a374ae6191e9c440f1953a264a94d38173737be (diff) |
menuconfig: Assign jump keys per-page instead of globally
At the moment, keys 1-9 are assigned to the first 9 search results. This patch
makes them assigned to the first 9 results per-page instead. We are much less
likely to run out of keys that way.
Signed-off-by: Benjamin Poirier <bpoirier@suse.de>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts/kconfig/lxdialog')
-rw-r--r-- | scripts/kconfig/lxdialog/dialog.h | 9 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/textbox.c | 67 |
2 files changed, 49 insertions, 27 deletions
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index 2a01cdfae5a8..ee17a5264d5b 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h | |||
@@ -210,8 +210,13 @@ 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 | |
214 | int *keys, int *_vscroll, int *_hscroll); | 214 | |
215 | typedef void (*update_text_fn)(char *buf, size_t start, size_t end, void | ||
216 | *_data); | ||
217 | int dialog_textbox(const char *title, char *tbuf, int initial_height, | ||
218 | int initial_width, int *keys, int *_vscroll, int *_hscroll, | ||
219 | update_text_fn update_text, void *data); | ||
215 | int dialog_menu(const char *title, const char *prompt, | 220 | int dialog_menu(const char *title, const char *prompt, |
216 | const void *selected, int *s_scroll); | 221 | const void *selected, int *s_scroll); |
217 | int dialog_checklist(const char *title, const char *prompt, int height, | 222 | 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 3b3c5c470bf8..a48bb93e0907 100644 --- a/scripts/kconfig/lxdialog/textbox.c +++ b/scripts/kconfig/lxdialog/textbox.c | |||
@@ -22,23 +22,25 @@ | |||
22 | #include "dialog.h" | 22 | #include "dialog.h" |
23 | 23 | ||
24 | static void back_lines(int n); | 24 | static void back_lines(int n); |
25 | static void print_page(WINDOW * win, int height, int width); | 25 | static void print_page(WINDOW *win, int height, int width, update_text_fn |
26 | static void print_line(WINDOW * win, int row, int width); | 26 | update_text, void *data); |
27 | static void print_line(WINDOW *win, int row, int width); | ||
27 | static char *get_line(void); | 28 | static char *get_line(void); |
28 | static void print_position(WINDOW * win); | 29 | static void print_position(WINDOW * win); |
29 | 30 | ||
30 | static int hscroll; | 31 | static int hscroll; |
31 | static int begin_reached, end_reached, page_length; | 32 | static int begin_reached, end_reached, page_length; |
32 | static const char *buf; | 33 | static char *buf; |
33 | static const char *page; | 34 | static char *page; |
34 | 35 | ||
35 | /* | 36 | /* |
36 | * refresh window content | 37 | * refresh window content |
37 | */ | 38 | */ |
38 | static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, | 39 | static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, |
39 | int cur_y, int cur_x) | 40 | int cur_y, int cur_x, update_text_fn update_text, |
41 | void *data) | ||
40 | { | 42 | { |
41 | print_page(box, boxh, boxw); | 43 | print_page(box, boxh, boxw, update_text, data); |
42 | print_position(dialog); | 44 | print_position(dialog); |
43 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 45 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
44 | wrefresh(dialog); | 46 | wrefresh(dialog); |
@@ -49,9 +51,11 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, | |||
49 | * Display text from a file in a dialog box. | 51 | * Display text from a file in a dialog box. |
50 | * | 52 | * |
51 | * keys is a null-terminated array | 53 | * keys is a null-terminated array |
54 | * update_text() may not add or remove any '\n' or '\0' in tbuf | ||
52 | */ | 55 | */ |
53 | int dialog_textbox(const char *title, const char *tbuf, int initial_height, | 56 | int dialog_textbox(const char *title, char *tbuf, int initial_height, |
54 | int initial_width, int *keys, int *_vscroll, int *_hscroll) | 57 | int initial_width, int *keys, int *_vscroll, int *_hscroll, |
58 | update_text_fn update_text, void *data) | ||
55 | { | 59 | { |
56 | int i, x, y, cur_x, cur_y, key = 0; | 60 | int i, x, y, cur_x, cur_y, key = 0; |
57 | int height, width, boxh, boxw; | 61 | int height, width, boxh, boxw; |
@@ -131,7 +135,8 @@ do_resize: | |||
131 | 135 | ||
132 | /* Print first page of text */ | 136 | /* Print first page of text */ |
133 | attr_clear(box, boxh, boxw, dlg.dialog.atr); | 137 | attr_clear(box, boxh, boxw, dlg.dialog.atr); |
134 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); | 138 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x, update_text, |
139 | data); | ||
135 | 140 | ||
136 | while (!done) { | 141 | while (!done) { |
137 | key = wgetch(dialog); | 142 | key = wgetch(dialog); |
@@ -150,7 +155,8 @@ do_resize: | |||
150 | begin_reached = 1; | 155 | begin_reached = 1; |
151 | page = buf; | 156 | page = buf; |
152 | refresh_text_box(dialog, box, boxh, boxw, | 157 | refresh_text_box(dialog, box, boxh, boxw, |
153 | cur_y, cur_x); | 158 | cur_y, cur_x, update_text, |
159 | data); | ||
154 | } | 160 | } |
155 | break; | 161 | break; |
156 | case 'G': /* Last page */ | 162 | case 'G': /* Last page */ |
@@ -160,8 +166,8 @@ do_resize: | |||
160 | /* point to last char in buf */ | 166 | /* point to last char in buf */ |
161 | page = buf + strlen(buf); | 167 | page = buf + strlen(buf); |
162 | back_lines(boxh); | 168 | back_lines(boxh); |
163 | refresh_text_box(dialog, box, boxh, boxw, | 169 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
164 | cur_y, cur_x); | 170 | cur_x, update_text, data); |
165 | break; | 171 | break; |
166 | case 'K': /* Previous line */ | 172 | case 'K': /* Previous line */ |
167 | case 'k': | 173 | case 'k': |
@@ -171,7 +177,7 @@ do_resize: | |||
171 | 177 | ||
172 | back_lines(page_length + 1); | 178 | back_lines(page_length + 1); |
173 | refresh_text_box(dialog, box, boxh, boxw, cur_y, | 179 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
174 | cur_x); | 180 | cur_x, update_text, data); |
175 | break; | 181 | break; |
176 | case 'B': /* Previous page */ | 182 | case 'B': /* Previous page */ |
177 | case 'b': | 183 | case 'b': |
@@ -180,8 +186,8 @@ do_resize: | |||
180 | if (begin_reached) | 186 | if (begin_reached) |
181 | break; | 187 | break; |
182 | back_lines(page_length + boxh); | 188 | back_lines(page_length + boxh); |
183 | refresh_text_box(dialog, box, boxh, boxw, | 189 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
184 | cur_y, cur_x); | 190 | cur_x, update_text, data); |
185 | break; | 191 | break; |
186 | case 'J': /* Next line */ | 192 | case 'J': /* Next line */ |
187 | case 'j': | 193 | case 'j': |
@@ -191,7 +197,7 @@ do_resize: | |||
191 | 197 | ||
192 | back_lines(page_length - 1); | 198 | back_lines(page_length - 1); |
193 | refresh_text_box(dialog, box, boxh, boxw, cur_y, | 199 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
194 | cur_x); | 200 | cur_x, update_text, data); |
195 | break; | 201 | break; |
196 | case KEY_NPAGE: /* Next page */ | 202 | case KEY_NPAGE: /* Next page */ |
197 | case ' ': | 203 | case ' ': |
@@ -200,8 +206,8 @@ do_resize: | |||
200 | break; | 206 | break; |
201 | 207 | ||
202 | begin_reached = 0; | 208 | begin_reached = 0; |
203 | refresh_text_box(dialog, box, boxh, boxw, | 209 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
204 | cur_y, cur_x); | 210 | cur_x, update_text, data); |
205 | break; | 211 | break; |
206 | case '0': /* Beginning of line */ | 212 | case '0': /* Beginning of line */ |
207 | case 'H': /* Scroll left */ | 213 | case 'H': /* Scroll left */ |
@@ -216,8 +222,8 @@ do_resize: | |||
216 | hscroll--; | 222 | hscroll--; |
217 | /* Reprint current page to scroll horizontally */ | 223 | /* Reprint current page to scroll horizontally */ |
218 | back_lines(page_length); | 224 | back_lines(page_length); |
219 | refresh_text_box(dialog, box, boxh, boxw, | 225 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
220 | cur_y, cur_x); | 226 | cur_x, update_text, data); |
221 | break; | 227 | break; |
222 | case 'L': /* Scroll right */ | 228 | case 'L': /* Scroll right */ |
223 | case 'l': | 229 | case 'l': |
@@ -227,8 +233,8 @@ do_resize: | |||
227 | hscroll++; | 233 | hscroll++; |
228 | /* Reprint current page to scroll horizontally */ | 234 | /* Reprint current page to scroll horizontally */ |
229 | back_lines(page_length); | 235 | back_lines(page_length); |
230 | refresh_text_box(dialog, box, boxh, boxw, | 236 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
231 | cur_y, cur_x); | 237 | cur_x, update_text, data); |
232 | break; | 238 | break; |
233 | case KEY_ESC: | 239 | case KEY_ESC: |
234 | if (on_key_esc(dialog) == KEY_ESC) | 240 | if (on_key_esc(dialog) == KEY_ESC) |
@@ -301,12 +307,23 @@ static void back_lines(int n) | |||
301 | } | 307 | } |
302 | 308 | ||
303 | /* | 309 | /* |
304 | * Print a new page of text. Called by dialog_textbox(). | 310 | * Print a new page of text. |
305 | */ | 311 | */ |
306 | static void print_page(WINDOW * win, int height, int width) | 312 | static void print_page(WINDOW *win, int height, int width, update_text_fn |
313 | update_text, void *data) | ||
307 | { | 314 | { |
308 | int i, passed_end = 0; | 315 | int i, passed_end = 0; |
309 | 316 | ||
317 | if (update_text) { | ||
318 | char *end; | ||
319 | |||
320 | for (i = 0; i < height; i++) | ||
321 | get_line(); | ||
322 | end = page; | ||
323 | back_lines(height); | ||
324 | update_text(buf, page - buf, end - buf, data); | ||
325 | } | ||
326 | |||
310 | page_length = 0; | 327 | page_length = 0; |
311 | for (i = 0; i < height; i++) { | 328 | for (i = 0; i < height; i++) { |
312 | print_line(win, i, width); | 329 | print_line(win, i, width); |
@@ -319,7 +336,7 @@ static void print_page(WINDOW * win, int height, int width) | |||
319 | } | 336 | } |
320 | 337 | ||
321 | /* | 338 | /* |
322 | * Print a new line of text. Called by dialog_textbox() and print_page(). | 339 | * Print a new line of text. |
323 | */ | 340 | */ |
324 | static void print_line(WINDOW * win, int row, int width) | 341 | static void print_line(WINDOW * win, int row, int width) |
325 | { | 342 | { |