diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-11 21:28:52 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-11 21:28:52 -0400 |
commit | 35e9a274fdc9c8feb763e4970a32d7089f51393c (patch) | |
tree | d67ae81b870cb4531a92cbf44c07210f4ad124c7 /scripts/kconfig/lxdialog | |
parent | ae3e4628287de0ab90545c14076657aeee38506b (diff) | |
parent | fb16d8912db5268f29706010ecafff74b971c58d (diff) |
Merge branch 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild
Pull kconfig changes from Michal Marek:
"kconfig in v3.7 is going to
- initialize ncurses only once in menuconfig
- be able to jump to a search result in menuconfig
- change the misnomer oldnoconfig to a more meaningful name
olddefconfig, keeping the old name as alias"
* 'kconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/mmarek/kbuild:
kconfig: replace 'oldnoconfig' with 'olddefconfig', and keep the old name as an alias
menuconfig: Assign jump keys per-page instead of globally
menuconfig: Do not open code textbox scroll up/down
menuconfig: Add jump keys to search results
menuconfig: Extend dialog_textbox so that it can return to a scrolled position
menuconfig: Extend dialog_textbox so that it can exit on arbitrary keypresses
menuconfig: Remove superfluous conditionnal
kconfig: document oldnoconfig to what it really does in conf.c
kconfig/mconf.c: revision of curses initialization.
Diffstat (limited to 'scripts/kconfig/lxdialog')
-rw-r--r-- | scripts/kconfig/lxdialog/dialog.h | 9 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/textbox.c | 171 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/util.c | 7 |
3 files changed, 108 insertions, 79 deletions
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index b5211fce0d94..ee17a5264d5b 100644 --- a/scripts/kconfig/lxdialog/dialog.h +++ b/scripts/kconfig/lxdialog/dialog.h | |||
@@ -144,6 +144,7 @@ struct dialog_info { | |||
144 | */ | 144 | */ |
145 | extern struct dialog_info dlg; | 145 | extern struct dialog_info dlg; |
146 | extern char dialog_input_result[]; | 146 | extern char dialog_input_result[]; |
147 | extern int saved_x, saved_y; /* Needed in signal handler in mconf.c */ | ||
147 | 148 | ||
148 | /* | 149 | /* |
149 | * Function prototypes | 150 | * Function prototypes |
@@ -209,7 +210,13 @@ int first_alpha(const char *string, const char *exempt); | |||
209 | 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); |
210 | int dialog_msgbox(const char *title, const char *prompt, int height, | 211 | int dialog_msgbox(const char *title, const char *prompt, int height, |
211 | int width, int pause); | 212 | int width, int pause); |
212 | int dialog_textbox(const char *title, const char *file, int height, int width); | 213 | |
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); | ||
213 | int dialog_menu(const char *title, const char *prompt, | 220 | int dialog_menu(const char *title, const char *prompt, |
214 | const void *selected, int *s_scroll); | 221 | const void *selected, int *s_scroll); |
215 | 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 4e5de60a0c0d..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); |
@@ -47,14 +49,18 @@ static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, | |||
47 | 49 | ||
48 | /* | 50 | /* |
49 | * Display text from a file in a dialog box. | 51 | * Display text from a file in a dialog box. |
52 | * | ||
53 | * keys is a null-terminated array | ||
54 | * update_text() may not add or remove any '\n' or '\0' in tbuf | ||
50 | */ | 55 | */ |
51 | int dialog_textbox(const char *title, const char *tbuf, | 56 | int dialog_textbox(const char *title, char *tbuf, int initial_height, |
52 | int initial_height, int initial_width) | 57 | int initial_width, int *keys, int *_vscroll, int *_hscroll, |
58 | update_text_fn update_text, void *data) | ||
53 | { | 59 | { |
54 | int i, x, y, cur_x, cur_y, key = 0; | 60 | int i, x, y, cur_x, cur_y, key = 0; |
55 | int height, width, boxh, boxw; | 61 | int height, width, boxh, boxw; |
56 | int passed_end; | ||
57 | WINDOW *dialog, *box; | 62 | WINDOW *dialog, *box; |
63 | bool done = false; | ||
58 | 64 | ||
59 | begin_reached = 1; | 65 | begin_reached = 1; |
60 | end_reached = 0; | 66 | end_reached = 0; |
@@ -63,6 +69,15 @@ int dialog_textbox(const char *title, const char *tbuf, | |||
63 | buf = tbuf; | 69 | buf = tbuf; |
64 | page = buf; /* page is pointer to start of page to be displayed */ | 70 | page = buf; /* page is pointer to start of page to be displayed */ |
65 | 71 | ||
72 | if (_vscroll && *_vscroll) { | ||
73 | begin_reached = 0; | ||
74 | |||
75 | for (i = 0; i < *_vscroll; i++) | ||
76 | get_line(); | ||
77 | } | ||
78 | if (_hscroll) | ||
79 | hscroll = *_hscroll; | ||
80 | |||
66 | do_resize: | 81 | do_resize: |
67 | getmaxyx(stdscr, height, width); | 82 | getmaxyx(stdscr, height, width); |
68 | if (height < 8 || width < 8) | 83 | if (height < 8 || width < 8) |
@@ -120,9 +135,10 @@ do_resize: | |||
120 | 135 | ||
121 | /* Print first page of text */ | 136 | /* Print first page of text */ |
122 | attr_clear(box, boxh, boxw, dlg.dialog.atr); | 137 | attr_clear(box, boxh, boxw, dlg.dialog.atr); |
123 | 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); | ||
124 | 140 | ||
125 | while ((key != KEY_ESC) && (key != '\n')) { | 141 | while (!done) { |
126 | key = wgetch(dialog); | 142 | key = wgetch(dialog); |
127 | switch (key) { | 143 | switch (key) { |
128 | case 'E': /* Exit */ | 144 | case 'E': /* Exit */ |
@@ -130,16 +146,17 @@ do_resize: | |||
130 | case 'X': | 146 | case 'X': |
131 | case 'x': | 147 | case 'x': |
132 | case 'q': | 148 | case 'q': |
133 | delwin(box); | 149 | case '\n': |
134 | delwin(dialog); | 150 | done = true; |
135 | return 0; | 151 | break; |
136 | case 'g': /* First page */ | 152 | case 'g': /* First page */ |
137 | case KEY_HOME: | 153 | case KEY_HOME: |
138 | if (!begin_reached) { | 154 | if (!begin_reached) { |
139 | begin_reached = 1; | 155 | begin_reached = 1; |
140 | page = buf; | 156 | page = buf; |
141 | refresh_text_box(dialog, box, boxh, boxw, | 157 | refresh_text_box(dialog, box, boxh, boxw, |
142 | cur_y, cur_x); | 158 | cur_y, cur_x, update_text, |
159 | data); | ||
143 | } | 160 | } |
144 | break; | 161 | break; |
145 | case 'G': /* Last page */ | 162 | case 'G': /* Last page */ |
@@ -149,45 +166,18 @@ do_resize: | |||
149 | /* point to last char in buf */ | 166 | /* point to last char in buf */ |
150 | page = buf + strlen(buf); | 167 | page = buf + strlen(buf); |
151 | back_lines(boxh); | 168 | back_lines(boxh); |
152 | refresh_text_box(dialog, box, boxh, boxw, | 169 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
153 | cur_y, cur_x); | 170 | cur_x, update_text, data); |
154 | break; | 171 | break; |
155 | case 'K': /* Previous line */ | 172 | case 'K': /* Previous line */ |
156 | case 'k': | 173 | case 'k': |
157 | case KEY_UP: | 174 | case KEY_UP: |
158 | if (!begin_reached) { | 175 | if (begin_reached) |
159 | back_lines(page_length + 1); | 176 | break; |
160 | |||
161 | /* We don't call print_page() here but use | ||
162 | * scrolling to ensure faster screen update. | ||
163 | * However, 'end_reached' and 'page_length' | ||
164 | * should still be updated, and 'page' should | ||
165 | * point to start of next page. This is done | ||
166 | * by calling get_line() in the following | ||
167 | * 'for' loop. */ | ||
168 | scrollok(box, TRUE); | ||
169 | wscrl(box, -1); /* Scroll box region down one line */ | ||
170 | scrollok(box, FALSE); | ||
171 | page_length = 0; | ||
172 | passed_end = 0; | ||
173 | for (i = 0; i < boxh; i++) { | ||
174 | if (!i) { | ||
175 | /* print first line of page */ | ||
176 | print_line(box, 0, boxw); | ||
177 | wnoutrefresh(box); | ||
178 | } else | ||
179 | /* Called to update 'end_reached' and 'page' */ | ||
180 | get_line(); | ||
181 | if (!passed_end) | ||
182 | page_length++; | ||
183 | if (end_reached && !passed_end) | ||
184 | passed_end = 1; | ||
185 | } | ||
186 | 177 | ||
187 | print_position(dialog); | 178 | back_lines(page_length + 1); |
188 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 179 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
189 | wrefresh(dialog); | 180 | cur_x, update_text, data); |
190 | } | ||
191 | break; | 181 | break; |
192 | case 'B': /* Previous page */ | 182 | case 'B': /* Previous page */ |
193 | case 'b': | 183 | case 'b': |
@@ -196,23 +186,18 @@ do_resize: | |||
196 | if (begin_reached) | 186 | if (begin_reached) |
197 | break; | 187 | break; |
198 | back_lines(page_length + boxh); | 188 | back_lines(page_length + boxh); |
199 | refresh_text_box(dialog, box, boxh, boxw, | 189 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
200 | cur_y, cur_x); | 190 | cur_x, update_text, data); |
201 | break; | 191 | break; |
202 | case 'J': /* Next line */ | 192 | case 'J': /* Next line */ |
203 | case 'j': | 193 | case 'j': |
204 | case KEY_DOWN: | 194 | case KEY_DOWN: |
205 | if (!end_reached) { | 195 | if (end_reached) |
206 | begin_reached = 0; | 196 | break; |
207 | scrollok(box, TRUE); | 197 | |
208 | scroll(box); /* Scroll box region up one line */ | 198 | back_lines(page_length - 1); |
209 | scrollok(box, FALSE); | 199 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
210 | print_line(box, boxh - 1, boxw); | 200 | cur_x, update_text, data); |
211 | wnoutrefresh(box); | ||
212 | print_position(dialog); | ||
213 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | ||
214 | wrefresh(dialog); | ||
215 | } | ||
216 | break; | 201 | break; |
217 | case KEY_NPAGE: /* Next page */ | 202 | case KEY_NPAGE: /* Next page */ |
218 | case ' ': | 203 | case ' ': |
@@ -221,8 +206,8 @@ do_resize: | |||
221 | break; | 206 | break; |
222 | 207 | ||
223 | begin_reached = 0; | 208 | begin_reached = 0; |
224 | refresh_text_box(dialog, box, boxh, boxw, | 209 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
225 | cur_y, cur_x); | 210 | cur_x, update_text, data); |
226 | break; | 211 | break; |
227 | case '0': /* Beginning of line */ | 212 | case '0': /* Beginning of line */ |
228 | case 'H': /* Scroll left */ | 213 | case 'H': /* Scroll left */ |
@@ -237,8 +222,8 @@ do_resize: | |||
237 | hscroll--; | 222 | hscroll--; |
238 | /* Reprint current page to scroll horizontally */ | 223 | /* Reprint current page to scroll horizontally */ |
239 | back_lines(page_length); | 224 | back_lines(page_length); |
240 | refresh_text_box(dialog, box, boxh, boxw, | 225 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
241 | cur_y, cur_x); | 226 | cur_x, update_text, data); |
242 | break; | 227 | break; |
243 | case 'L': /* Scroll right */ | 228 | case 'L': /* Scroll right */ |
244 | case 'l': | 229 | case 'l': |
@@ -248,11 +233,12 @@ do_resize: | |||
248 | hscroll++; | 233 | hscroll++; |
249 | /* Reprint current page to scroll horizontally */ | 234 | /* Reprint current page to scroll horizontally */ |
250 | back_lines(page_length); | 235 | back_lines(page_length); |
251 | refresh_text_box(dialog, box, boxh, boxw, | 236 | refresh_text_box(dialog, box, boxh, boxw, cur_y, |
252 | cur_y, cur_x); | 237 | cur_x, update_text, data); |
253 | break; | 238 | break; |
254 | case KEY_ESC: | 239 | case KEY_ESC: |
255 | key = on_key_esc(dialog); | 240 | if (on_key_esc(dialog) == KEY_ESC) |
241 | done = true; | ||
256 | break; | 242 | break; |
257 | case KEY_RESIZE: | 243 | case KEY_RESIZE: |
258 | back_lines(height); | 244 | back_lines(height); |
@@ -260,11 +246,31 @@ do_resize: | |||
260 | delwin(dialog); | 246 | delwin(dialog); |
261 | on_key_resize(); | 247 | on_key_resize(); |
262 | goto do_resize; | 248 | goto do_resize; |
249 | default: | ||
250 | for (i = 0; keys[i]; i++) { | ||
251 | if (key == keys[i]) { | ||
252 | done = true; | ||
253 | break; | ||
254 | } | ||
255 | } | ||
263 | } | 256 | } |
264 | } | 257 | } |
265 | delwin(box); | 258 | delwin(box); |
266 | delwin(dialog); | 259 | delwin(dialog); |
267 | return key; /* ESC pressed */ | 260 | if (_vscroll) { |
261 | const char *s; | ||
262 | |||
263 | s = buf; | ||
264 | *_vscroll = 0; | ||
265 | back_lines(page_length); | ||
266 | while (s < page && (s = strchr(s, '\n'))) { | ||
267 | (*_vscroll)++; | ||
268 | s++; | ||
269 | } | ||
270 | } | ||
271 | if (_hscroll) | ||
272 | *_hscroll = hscroll; | ||
273 | return key; | ||
268 | } | 274 | } |
269 | 275 | ||
270 | /* | 276 | /* |
@@ -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 | { |
@@ -357,10 +374,8 @@ static char *get_line(void) | |||
357 | end_reached = 0; | 374 | end_reached = 0; |
358 | while (*page != '\n') { | 375 | while (*page != '\n') { |
359 | if (*page == '\0') { | 376 | if (*page == '\0') { |
360 | if (!end_reached) { | 377 | end_reached = 1; |
361 | end_reached = 1; | 378 | break; |
362 | break; | ||
363 | } | ||
364 | } else if (i < MAX_LEN) | 379 | } else if (i < MAX_LEN) |
365 | line[i++] = *(page++); | 380 | line[i++] = *(page++); |
366 | else { | 381 | else { |
@@ -373,7 +388,7 @@ static char *get_line(void) | |||
373 | if (i <= MAX_LEN) | 388 | if (i <= MAX_LEN) |
374 | line[i] = '\0'; | 389 | line[i] = '\0'; |
375 | if (!end_reached) | 390 | if (!end_reached) |
376 | page++; /* move pass '\n' */ | 391 | page++; /* move past '\n' */ |
377 | 392 | ||
378 | return line; | 393 | return line; |
379 | } | 394 | } |
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index f2375ad7ebc9..109d53117d22 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c | |||
@@ -23,6 +23,9 @@ | |||
23 | 23 | ||
24 | #include "dialog.h" | 24 | #include "dialog.h" |
25 | 25 | ||
26 | /* Needed in signal handler in mconf.c */ | ||
27 | int saved_x, saved_y; | ||
28 | |||
26 | struct dialog_info dlg; | 29 | struct dialog_info dlg; |
27 | 30 | ||
28 | static void set_mono_theme(void) | 31 | static void set_mono_theme(void) |
@@ -273,6 +276,10 @@ int init_dialog(const char *backtitle) | |||
273 | int height, width; | 276 | int height, width; |
274 | 277 | ||
275 | initscr(); /* Init curses */ | 278 | initscr(); /* Init curses */ |
279 | |||
280 | /* Get current cursor position for signal handler in mconf.c */ | ||
281 | getyx(stdscr, saved_y, saved_x); | ||
282 | |||
276 | getmaxyx(stdscr, height, width); | 283 | getmaxyx(stdscr, height, width); |
277 | if (height < 19 || width < 80) { | 284 | if (height < 19 || width < 80) { |
278 | endwin(); | 285 | endwin(); |