diff options
Diffstat (limited to 'scripts/kconfig/lxdialog')
-rw-r--r-- | scripts/kconfig/lxdialog/Makefile | 21 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/checklist.c | 183 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/colors.h | 154 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/dialog.h | 144 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/inputbox.c | 48 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/lxdialog.c | 204 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/menubox.c | 166 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/msgbox.c | 71 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/textbox.c | 416 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/util.c | 502 | ||||
-rw-r--r-- | scripts/kconfig/lxdialog/yesno.c | 26 |
11 files changed, 846 insertions, 1089 deletions
diff --git a/scripts/kconfig/lxdialog/Makefile b/scripts/kconfig/lxdialog/Makefile deleted file mode 100644 index a8b026326247..000000000000 --- a/scripts/kconfig/lxdialog/Makefile +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | # Makefile to build lxdialog package | ||
2 | # | ||
3 | |||
4 | check-lxdialog := $(srctree)/$(src)/check-lxdialog.sh | ||
5 | |||
6 | # Use reursively expanded variables so we do not call gcc unless | ||
7 | # we really need to do so. (Do not call gcc as part of make mrproper) | ||
8 | HOST_EXTRACFLAGS = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ccflags) | ||
9 | HOST_LOADLIBES = $(shell $(CONFIG_SHELL) $(check-lxdialog) -ldflags $(HOSTCC)) | ||
10 | |||
11 | HOST_EXTRACFLAGS += -DLOCALE | ||
12 | |||
13 | PHONY += dochecklxdialog | ||
14 | $(obj)/dochecklxdialog: | ||
15 | $(Q)$(CONFIG_SHELL) $(check-lxdialog) -check $(HOSTCC) $(HOST_LOADLIBES) | ||
16 | |||
17 | hostprogs-y := lxdialog | ||
18 | always := $(hostprogs-y) dochecklxdialog | ||
19 | |||
20 | lxdialog-objs := checklist.o menubox.o textbox.o yesno.o inputbox.o \ | ||
21 | util.o lxdialog.o msgbox.o | ||
diff --git a/scripts/kconfig/lxdialog/checklist.c b/scripts/kconfig/lxdialog/checklist.c index 79886413b6d5..cf697080dddd 100644 --- a/scripts/kconfig/lxdialog/checklist.c +++ b/scripts/kconfig/lxdialog/checklist.c | |||
@@ -28,25 +28,25 @@ static int list_width, check_x, item_x; | |||
28 | /* | 28 | /* |
29 | * Print list item | 29 | * Print list item |
30 | */ | 30 | */ |
31 | static void print_item(WINDOW * win, const char *item, int status, int choice, | 31 | static void print_item(WINDOW * win, int choice, int selected) |
32 | int selected) | ||
33 | { | 32 | { |
34 | int i; | 33 | int i; |
35 | 34 | ||
36 | /* Clear 'residue' of last item */ | 35 | /* Clear 'residue' of last item */ |
37 | wattrset(win, menubox_attr); | 36 | wattrset(win, dlg.menubox.atr); |
38 | wmove(win, choice, 0); | 37 | wmove(win, choice, 0); |
39 | for (i = 0; i < list_width; i++) | 38 | for (i = 0; i < list_width; i++) |
40 | waddch(win, ' '); | 39 | waddch(win, ' '); |
41 | 40 | ||
42 | wmove(win, choice, check_x); | 41 | wmove(win, choice, check_x); |
43 | wattrset(win, selected ? check_selected_attr : check_attr); | 42 | wattrset(win, selected ? dlg.check_selected.atr |
44 | wprintw(win, "(%c)", status ? 'X' : ' '); | 43 | : dlg.check.atr); |
45 | 44 | wprintw(win, "(%c)", item_is_tag('X') ? 'X' : ' '); | |
46 | wattrset(win, selected ? tag_selected_attr : tag_attr); | 45 | |
47 | mvwaddch(win, choice, item_x, item[0]); | 46 | wattrset(win, selected ? dlg.tag_selected.atr : dlg.tag.atr); |
48 | wattrset(win, selected ? item_selected_attr : item_attr); | 47 | mvwaddch(win, choice, item_x, item_str()[0]); |
49 | waddstr(win, (char *)item + 1); | 48 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); |
49 | waddstr(win, (char *)item_str() + 1); | ||
50 | if (selected) { | 50 | if (selected) { |
51 | wmove(win, choice, check_x + 1); | 51 | wmove(win, choice, check_x + 1); |
52 | wrefresh(win); | 52 | wrefresh(win); |
@@ -62,11 +62,11 @@ static void print_arrows(WINDOW * win, int choice, int item_no, int scroll, | |||
62 | wmove(win, y, x); | 62 | wmove(win, y, x); |
63 | 63 | ||
64 | if (scroll > 0) { | 64 | if (scroll > 0) { |
65 | wattrset(win, uarrow_attr); | 65 | wattrset(win, dlg.uarrow.atr); |
66 | waddch(win, ACS_UARROW); | 66 | waddch(win, ACS_UARROW); |
67 | waddstr(win, "(-)"); | 67 | waddstr(win, "(-)"); |
68 | } else { | 68 | } else { |
69 | wattrset(win, menubox_attr); | 69 | wattrset(win, dlg.menubox.atr); |
70 | waddch(win, ACS_HLINE); | 70 | waddch(win, ACS_HLINE); |
71 | waddch(win, ACS_HLINE); | 71 | waddch(win, ACS_HLINE); |
72 | waddch(win, ACS_HLINE); | 72 | waddch(win, ACS_HLINE); |
@@ -77,11 +77,11 @@ static void print_arrows(WINDOW * win, int choice, int item_no, int scroll, | |||
77 | wmove(win, y, x); | 77 | wmove(win, y, x); |
78 | 78 | ||
79 | if ((height < item_no) && (scroll + choice < item_no - 1)) { | 79 | if ((height < item_no) && (scroll + choice < item_no - 1)) { |
80 | wattrset(win, darrow_attr); | 80 | wattrset(win, dlg.darrow.atr); |
81 | waddch(win, ACS_DARROW); | 81 | waddch(win, ACS_DARROW); |
82 | waddstr(win, "(+)"); | 82 | waddstr(win, "(+)"); |
83 | } else { | 83 | } else { |
84 | wattrset(win, menubox_border_attr); | 84 | wattrset(win, dlg.menubox_border.atr); |
85 | waddch(win, ACS_HLINE); | 85 | waddch(win, ACS_HLINE); |
86 | waddch(win, ACS_HLINE); | 86 | waddch(win, ACS_HLINE); |
87 | waddch(win, ACS_HLINE); | 87 | waddch(win, ACS_HLINE); |
@@ -109,32 +109,29 @@ static void print_buttons(WINDOW * dialog, int height, int width, int selected) | |||
109 | * in the style of radiolist (only one option turned on at a time). | 109 | * in the style of radiolist (only one option turned on at a time). |
110 | */ | 110 | */ |
111 | int dialog_checklist(const char *title, const char *prompt, int height, | 111 | int dialog_checklist(const char *title, const char *prompt, int height, |
112 | int width, int list_height, int item_no, | 112 | int width, int list_height) |
113 | const char *const *items) | ||
114 | { | 113 | { |
115 | int i, x, y, box_x, box_y; | 114 | int i, x, y, box_x, box_y; |
116 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; | 115 | int key = 0, button = 0, choice = 0, scroll = 0, max_choice; |
117 | WINDOW *dialog, *list; | 116 | WINDOW *dialog, *list; |
118 | 117 | ||
119 | /* Allocate space for storing item on/off status */ | 118 | /* which item to highlight */ |
120 | if ((status = malloc(sizeof(int) * item_no)) == NULL) { | 119 | item_foreach() { |
121 | endwin(); | 120 | if (item_is_tag('X')) |
122 | fprintf(stderr, | 121 | choice = item_n(); |
123 | "\nCan't allocate memory in dialog_checklist().\n"); | 122 | if (item_is_selected()) { |
124 | exit(-1); | 123 | choice = item_n(); |
124 | break; | ||
125 | } | ||
125 | } | 126 | } |
126 | 127 | ||
127 | /* Initializes status */ | 128 | do_resize: |
128 | for (i = 0; i < item_no; i++) { | 129 | if (getmaxy(stdscr) < (height + 6)) |
129 | status[i] = !strcasecmp(items[i * 3 + 2], "on"); | 130 | return -ERRDISPLAYTOOSMALL; |
130 | if ((!choice && status[i]) | 131 | if (getmaxx(stdscr) < (width + 6)) |
131 | || !strcasecmp(items[i * 3 + 2], "selected")) | 132 | return -ERRDISPLAYTOOSMALL; |
132 | choice = i + 1; | ||
133 | } | ||
134 | if (choice) | ||
135 | choice--; | ||
136 | 133 | ||
137 | max_choice = MIN(list_height, item_no); | 134 | max_choice = MIN(list_height, item_count()); |
138 | 135 | ||
139 | /* center dialog box on screen */ | 136 | /* center dialog box on screen */ |
140 | x = (COLS - width) / 2; | 137 | x = (COLS - width) / 2; |
@@ -145,17 +142,18 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
145 | dialog = newwin(height, width, y, x); | 142 | dialog = newwin(height, width, y, x); |
146 | keypad(dialog, TRUE); | 143 | keypad(dialog, TRUE); |
147 | 144 | ||
148 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | 145 | draw_box(dialog, 0, 0, height, width, |
149 | wattrset(dialog, border_attr); | 146 | dlg.dialog.atr, dlg.border.atr); |
147 | wattrset(dialog, dlg.border.atr); | ||
150 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 148 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
151 | for (i = 0; i < width - 2; i++) | 149 | for (i = 0; i < width - 2; i++) |
152 | waddch(dialog, ACS_HLINE); | 150 | waddch(dialog, ACS_HLINE); |
153 | wattrset(dialog, dialog_attr); | 151 | wattrset(dialog, dlg.dialog.atr); |
154 | waddch(dialog, ACS_RTEE); | 152 | waddch(dialog, ACS_RTEE); |
155 | 153 | ||
156 | print_title(dialog, title, width); | 154 | print_title(dialog, title, width); |
157 | 155 | ||
158 | wattrset(dialog, dialog_attr); | 156 | wattrset(dialog, dlg.dialog.atr); |
159 | print_autowrap(dialog, prompt, width - 2, 1, 3); | 157 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
160 | 158 | ||
161 | list_width = width - 6; | 159 | list_width = width - 6; |
@@ -170,12 +168,12 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
170 | 168 | ||
171 | /* draw a box around the list items */ | 169 | /* draw a box around the list items */ |
172 | draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, | 170 | draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2, |
173 | menubox_border_attr, menubox_attr); | 171 | dlg.menubox_border.atr, dlg.menubox.atr); |
174 | 172 | ||
175 | /* Find length of longest item in order to center checklist */ | 173 | /* Find length of longest item in order to center checklist */ |
176 | check_x = 0; | 174 | check_x = 0; |
177 | for (i = 0; i < item_no; i++) | 175 | item_foreach() |
178 | check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4); | 176 | check_x = MAX(check_x, strlen(item_str()) + 4); |
179 | 177 | ||
180 | check_x = (list_width - check_x) / 2; | 178 | check_x = (list_width - check_x) / 2; |
181 | item_x = check_x + 4; | 179 | item_x = check_x + 4; |
@@ -187,14 +185,11 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
187 | 185 | ||
188 | /* Print the list */ | 186 | /* Print the list */ |
189 | for (i = 0; i < max_choice; i++) { | 187 | for (i = 0; i < max_choice; i++) { |
190 | if (i != choice) | 188 | item_set(scroll + i); |
191 | print_item(list, items[(scroll + i) * 3 + 1], | 189 | print_item(list, i, i == choice); |
192 | status[i + scroll], i, 0); | ||
193 | } | 190 | } |
194 | print_item(list, items[(scroll + choice) * 3 + 1], | ||
195 | status[choice + scroll], choice, 1); | ||
196 | 191 | ||
197 | print_arrows(dialog, choice, item_no, scroll, | 192 | print_arrows(dialog, choice, item_count(), scroll, |
198 | box_y, box_x + check_x + 5, list_height); | 193 | box_y, box_x + check_x + 5, list_height); |
199 | 194 | ||
200 | print_buttons(dialog, height, width, 0); | 195 | print_buttons(dialog, height, width, 0); |
@@ -203,13 +198,14 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
203 | wnoutrefresh(list); | 198 | wnoutrefresh(list); |
204 | doupdate(); | 199 | doupdate(); |
205 | 200 | ||
206 | while (key != ESC) { | 201 | while (key != KEY_ESC) { |
207 | key = wgetch(dialog); | 202 | key = wgetch(dialog); |
208 | 203 | ||
209 | for (i = 0; i < max_choice; i++) | 204 | for (i = 0; i < max_choice; i++) { |
210 | if (toupper(key) == | 205 | item_set(i + scroll); |
211 | toupper(items[(scroll + i) * 3 + 1][0])) | 206 | if (toupper(key) == toupper(item_str()[0])) |
212 | break; | 207 | break; |
208 | } | ||
213 | 209 | ||
214 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || | 210 | if (i < max_choice || key == KEY_UP || key == KEY_DOWN || |
215 | key == '+' || key == '-') { | 211 | key == '+' || key == '-') { |
@@ -220,15 +216,16 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
220 | /* Scroll list down */ | 216 | /* Scroll list down */ |
221 | if (list_height > 1) { | 217 | if (list_height > 1) { |
222 | /* De-highlight current first item */ | 218 | /* De-highlight current first item */ |
223 | print_item(list, items[scroll * 3 + 1], | 219 | item_set(scroll); |
224 | status[scroll], 0, FALSE); | 220 | print_item(list, 0, FALSE); |
225 | scrollok(list, TRUE); | 221 | scrollok(list, TRUE); |
226 | wscrl(list, -1); | 222 | wscrl(list, -1); |
227 | scrollok(list, FALSE); | 223 | scrollok(list, FALSE); |
228 | } | 224 | } |
229 | scroll--; | 225 | scroll--; |
230 | print_item(list, items[scroll * 3 + 1], status[scroll], 0, TRUE); | 226 | item_set(scroll); |
231 | print_arrows(dialog, choice, item_no, | 227 | print_item(list, 0, TRUE); |
228 | print_arrows(dialog, choice, item_count(), | ||
232 | scroll, box_y, box_x + check_x + 5, list_height); | 229 | scroll, box_y, box_x + check_x + 5, list_height); |
233 | 230 | ||
234 | wnoutrefresh(dialog); | 231 | wnoutrefresh(dialog); |
@@ -239,23 +236,24 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
239 | i = choice - 1; | 236 | i = choice - 1; |
240 | } else if (key == KEY_DOWN || key == '+') { | 237 | } else if (key == KEY_DOWN || key == '+') { |
241 | if (choice == max_choice - 1) { | 238 | if (choice == max_choice - 1) { |
242 | if (scroll + choice >= item_no - 1) | 239 | if (scroll + choice >= item_count() - 1) |
243 | continue; | 240 | continue; |
244 | /* Scroll list up */ | 241 | /* Scroll list up */ |
245 | if (list_height > 1) { | 242 | if (list_height > 1) { |
246 | /* De-highlight current last item before scrolling up */ | 243 | /* De-highlight current last item before scrolling up */ |
247 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 244 | item_set(scroll + max_choice - 1); |
248 | status[scroll + max_choice - 1], | 245 | print_item(list, |
249 | max_choice - 1, FALSE); | 246 | max_choice - 1, |
247 | FALSE); | ||
250 | scrollok(list, TRUE); | 248 | scrollok(list, TRUE); |
251 | wscrl(list, 1); | 249 | wscrl(list, 1); |
252 | scrollok(list, FALSE); | 250 | scrollok(list, FALSE); |
253 | } | 251 | } |
254 | scroll++; | 252 | scroll++; |
255 | print_item(list, items[(scroll + max_choice - 1) * 3 + 1], | 253 | item_set(scroll + max_choice - 1); |
256 | status[scroll + max_choice - 1], max_choice - 1, TRUE); | 254 | print_item(list, max_choice - 1, TRUE); |
257 | 255 | ||
258 | print_arrows(dialog, choice, item_no, | 256 | print_arrows(dialog, choice, item_count(), |
259 | scroll, box_y, box_x + check_x + 5, list_height); | 257 | scroll, box_y, box_x + check_x + 5, list_height); |
260 | 258 | ||
261 | wnoutrefresh(dialog); | 259 | wnoutrefresh(dialog); |
@@ -267,12 +265,12 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
267 | } | 265 | } |
268 | if (i != choice) { | 266 | if (i != choice) { |
269 | /* De-highlight current item */ | 267 | /* De-highlight current item */ |
270 | print_item(list, items[(scroll + choice) * 3 + 1], | 268 | item_set(scroll + choice); |
271 | status[scroll + choice], choice, FALSE); | 269 | print_item(list, choice, FALSE); |
272 | /* Highlight new item */ | 270 | /* Highlight new item */ |
273 | choice = i; | 271 | choice = i; |
274 | print_item(list, items[(scroll + choice) * 3 + 1], | 272 | item_set(scroll + choice); |
275 | status[scroll + choice], choice, TRUE); | 273 | print_item(list, choice, TRUE); |
276 | wnoutrefresh(dialog); | 274 | wnoutrefresh(dialog); |
277 | wrefresh(list); | 275 | wrefresh(list); |
278 | } | 276 | } |
@@ -282,10 +280,19 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
282 | case 'H': | 280 | case 'H': |
283 | case 'h': | 281 | case 'h': |
284 | case '?': | 282 | case '?': |
285 | fprintf(stderr, "%s", items[(scroll + choice) * 3]); | 283 | button = 1; |
284 | /* fall-through */ | ||
285 | case 'S': | ||
286 | case 's': | ||
287 | case ' ': | ||
288 | case '\n': | ||
289 | item_foreach() | ||
290 | item_set_selected(0); | ||
291 | item_set(scroll + choice); | ||
292 | item_set_selected(1); | ||
293 | delwin(list); | ||
286 | delwin(dialog); | 294 | delwin(dialog); |
287 | free(status); | 295 | return button; |
288 | return 1; | ||
289 | case TAB: | 296 | case TAB: |
290 | case KEY_LEFT: | 297 | case KEY_LEFT: |
291 | case KEY_RIGHT: | 298 | case KEY_RIGHT: |
@@ -295,42 +302,24 @@ int dialog_checklist(const char *title, const char *prompt, int height, | |||
295 | print_buttons(dialog, height, width, button); | 302 | print_buttons(dialog, height, width, button); |
296 | wrefresh(dialog); | 303 | wrefresh(dialog); |
297 | break; | 304 | break; |
298 | case 'S': | ||
299 | case 's': | ||
300 | case ' ': | ||
301 | case '\n': | ||
302 | if (!button) { | ||
303 | if (!status[scroll + choice]) { | ||
304 | for (i = 0; i < item_no; i++) | ||
305 | status[i] = 0; | ||
306 | status[scroll + choice] = 1; | ||
307 | for (i = 0; i < max_choice; i++) | ||
308 | print_item(list, items[(scroll + i) * 3 + 1], | ||
309 | status[scroll + i], i, i == choice); | ||
310 | } | ||
311 | wnoutrefresh(dialog); | ||
312 | wrefresh(list); | ||
313 | |||
314 | for (i = 0; i < item_no; i++) | ||
315 | if (status[i]) | ||
316 | fprintf(stderr, "%s", items[i * 3]); | ||
317 | } else | ||
318 | fprintf(stderr, "%s", items[(scroll + choice) * 3]); | ||
319 | delwin(dialog); | ||
320 | free(status); | ||
321 | return button; | ||
322 | case 'X': | 305 | case 'X': |
323 | case 'x': | 306 | case 'x': |
324 | key = ESC; | 307 | key = KEY_ESC; |
325 | case ESC: | 308 | break; |
309 | case KEY_ESC: | ||
310 | key = on_key_esc(dialog); | ||
326 | break; | 311 | break; |
312 | case KEY_RESIZE: | ||
313 | delwin(list); | ||
314 | delwin(dialog); | ||
315 | on_key_resize(); | ||
316 | goto do_resize; | ||
327 | } | 317 | } |
328 | 318 | ||
329 | /* Now, update everything... */ | 319 | /* Now, update everything... */ |
330 | doupdate(); | 320 | doupdate(); |
331 | } | 321 | } |
332 | 322 | delwin(list); | |
333 | delwin(dialog); | 323 | delwin(dialog); |
334 | free(status); | 324 | return key; /* ESC pressed */ |
335 | return -1; /* ESC pressed */ | ||
336 | } | 325 | } |
diff --git a/scripts/kconfig/lxdialog/colors.h b/scripts/kconfig/lxdialog/colors.h deleted file mode 100644 index db071df12bbb..000000000000 --- a/scripts/kconfig/lxdialog/colors.h +++ /dev/null | |||
@@ -1,154 +0,0 @@ | |||
1 | /* | ||
2 | * colors.h -- color attribute definitions | ||
3 | * | ||
4 | * AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version 2 | ||
9 | * of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
19 | */ | ||
20 | |||
21 | /* | ||
22 | * Default color definitions | ||
23 | * | ||
24 | * *_FG = foreground | ||
25 | * *_BG = background | ||
26 | * *_HL = highlight? | ||
27 | */ | ||
28 | #define SCREEN_FG COLOR_CYAN | ||
29 | #define SCREEN_BG COLOR_BLUE | ||
30 | #define SCREEN_HL TRUE | ||
31 | |||
32 | #define SHADOW_FG COLOR_BLACK | ||
33 | #define SHADOW_BG COLOR_BLACK | ||
34 | #define SHADOW_HL TRUE | ||
35 | |||
36 | #define DIALOG_FG COLOR_BLACK | ||
37 | #define DIALOG_BG COLOR_WHITE | ||
38 | #define DIALOG_HL FALSE | ||
39 | |||
40 | #define TITLE_FG COLOR_YELLOW | ||
41 | #define TITLE_BG COLOR_WHITE | ||
42 | #define TITLE_HL TRUE | ||
43 | |||
44 | #define BORDER_FG COLOR_WHITE | ||
45 | #define BORDER_BG COLOR_WHITE | ||
46 | #define BORDER_HL TRUE | ||
47 | |||
48 | #define BUTTON_ACTIVE_FG COLOR_WHITE | ||
49 | #define BUTTON_ACTIVE_BG COLOR_BLUE | ||
50 | #define BUTTON_ACTIVE_HL TRUE | ||
51 | |||
52 | #define BUTTON_INACTIVE_FG COLOR_BLACK | ||
53 | #define BUTTON_INACTIVE_BG COLOR_WHITE | ||
54 | #define BUTTON_INACTIVE_HL FALSE | ||
55 | |||
56 | #define BUTTON_KEY_ACTIVE_FG COLOR_WHITE | ||
57 | #define BUTTON_KEY_ACTIVE_BG COLOR_BLUE | ||
58 | #define BUTTON_KEY_ACTIVE_HL TRUE | ||
59 | |||
60 | #define BUTTON_KEY_INACTIVE_FG COLOR_RED | ||
61 | #define BUTTON_KEY_INACTIVE_BG COLOR_WHITE | ||
62 | #define BUTTON_KEY_INACTIVE_HL FALSE | ||
63 | |||
64 | #define BUTTON_LABEL_ACTIVE_FG COLOR_YELLOW | ||
65 | #define BUTTON_LABEL_ACTIVE_BG COLOR_BLUE | ||
66 | #define BUTTON_LABEL_ACTIVE_HL TRUE | ||
67 | |||
68 | #define BUTTON_LABEL_INACTIVE_FG COLOR_BLACK | ||
69 | #define BUTTON_LABEL_INACTIVE_BG COLOR_WHITE | ||
70 | #define BUTTON_LABEL_INACTIVE_HL TRUE | ||
71 | |||
72 | #define INPUTBOX_FG COLOR_BLACK | ||
73 | #define INPUTBOX_BG COLOR_WHITE | ||
74 | #define INPUTBOX_HL FALSE | ||
75 | |||
76 | #define INPUTBOX_BORDER_FG COLOR_BLACK | ||
77 | #define INPUTBOX_BORDER_BG COLOR_WHITE | ||
78 | #define INPUTBOX_BORDER_HL FALSE | ||
79 | |||
80 | #define SEARCHBOX_FG COLOR_BLACK | ||
81 | #define SEARCHBOX_BG COLOR_WHITE | ||
82 | #define SEARCHBOX_HL FALSE | ||
83 | |||
84 | #define SEARCHBOX_TITLE_FG COLOR_YELLOW | ||
85 | #define SEARCHBOX_TITLE_BG COLOR_WHITE | ||
86 | #define SEARCHBOX_TITLE_HL TRUE | ||
87 | |||
88 | #define SEARCHBOX_BORDER_FG COLOR_WHITE | ||
89 | #define SEARCHBOX_BORDER_BG COLOR_WHITE | ||
90 | #define SEARCHBOX_BORDER_HL TRUE | ||
91 | |||
92 | #define POSITION_INDICATOR_FG COLOR_YELLOW | ||
93 | #define POSITION_INDICATOR_BG COLOR_WHITE | ||
94 | #define POSITION_INDICATOR_HL TRUE | ||
95 | |||
96 | #define MENUBOX_FG COLOR_BLACK | ||
97 | #define MENUBOX_BG COLOR_WHITE | ||
98 | #define MENUBOX_HL FALSE | ||
99 | |||
100 | #define MENUBOX_BORDER_FG COLOR_WHITE | ||
101 | #define MENUBOX_BORDER_BG COLOR_WHITE | ||
102 | #define MENUBOX_BORDER_HL TRUE | ||
103 | |||
104 | #define ITEM_FG COLOR_BLACK | ||
105 | #define ITEM_BG COLOR_WHITE | ||
106 | #define ITEM_HL FALSE | ||
107 | |||
108 | #define ITEM_SELECTED_FG COLOR_WHITE | ||
109 | #define ITEM_SELECTED_BG COLOR_BLUE | ||
110 | #define ITEM_SELECTED_HL TRUE | ||
111 | |||
112 | #define TAG_FG COLOR_YELLOW | ||
113 | #define TAG_BG COLOR_WHITE | ||
114 | #define TAG_HL TRUE | ||
115 | |||
116 | #define TAG_SELECTED_FG COLOR_YELLOW | ||
117 | #define TAG_SELECTED_BG COLOR_BLUE | ||
118 | #define TAG_SELECTED_HL TRUE | ||
119 | |||
120 | #define TAG_KEY_FG COLOR_YELLOW | ||
121 | #define TAG_KEY_BG COLOR_WHITE | ||
122 | #define TAG_KEY_HL TRUE | ||
123 | |||
124 | #define TAG_KEY_SELECTED_FG COLOR_YELLOW | ||
125 | #define TAG_KEY_SELECTED_BG COLOR_BLUE | ||
126 | #define TAG_KEY_SELECTED_HL TRUE | ||
127 | |||
128 | #define CHECK_FG COLOR_BLACK | ||
129 | #define CHECK_BG COLOR_WHITE | ||
130 | #define CHECK_HL FALSE | ||
131 | |||
132 | #define CHECK_SELECTED_FG COLOR_WHITE | ||
133 | #define CHECK_SELECTED_BG COLOR_BLUE | ||
134 | #define CHECK_SELECTED_HL TRUE | ||
135 | |||
136 | #define UARROW_FG COLOR_GREEN | ||
137 | #define UARROW_BG COLOR_WHITE | ||
138 | #define UARROW_HL TRUE | ||
139 | |||
140 | #define DARROW_FG COLOR_GREEN | ||
141 | #define DARROW_BG COLOR_WHITE | ||
142 | #define DARROW_HL TRUE | ||
143 | |||
144 | /* End of default color definitions */ | ||
145 | |||
146 | #define C_ATTR(x,y) ((x ? A_BOLD : 0) | COLOR_PAIR((y))) | ||
147 | #define COLOR_NAME_LEN 10 | ||
148 | #define COLOR_COUNT 8 | ||
149 | |||
150 | /* | ||
151 | * Global variables | ||
152 | */ | ||
153 | |||
154 | extern int color_table[][3]; | ||
diff --git a/scripts/kconfig/lxdialog/dialog.h b/scripts/kconfig/lxdialog/dialog.h index af3cf716e215..8dea47f9d3e4 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) |
@@ -86,63 +86,111 @@ | |||
86 | #define ACS_DARROW 'v' | 86 | #define ACS_DARROW 'v' |
87 | #endif | 87 | #endif |
88 | 88 | ||
89 | /* error return codes */ | ||
90 | #define ERRDISPLAYTOOSMALL (KEY_MAX + 1) | ||
91 | |||
89 | /* | 92 | /* |
90 | * Attribute names | 93 | * Color definitions |
91 | */ | 94 | */ |
92 | #define screen_attr attributes[0] | 95 | struct dialog_color { |
93 | #define shadow_attr attributes[1] | 96 | chtype atr; /* Color attribute */ |
94 | #define dialog_attr attributes[2] | 97 | int fg; /* foreground */ |
95 | #define title_attr attributes[3] | 98 | int bg; /* background */ |
96 | #define border_attr attributes[4] | 99 | int hl; /* highlight this item */ |
97 | #define button_active_attr attributes[5] | 100 | }; |
98 | #define button_inactive_attr attributes[6] | 101 | |
99 | #define button_key_active_attr attributes[7] | 102 | struct dialog_info { |
100 | #define button_key_inactive_attr attributes[8] | 103 | const char *backtitle; |
101 | #define button_label_active_attr attributes[9] | 104 | struct dialog_color screen; |
102 | #define button_label_inactive_attr attributes[10] | 105 | struct dialog_color shadow; |
103 | #define inputbox_attr attributes[11] | 106 | struct dialog_color dialog; |
104 | #define inputbox_border_attr attributes[12] | 107 | struct dialog_color title; |
105 | #define searchbox_attr attributes[13] | 108 | struct dialog_color border; |
106 | #define searchbox_title_attr attributes[14] | 109 | struct dialog_color button_active; |
107 | #define searchbox_border_attr attributes[15] | 110 | struct dialog_color button_inactive; |
108 | #define position_indicator_attr attributes[16] | 111 | struct dialog_color button_key_active; |
109 | #define menubox_attr attributes[17] | 112 | struct dialog_color button_key_inactive; |
110 | #define menubox_border_attr attributes[18] | 113 | struct dialog_color button_label_active; |
111 | #define item_attr attributes[19] | 114 | struct dialog_color button_label_inactive; |
112 | #define item_selected_attr attributes[20] | 115 | struct dialog_color inputbox; |
113 | #define tag_attr attributes[21] | 116 | struct dialog_color inputbox_border; |
114 | #define tag_selected_attr attributes[22] | 117 | struct dialog_color searchbox; |
115 | #define tag_key_attr attributes[23] | 118 | struct dialog_color searchbox_title; |
116 | #define tag_key_selected_attr attributes[24] | 119 | struct dialog_color searchbox_border; |
117 | #define check_attr attributes[25] | 120 | struct dialog_color position_indicator; |
118 | #define check_selected_attr attributes[26] | 121 | struct dialog_color menubox; |
119 | #define uarrow_attr attributes[27] | 122 | struct dialog_color menubox_border; |
120 | #define darrow_attr attributes[28] | 123 | struct dialog_color item; |
121 | 124 | struct dialog_color item_selected; | |
122 | /* number of attributes */ | 125 | struct dialog_color tag; |
123 | #define ATTRIBUTE_COUNT 29 | 126 | struct dialog_color tag_selected; |
127 | struct dialog_color tag_key; | ||
128 | struct dialog_color tag_key_selected; | ||
129 | struct dialog_color check; | ||
130 | struct dialog_color check_selected; | ||
131 | struct dialog_color uarrow; | ||
132 | struct dialog_color darrow; | ||
133 | }; | ||
124 | 134 | ||
125 | /* | 135 | /* |
126 | * Global variables | 136 | * Global variables |
127 | */ | 137 | */ |
128 | extern bool use_colors; | 138 | extern struct dialog_info dlg; |
129 | extern bool use_shadow; | 139 | extern char dialog_input_result[]; |
130 | |||
131 | extern chtype attributes[]; | ||
132 | |||
133 | extern const char *backtitle; | ||
134 | 140 | ||
135 | /* | 141 | /* |
136 | * Function prototypes | 142 | * Function prototypes |
137 | */ | 143 | */ |
138 | extern void create_rc(const char *filename); | ||
139 | extern int parse_rc(void); | ||
140 | 144 | ||
141 | void init_dialog(void); | 145 | /* item list as used by checklist and menubox */ |
146 | void item_reset(void); | ||
147 | void item_make(const char *fmt, ...); | ||
148 | void item_add_str(const char *fmt, ...); | ||
149 | void item_set_tag(char tag); | ||
150 | void item_set_data(void *p); | ||
151 | void item_set_selected(int val); | ||
152 | int item_activate_selected(void); | ||
153 | void *item_data(void); | ||
154 | char item_tag(void); | ||
155 | |||
156 | /* item list manipulation for lxdialog use */ | ||
157 | #define MAXITEMSTR 200 | ||
158 | struct dialog_item { | ||
159 | char str[MAXITEMSTR]; /* promtp displayed */ | ||
160 | char tag; | ||
161 | void *data; /* pointer to menu item - used by menubox+checklist */ | ||
162 | int selected; /* Set to 1 by dialog_*() function if selected. */ | ||
163 | }; | ||
164 | |||
165 | /* list of lialog_items */ | ||
166 | struct dialog_list { | ||
167 | struct dialog_item node; | ||
168 | struct dialog_list *next; | ||
169 | }; | ||
170 | |||
171 | extern struct dialog_list *item_cur; | ||
172 | extern struct dialog_list item_nil; | ||
173 | extern struct dialog_list *item_head; | ||
174 | |||
175 | int item_count(void); | ||
176 | void item_set(int n); | ||
177 | int item_n(void); | ||
178 | const char *item_str(void); | ||
179 | int item_is_selected(void); | ||
180 | int item_is_tag(char tag); | ||
181 | #define item_foreach() \ | ||
182 | for (item_cur = item_head ? item_head: item_cur; \ | ||
183 | item_cur && (item_cur != &item_nil); item_cur = item_cur->next) | ||
184 | |||
185 | /* generic key handlers */ | ||
186 | int on_key_esc(WINDOW *win); | ||
187 | int on_key_resize(void); | ||
188 | |||
189 | void init_dialog(const char *backtitle); | ||
190 | void reset_dialog(void); | ||
142 | void end_dialog(void); | 191 | void end_dialog(void); |
143 | void attr_clear(WINDOW * win, int height, int width, chtype attr); | 192 | void attr_clear(WINDOW * win, int height, int width, chtype attr); |
144 | void dialog_clear(void); | 193 | void dialog_clear(void); |
145 | void color_setup(void); | ||
146 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); | 194 | void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x); |
147 | void print_button(WINDOW * win, const char *label, int y, int x, int selected); | 195 | void print_button(WINDOW * win, const char *label, int y, int x, int selected); |
148 | void print_title(WINDOW *dialog, const char *title, int width); | 196 | void print_title(WINDOW *dialog, const char *title, int width); |
@@ -155,12 +203,10 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width); | |||
155 | int dialog_msgbox(const char *title, const char *prompt, int height, | 203 | int dialog_msgbox(const char *title, const char *prompt, int height, |
156 | int width, int pause); | 204 | int width, int pause); |
157 | int dialog_textbox(const char *title, const char *file, int height, int width); | 205 | int dialog_textbox(const char *title, const char *file, int height, int width); |
158 | int dialog_menu(const char *title, const char *prompt, int height, int width, | 206 | int dialog_menu(const char *title, const char *prompt, |
159 | int menu_height, const char *choice, int item_no, | 207 | const void *selected, int *s_scroll); |
160 | const char *const *items); | ||
161 | int dialog_checklist(const char *title, const char *prompt, int height, | 208 | int dialog_checklist(const char *title, const char *prompt, int height, |
162 | int width, int list_height, int item_no, | 209 | int width, int list_height); |
163 | const char *const *items); | ||
164 | extern char dialog_input_result[]; | 210 | extern char dialog_input_result[]; |
165 | int dialog_inputbox(const char *title, const char *prompt, int height, | 211 | int dialog_inputbox(const char *title, const char *prompt, int height, |
166 | int width, const char *init); | 212 | int width, const char *init); |
diff --git a/scripts/kconfig/lxdialog/inputbox.c b/scripts/kconfig/lxdialog/inputbox.c index 779503726b0a..05e72066b359 100644 --- a/scripts/kconfig/lxdialog/inputbox.c +++ b/scripts/kconfig/lxdialog/inputbox.c | |||
@@ -49,6 +49,17 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
49 | char *instr = dialog_input_result; | 49 | char *instr = dialog_input_result; |
50 | WINDOW *dialog; | 50 | WINDOW *dialog; |
51 | 51 | ||
52 | if (!init) | ||
53 | instr[0] = '\0'; | ||
54 | else | ||
55 | strcpy(instr, init); | ||
56 | |||
57 | do_resize: | ||
58 | if (getmaxy(stdscr) <= (height - 2)) | ||
59 | return -ERRDISPLAYTOOSMALL; | ||
60 | if (getmaxx(stdscr) <= (width - 2)) | ||
61 | return -ERRDISPLAYTOOSMALL; | ||
62 | |||
52 | /* center dialog box on screen */ | 63 | /* center dialog box on screen */ |
53 | x = (COLS - width) / 2; | 64 | x = (COLS - width) / 2; |
54 | y = (LINES - height) / 2; | 65 | y = (LINES - height) / 2; |
@@ -58,17 +69,18 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
58 | dialog = newwin(height, width, y, x); | 69 | dialog = newwin(height, width, y, x); |
59 | keypad(dialog, TRUE); | 70 | keypad(dialog, TRUE); |
60 | 71 | ||
61 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | 72 | draw_box(dialog, 0, 0, height, width, |
62 | wattrset(dialog, border_attr); | 73 | dlg.dialog.atr, dlg.border.atr); |
74 | wattrset(dialog, dlg.border.atr); | ||
63 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 75 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
64 | for (i = 0; i < width - 2; i++) | 76 | for (i = 0; i < width - 2; i++) |
65 | waddch(dialog, ACS_HLINE); | 77 | waddch(dialog, ACS_HLINE); |
66 | wattrset(dialog, dialog_attr); | 78 | wattrset(dialog, dlg.dialog.atr); |
67 | waddch(dialog, ACS_RTEE); | 79 | waddch(dialog, ACS_RTEE); |
68 | 80 | ||
69 | print_title(dialog, title, width); | 81 | print_title(dialog, title, width); |
70 | 82 | ||
71 | wattrset(dialog, dialog_attr); | 83 | wattrset(dialog, dlg.dialog.atr); |
72 | print_autowrap(dialog, prompt, width - 2, 1, 3); | 84 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
73 | 85 | ||
74 | /* Draw the input field box */ | 86 | /* Draw the input field box */ |
@@ -76,18 +88,14 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
76 | getyx(dialog, y, x); | 88 | getyx(dialog, y, x); |
77 | box_y = y + 2; | 89 | box_y = y + 2; |
78 | box_x = (width - box_width) / 2; | 90 | box_x = (width - box_width) / 2; |
79 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, border_attr, dialog_attr); | 91 | draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2, |
92 | dlg.border.atr, dlg.dialog.atr); | ||
80 | 93 | ||
81 | print_buttons(dialog, height, width, 0); | 94 | print_buttons(dialog, height, width, 0); |
82 | 95 | ||
83 | /* Set up the initial value */ | 96 | /* Set up the initial value */ |
84 | wmove(dialog, box_y, box_x); | 97 | wmove(dialog, box_y, box_x); |
85 | wattrset(dialog, inputbox_attr); | 98 | wattrset(dialog, dlg.inputbox.atr); |
86 | |||
87 | if (!init) | ||
88 | instr[0] = '\0'; | ||
89 | else | ||
90 | strcpy(instr, init); | ||
91 | 99 | ||
92 | input_x = strlen(instr); | 100 | input_x = strlen(instr); |
93 | 101 | ||
@@ -104,7 +112,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
104 | 112 | ||
105 | wrefresh(dialog); | 113 | wrefresh(dialog); |
106 | 114 | ||
107 | while (key != ESC) { | 115 | while (key != KEY_ESC) { |
108 | key = wgetch(dialog); | 116 | key = wgetch(dialog); |
109 | 117 | ||
110 | if (button == -1) { /* Input box selected */ | 118 | if (button == -1) { /* Input box selected */ |
@@ -120,7 +128,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
120 | case KEY_BACKSPACE: | 128 | case KEY_BACKSPACE: |
121 | case 127: | 129 | case 127: |
122 | if (input_x || scroll) { | 130 | if (input_x || scroll) { |
123 | wattrset(dialog, inputbox_attr); | 131 | wattrset(dialog, dlg.inputbox.atr); |
124 | if (!input_x) { | 132 | if (!input_x) { |
125 | scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); | 133 | scroll = scroll < box_width - 1 ? 0 : scroll - (box_width - 1); |
126 | wmove(dialog, box_y, box_x); | 134 | wmove(dialog, box_y, box_x); |
@@ -140,7 +148,7 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
140 | default: | 148 | default: |
141 | if (key < 0x100 && isprint(key)) { | 149 | if (key < 0x100 && isprint(key)) { |
142 | if (scroll + input_x < MAX_LEN) { | 150 | if (scroll + input_x < MAX_LEN) { |
143 | wattrset(dialog, inputbox_attr); | 151 | wattrset(dialog, dlg.inputbox.atr); |
144 | instr[scroll + input_x] = key; | 152 | instr[scroll + input_x] = key; |
145 | instr[scroll + input_x + 1] = '\0'; | 153 | instr[scroll + input_x + 1] = '\0'; |
146 | if (input_x == box_width - 1) { | 154 | if (input_x == box_width - 1) { |
@@ -213,12 +221,18 @@ int dialog_inputbox(const char *title, const char *prompt, int height, int width | |||
213 | return (button == -1 ? 0 : button); | 221 | return (button == -1 ? 0 : button); |
214 | case 'X': | 222 | case 'X': |
215 | case 'x': | 223 | case 'x': |
216 | key = ESC; | 224 | key = KEY_ESC; |
217 | case ESC: | 225 | break; |
226 | case KEY_ESC: | ||
227 | key = on_key_esc(dialog); | ||
218 | break; | 228 | break; |
229 | case KEY_RESIZE: | ||
230 | delwin(dialog); | ||
231 | on_key_resize(); | ||
232 | goto do_resize; | ||
219 | } | 233 | } |
220 | } | 234 | } |
221 | 235 | ||
222 | delwin(dialog); | 236 | delwin(dialog); |
223 | return -1; /* ESC pressed */ | 237 | return KEY_ESC; /* ESC pressed */ |
224 | } | 238 | } |
diff --git a/scripts/kconfig/lxdialog/lxdialog.c b/scripts/kconfig/lxdialog/lxdialog.c deleted file mode 100644 index 79f6c5fb5cef..000000000000 --- a/scripts/kconfig/lxdialog/lxdialog.c +++ /dev/null | |||
@@ -1,204 +0,0 @@ | |||
1 | /* | ||
2 | * dialog - Display simple dialog boxes from shell scripts | ||
3 | * | ||
4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | ||
5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version 2 | ||
10 | * of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include "dialog.h" | ||
23 | |||
24 | static void Usage(const char *name); | ||
25 | |||
26 | typedef int (jumperFn) (const char *title, int argc, const char *const *argv); | ||
27 | |||
28 | struct Mode { | ||
29 | char *name; | ||
30 | int argmin, argmax, argmod; | ||
31 | jumperFn *jumper; | ||
32 | }; | ||
33 | |||
34 | jumperFn j_menu, j_radiolist, j_yesno, j_textbox, j_inputbox; | ||
35 | jumperFn j_msgbox, j_infobox; | ||
36 | |||
37 | static struct Mode modes[] = { | ||
38 | {"--menu", 9, 0, 3, j_menu}, | ||
39 | {"--radiolist", 9, 0, 3, j_radiolist}, | ||
40 | {"--yesno", 5, 5, 1, j_yesno}, | ||
41 | {"--textbox", 5, 5, 1, j_textbox}, | ||
42 | {"--inputbox", 5, 6, 1, j_inputbox}, | ||
43 | {"--msgbox", 5, 5, 1, j_msgbox}, | ||
44 | {"--infobox", 5, 5, 1, j_infobox}, | ||
45 | {NULL, 0, 0, 0, NULL} | ||
46 | }; | ||
47 | |||
48 | static struct Mode *modePtr; | ||
49 | |||
50 | #ifdef LOCALE | ||
51 | #include <locale.h> | ||
52 | #endif | ||
53 | |||
54 | int main(int argc, const char *const *argv) | ||
55 | { | ||
56 | int offset = 0, opt_clear = 0, end_common_opts = 0, retval; | ||
57 | const char *title = NULL; | ||
58 | |||
59 | #ifdef LOCALE | ||
60 | (void)setlocale(LC_ALL, ""); | ||
61 | #endif | ||
62 | |||
63 | #ifdef TRACE | ||
64 | trace(TRACE_CALLS | TRACE_UPDATE); | ||
65 | #endif | ||
66 | if (argc < 2) { | ||
67 | Usage(argv[0]); | ||
68 | exit(-1); | ||
69 | } | ||
70 | |||
71 | while (offset < argc - 1 && !end_common_opts) { /* Common options */ | ||
72 | if (!strcmp(argv[offset + 1], "--title")) { | ||
73 | if (argc - offset < 3 || title != NULL) { | ||
74 | Usage(argv[0]); | ||
75 | exit(-1); | ||
76 | } else { | ||
77 | title = argv[offset + 2]; | ||
78 | offset += 2; | ||
79 | } | ||
80 | } else if (!strcmp(argv[offset + 1], "--backtitle")) { | ||
81 | if (backtitle != NULL) { | ||
82 | Usage(argv[0]); | ||
83 | exit(-1); | ||
84 | } else { | ||
85 | backtitle = argv[offset + 2]; | ||
86 | offset += 2; | ||
87 | } | ||
88 | } else if (!strcmp(argv[offset + 1], "--clear")) { | ||
89 | if (opt_clear) { /* Hey, "--clear" can't appear twice! */ | ||
90 | Usage(argv[0]); | ||
91 | exit(-1); | ||
92 | } else if (argc == 2) { /* we only want to clear the screen */ | ||
93 | init_dialog(); | ||
94 | refresh(); /* init_dialog() will clear the screen for us */ | ||
95 | end_dialog(); | ||
96 | return 0; | ||
97 | } else { | ||
98 | opt_clear = 1; | ||
99 | offset++; | ||
100 | } | ||
101 | } else /* no more common options */ | ||
102 | end_common_opts = 1; | ||
103 | } | ||
104 | |||
105 | if (argc - 1 == offset) { /* no more options */ | ||
106 | Usage(argv[0]); | ||
107 | exit(-1); | ||
108 | } | ||
109 | /* use a table to look for the requested mode, to avoid code duplication */ | ||
110 | |||
111 | for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */ | ||
112 | if (!strcmp(argv[offset + 1], modePtr->name)) | ||
113 | break; | ||
114 | |||
115 | if (!modePtr->name) | ||
116 | Usage(argv[0]); | ||
117 | if (argc - offset < modePtr->argmin) | ||
118 | Usage(argv[0]); | ||
119 | if (modePtr->argmax && argc - offset > modePtr->argmax) | ||
120 | Usage(argv[0]); | ||
121 | |||
122 | init_dialog(); | ||
123 | retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); | ||
124 | |||
125 | if (opt_clear) { /* clear screen before exit */ | ||
126 | attr_clear(stdscr, LINES, COLS, screen_attr); | ||
127 | refresh(); | ||
128 | } | ||
129 | end_dialog(); | ||
130 | |||
131 | exit(retval); | ||
132 | } | ||
133 | |||
134 | /* | ||
135 | * Print program usage | ||
136 | */ | ||
137 | static void Usage(const char *name) | ||
138 | { | ||
139 | fprintf(stderr, "\ | ||
140 | \ndialog, by Savio Lam (lam836@cs.cuhk.hk).\ | ||
141 | \n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\ | ||
142 | \n modified/gutted for use as a Linux kernel config tool by \ | ||
143 | \n William Roadcap (roadcapw@cfw.com)\ | ||
144 | \n\ | ||
145 | \n* Display dialog boxes from shell scripts *\ | ||
146 | \n\ | ||
147 | \nUsage: %s --clear\ | ||
148 | \n %s [--title <title>] [--backtitle <backtitle>] --clear <Box options>\ | ||
149 | \n\ | ||
150 | \nBox options:\ | ||
151 | \n\ | ||
152 | \n --menu <text> <height> <width> <menu height> <tag1> <item1>...\ | ||
153 | \n --radiolist <text> <height> <width> <list height> <tag1> <item1> <status1>...\ | ||
154 | \n --textbox <file> <height> <width>\ | ||
155 | \n --inputbox <text> <height> <width> [<init>]\ | ||
156 | \n --yesno <text> <height> <width>\ | ||
157 | \n", name, name); | ||
158 | exit(-1); | ||
159 | } | ||
160 | |||
161 | /* | ||
162 | * These are the program jumpers | ||
163 | */ | ||
164 | |||
165 | int j_menu(const char *t, int ac, const char *const *av) | ||
166 | { | ||
167 | return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]), | ||
168 | atoi(av[5]), av[6], (ac - 6) / 2, av + 7); | ||
169 | } | ||
170 | |||
171 | int j_radiolist(const char *t, int ac, const char *const *av) | ||
172 | { | ||
173 | return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]), | ||
174 | atoi(av[5]), (ac - 6) / 3, av + 6); | ||
175 | } | ||
176 | |||
177 | int j_textbox(const char *t, int ac, const char *const *av) | ||
178 | { | ||
179 | return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4])); | ||
180 | } | ||
181 | |||
182 | int j_yesno(const char *t, int ac, const char *const *av) | ||
183 | { | ||
184 | return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4])); | ||
185 | } | ||
186 | |||
187 | int j_inputbox(const char *t, int ac, const char *const *av) | ||
188 | { | ||
189 | int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]), | ||
190 | ac == 6 ? av[5] : (char *)NULL); | ||
191 | if (ret == 0) | ||
192 | fprintf(stderr, dialog_input_result); | ||
193 | return ret; | ||
194 | } | ||
195 | |||
196 | int j_msgbox(const char *t, int ac, const char *const *av) | ||
197 | { | ||
198 | return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1); | ||
199 | } | ||
200 | |||
201 | int j_infobox(const char *t, int ac, const char *const *av) | ||
202 | { | ||
203 | return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0); | ||
204 | } | ||
diff --git a/scripts/kconfig/lxdialog/menubox.c b/scripts/kconfig/lxdialog/menubox.c index bf8052f4fd4a..0d83159d9012 100644 --- a/scripts/kconfig/lxdialog/menubox.c +++ b/scripts/kconfig/lxdialog/menubox.c | |||
@@ -63,19 +63,19 @@ static int menu_width, item_x; | |||
63 | /* | 63 | /* |
64 | * Print menu item | 64 | * Print menu item |
65 | */ | 65 | */ |
66 | static void do_print_item(WINDOW * win, const char *item, int choice, | 66 | static void do_print_item(WINDOW * win, const char *item, int line_y, |
67 | int selected, int hotkey) | 67 | int selected, int hotkey) |
68 | { | 68 | { |
69 | int j; | 69 | int j; |
70 | char *menu_item = malloc(menu_width + 1); | 70 | char *menu_item = malloc(menu_width + 1); |
71 | 71 | ||
72 | strncpy(menu_item, item, menu_width - item_x); | 72 | strncpy(menu_item, item, menu_width - item_x); |
73 | menu_item[menu_width] = 0; | 73 | menu_item[menu_width - item_x] = '\0'; |
74 | j = first_alpha(menu_item, "YyNnMmHh"); | 74 | j = first_alpha(menu_item, "YyNnMmHh"); |
75 | 75 | ||
76 | /* Clear 'residue' of last item */ | 76 | /* Clear 'residue' of last item */ |
77 | wattrset(win, menubox_attr); | 77 | wattrset(win, dlg.menubox.atr); |
78 | wmove(win, choice, 0); | 78 | wmove(win, line_y, 0); |
79 | #if OLD_NCURSES | 79 | #if OLD_NCURSES |
80 | { | 80 | { |
81 | int i; | 81 | int i; |
@@ -85,23 +85,24 @@ static void do_print_item(WINDOW * win, const char *item, int choice, | |||
85 | #else | 85 | #else |
86 | wclrtoeol(win); | 86 | wclrtoeol(win); |
87 | #endif | 87 | #endif |
88 | wattrset(win, selected ? item_selected_attr : item_attr); | 88 | wattrset(win, selected ? dlg.item_selected.atr : dlg.item.atr); |
89 | mvwaddstr(win, choice, item_x, menu_item); | 89 | mvwaddstr(win, line_y, item_x, menu_item); |
90 | if (hotkey) { | 90 | if (hotkey) { |
91 | wattrset(win, selected ? tag_key_selected_attr : tag_key_attr); | 91 | wattrset(win, selected ? dlg.tag_key_selected.atr |
92 | mvwaddch(win, choice, item_x + j, menu_item[j]); | 92 | : dlg.tag_key.atr); |
93 | mvwaddch(win, line_y, item_x + j, menu_item[j]); | ||
93 | } | 94 | } |
94 | if (selected) { | 95 | if (selected) { |
95 | wmove(win, choice, item_x + 1); | 96 | wmove(win, line_y, item_x + 1); |
96 | } | 97 | } |
97 | free(menu_item); | 98 | free(menu_item); |
98 | wrefresh(win); | 99 | wrefresh(win); |
99 | } | 100 | } |
100 | 101 | ||
101 | #define print_item(index, choice, selected) \ | 102 | #define print_item(index, choice, selected) \ |
102 | do {\ | 103 | do { \ |
103 | int hotkey = (items[(index) * 2][0] != ':'); \ | 104 | item_set(index); \ |
104 | do_print_item(menu, items[(index) * 2 + 1], choice, selected, hotkey); \ | 105 | do_print_item(menu, item_str(), choice, selected, !item_is_tag(':')); \ |
105 | } while (0) | 106 | } while (0) |
106 | 107 | ||
107 | /* | 108 | /* |
@@ -117,11 +118,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, | |||
117 | wmove(win, y, x); | 118 | wmove(win, y, x); |
118 | 119 | ||
119 | if (scroll > 0) { | 120 | if (scroll > 0) { |
120 | wattrset(win, uarrow_attr); | 121 | wattrset(win, dlg.uarrow.atr); |
121 | waddch(win, ACS_UARROW); | 122 | waddch(win, ACS_UARROW); |
122 | waddstr(win, "(-)"); | 123 | waddstr(win, "(-)"); |
123 | } else { | 124 | } else { |
124 | wattrset(win, menubox_attr); | 125 | wattrset(win, dlg.menubox.atr); |
125 | waddch(win, ACS_HLINE); | 126 | waddch(win, ACS_HLINE); |
126 | waddch(win, ACS_HLINE); | 127 | waddch(win, ACS_HLINE); |
127 | waddch(win, ACS_HLINE); | 128 | waddch(win, ACS_HLINE); |
@@ -133,11 +134,11 @@ static void print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, | |||
133 | wrefresh(win); | 134 | wrefresh(win); |
134 | 135 | ||
135 | if ((height < item_no) && (scroll + height < item_no)) { | 136 | if ((height < item_no) && (scroll + height < item_no)) { |
136 | wattrset(win, darrow_attr); | 137 | wattrset(win, dlg.darrow.atr); |
137 | waddch(win, ACS_DARROW); | 138 | waddch(win, ACS_DARROW); |
138 | waddstr(win, "(+)"); | 139 | waddstr(win, "(+)"); |
139 | } else { | 140 | } else { |
140 | wattrset(win, menubox_border_attr); | 141 | wattrset(win, dlg.menubox_border.atr); |
141 | waddch(win, ACS_HLINE); | 142 | waddch(win, ACS_HLINE); |
142 | waddch(win, ACS_HLINE); | 143 | waddch(win, ACS_HLINE); |
143 | waddch(win, ACS_HLINE); | 144 | waddch(win, ACS_HLINE); |
@@ -178,17 +179,26 @@ static void do_scroll(WINDOW *win, int *scroll, int n) | |||
178 | /* | 179 | /* |
179 | * Display a menu for choosing among a number of options | 180 | * Display a menu for choosing among a number of options |
180 | */ | 181 | */ |
181 | int dialog_menu(const char *title, const char *prompt, int height, int width, | 182 | int dialog_menu(const char *title, const char *prompt, |
182 | int menu_height, const char *current, int item_no, | 183 | const void *selected, int *s_scroll) |
183 | const char *const *items) | ||
184 | { | 184 | { |
185 | int i, j, x, y, box_x, box_y; | 185 | int i, j, x, y, box_x, box_y; |
186 | int height, width, menu_height; | ||
186 | int key = 0, button = 0, scroll = 0, choice = 0; | 187 | int key = 0, button = 0, scroll = 0, choice = 0; |
187 | int first_item = 0, max_choice; | 188 | int first_item = 0, max_choice; |
188 | WINDOW *dialog, *menu; | 189 | WINDOW *dialog, *menu; |
189 | FILE *f; | ||
190 | 190 | ||
191 | max_choice = MIN(menu_height, item_no); | 191 | do_resize: |
192 | height = getmaxy(stdscr); | ||
193 | width = getmaxx(stdscr); | ||
194 | if (height < 15 || width < 65) | ||
195 | return -ERRDISPLAYTOOSMALL; | ||
196 | |||
197 | height -= 4; | ||
198 | width -= 5; | ||
199 | menu_height = height - 10; | ||
200 | |||
201 | max_choice = MIN(menu_height, item_count()); | ||
192 | 202 | ||
193 | /* center dialog box on screen */ | 203 | /* center dialog box on screen */ |
194 | x = (COLS - width) / 2; | 204 | x = (COLS - width) / 2; |
@@ -199,18 +209,19 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
199 | dialog = newwin(height, width, y, x); | 209 | dialog = newwin(height, width, y, x); |
200 | keypad(dialog, TRUE); | 210 | keypad(dialog, TRUE); |
201 | 211 | ||
202 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | 212 | draw_box(dialog, 0, 0, height, width, |
203 | wattrset(dialog, border_attr); | 213 | dlg.dialog.atr, dlg.border.atr); |
214 | wattrset(dialog, dlg.border.atr); | ||
204 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 215 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
205 | for (i = 0; i < width - 2; i++) | 216 | for (i = 0; i < width - 2; i++) |
206 | waddch(dialog, ACS_HLINE); | 217 | waddch(dialog, ACS_HLINE); |
207 | wattrset(dialog, dialog_attr); | 218 | wattrset(dialog, dlg.dialog.atr); |
208 | wbkgdset(dialog, dialog_attr & A_COLOR); | 219 | wbkgdset(dialog, dlg.dialog.atr & A_COLOR); |
209 | waddch(dialog, ACS_RTEE); | 220 | waddch(dialog, ACS_RTEE); |
210 | 221 | ||
211 | print_title(dialog, title, width); | 222 | print_title(dialog, title, width); |
212 | 223 | ||
213 | wattrset(dialog, dialog_attr); | 224 | wattrset(dialog, dlg.dialog.atr); |
214 | print_autowrap(dialog, prompt, width - 2, 1, 3); | 225 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
215 | 226 | ||
216 | menu_width = width - 6; | 227 | menu_width = width - 6; |
@@ -224,33 +235,29 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
224 | 235 | ||
225 | /* draw a box around the menu items */ | 236 | /* draw a box around the menu items */ |
226 | draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, | 237 | draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2, |
227 | menubox_border_attr, menubox_attr); | 238 | dlg.menubox_border.atr, dlg.menubox.atr); |
228 | 239 | ||
229 | item_x = (menu_width - 70) / 2; | 240 | if (menu_width >= 80) |
241 | item_x = (menu_width - 70) / 2; | ||
242 | else | ||
243 | item_x = 4; | ||
230 | 244 | ||
231 | /* Set choice to default item */ | 245 | /* Set choice to default item */ |
232 | for (i = 0; i < item_no; i++) | 246 | item_foreach() |
233 | if (strcmp(current, items[i * 2]) == 0) | 247 | if (selected && (selected == item_data())) |
234 | choice = i; | 248 | choice = item_n(); |
235 | 249 | /* get the saved scroll info */ | |
236 | /* get the scroll info from the temp file */ | 250 | scroll = *s_scroll; |
237 | if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) { | 251 | if ((scroll <= choice) && (scroll + max_choice > choice) && |
238 | if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) && | 252 | (scroll >= 0) && (scroll + max_choice <= item_count())) { |
239 | (scroll + max_choice > choice) && (scroll >= 0) && | 253 | first_item = scroll; |
240 | (scroll + max_choice <= item_no)) { | 254 | choice = choice - scroll; |
241 | first_item = scroll; | 255 | } else { |
242 | choice = choice - scroll; | 256 | scroll = 0; |
243 | fclose(f); | ||
244 | } else { | ||
245 | scroll = 0; | ||
246 | remove("lxdialog.scrltmp"); | ||
247 | fclose(f); | ||
248 | f = NULL; | ||
249 | } | ||
250 | } | 257 | } |
251 | if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) { | 258 | if ((choice >= max_choice)) { |
252 | if (choice >= item_no - max_choice / 2) | 259 | if (choice >= item_count() - max_choice / 2) |
253 | scroll = first_item = item_no - max_choice; | 260 | scroll = first_item = item_count() - max_choice; |
254 | else | 261 | else |
255 | scroll = first_item = choice - max_choice / 2; | 262 | scroll = first_item = choice - max_choice / 2; |
256 | choice = choice - scroll; | 263 | choice = choice - scroll; |
@@ -263,14 +270,14 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
263 | 270 | ||
264 | wnoutrefresh(menu); | 271 | wnoutrefresh(menu); |
265 | 272 | ||
266 | print_arrows(dialog, item_no, scroll, | 273 | print_arrows(dialog, item_count(), scroll, |
267 | box_y, box_x + item_x + 1, menu_height); | 274 | box_y, box_x + item_x + 1, menu_height); |
268 | 275 | ||
269 | print_buttons(dialog, height, width, 0); | 276 | print_buttons(dialog, height, width, 0); |
270 | wmove(menu, choice, item_x + 1); | 277 | wmove(menu, choice, item_x + 1); |
271 | wrefresh(menu); | 278 | wrefresh(menu); |
272 | 279 | ||
273 | while (key != ESC) { | 280 | while (key != KEY_ESC) { |
274 | key = wgetch(menu); | 281 | key = wgetch(menu); |
275 | 282 | ||
276 | if (key < 256 && isalpha(key)) | 283 | if (key < 256 && isalpha(key)) |
@@ -280,14 +287,16 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
280 | i = max_choice; | 287 | i = max_choice; |
281 | else { | 288 | else { |
282 | for (i = choice + 1; i < max_choice; i++) { | 289 | for (i = choice + 1; i < max_choice; i++) { |
283 | j = first_alpha(items[(scroll + i) * 2 + 1], "YyNnMmHh"); | 290 | item_set(scroll + i); |
284 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) | 291 | j = first_alpha(item_str(), "YyNnMmHh"); |
292 | if (key == tolower(item_str()[j])) | ||
285 | break; | 293 | break; |
286 | } | 294 | } |
287 | if (i == max_choice) | 295 | if (i == max_choice) |
288 | for (i = 0; i < max_choice; i++) { | 296 | for (i = 0; i < max_choice; i++) { |
289 | j = first_alpha(items [(scroll + i) * 2 + 1], "YyNnMmHh"); | 297 | item_set(scroll + i); |
290 | if (key == tolower(items[(scroll + i) * 2 + 1][j])) | 298 | j = first_alpha(item_str(), "YyNnMmHh"); |
299 | if (key == tolower(item_str()[j])) | ||
291 | break; | 300 | break; |
292 | } | 301 | } |
293 | } | 302 | } |
@@ -312,7 +321,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
312 | print_item(scroll+choice, choice, FALSE); | 321 | print_item(scroll+choice, choice, FALSE); |
313 | 322 | ||
314 | if ((choice > max_choice - 3) && | 323 | if ((choice > max_choice - 3) && |
315 | (scroll + max_choice < item_no)) { | 324 | (scroll + max_choice < item_count())) { |
316 | /* Scroll menu up */ | 325 | /* Scroll menu up */ |
317 | do_scroll(menu, &scroll, 1); | 326 | do_scroll(menu, &scroll, 1); |
318 | 327 | ||
@@ -335,7 +344,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
335 | 344 | ||
336 | } else if (key == KEY_NPAGE) { | 345 | } else if (key == KEY_NPAGE) { |
337 | for (i = 0; (i < max_choice); i++) { | 346 | for (i = 0; (i < max_choice); i++) { |
338 | if (scroll + max_choice < item_no) { | 347 | if (scroll + max_choice < item_count()) { |
339 | do_scroll(menu, &scroll, 1); | 348 | do_scroll(menu, &scroll, 1); |
340 | print_item(scroll+max_choice-1, | 349 | print_item(scroll+max_choice-1, |
341 | max_choice - 1, FALSE); | 350 | max_choice - 1, FALSE); |
@@ -349,7 +358,7 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
349 | 358 | ||
350 | print_item(scroll + choice, choice, TRUE); | 359 | print_item(scroll + choice, choice, TRUE); |
351 | 360 | ||
352 | print_arrows(dialog, item_no, scroll, | 361 | print_arrows(dialog, item_count(), scroll, |
353 | box_y, box_x + item_x + 1, menu_height); | 362 | box_y, box_x + item_x + 1, menu_height); |
354 | 363 | ||
355 | wnoutrefresh(dialog); | 364 | wnoutrefresh(dialog); |
@@ -375,12 +384,11 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
375 | case 'm': | 384 | case 'm': |
376 | case '/': | 385 | case '/': |
377 | /* save scroll info */ | 386 | /* save scroll info */ |
378 | if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) { | 387 | *s_scroll = scroll; |
379 | fprintf(f, "%d\n", scroll); | 388 | delwin(menu); |
380 | fclose(f); | ||
381 | } | ||
382 | delwin(dialog); | 389 | delwin(dialog); |
383 | fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); | 390 | item_set(scroll + choice); |
391 | item_set_selected(1); | ||
384 | switch (key) { | 392 | switch (key) { |
385 | case 's': | 393 | case 's': |
386 | return 3; | 394 | return 3; |
@@ -400,27 +408,27 @@ int dialog_menu(const char *title, const char *prompt, int height, int width, | |||
400 | case '?': | 408 | case '?': |
401 | button = 2; | 409 | button = 2; |
402 | case '\n': | 410 | case '\n': |
411 | *s_scroll = scroll; | ||
412 | delwin(menu); | ||
403 | delwin(dialog); | 413 | delwin(dialog); |
404 | if (button == 2) | 414 | item_set(scroll + choice); |
405 | fprintf(stderr, "%s \"%s\"\n", | 415 | item_set_selected(1); |
406 | items[(scroll + choice) * 2], | ||
407 | items[(scroll + choice) * 2 + 1] + | ||
408 | first_alpha(items [(scroll + choice) * 2 + 1], "")); | ||
409 | else | ||
410 | fprintf(stderr, "%s\n", | ||
411 | items[(scroll + choice) * 2]); | ||
412 | |||
413 | remove("lxdialog.scrltmp"); | ||
414 | return button; | 416 | return button; |
415 | case 'e': | 417 | case 'e': |
416 | case 'x': | 418 | case 'x': |
417 | key = ESC; | 419 | key = KEY_ESC; |
418 | case ESC: | 420 | break; |
421 | case KEY_ESC: | ||
422 | key = on_key_esc(menu); | ||
419 | break; | 423 | break; |
424 | case KEY_RESIZE: | ||
425 | on_key_resize(); | ||
426 | delwin(menu); | ||
427 | delwin(dialog); | ||
428 | goto do_resize; | ||
420 | } | 429 | } |
421 | } | 430 | } |
422 | 431 | delwin(menu); | |
423 | delwin(dialog); | 432 | delwin(dialog); |
424 | remove("lxdialog.scrltmp"); | 433 | return key; /* ESC pressed */ |
425 | return -1; /* ESC pressed */ | ||
426 | } | 434 | } |
diff --git a/scripts/kconfig/lxdialog/msgbox.c b/scripts/kconfig/lxdialog/msgbox.c deleted file mode 100644 index 7323f5471f69..000000000000 --- a/scripts/kconfig/lxdialog/msgbox.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* | ||
2 | * msgbox.c -- implements the message box and info box | ||
3 | * | ||
4 | * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk) | ||
5 | * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcapw@cfw.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; either version 2 | ||
10 | * of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
20 | */ | ||
21 | |||
22 | #include "dialog.h" | ||
23 | |||
24 | /* | ||
25 | * Display a message box. Program will pause and display an "OK" button | ||
26 | * if the parameter 'pause' is non-zero. | ||
27 | */ | ||
28 | int dialog_msgbox(const char *title, const char *prompt, int height, int width, | ||
29 | int pause) | ||
30 | { | ||
31 | int i, x, y, key = 0; | ||
32 | WINDOW *dialog; | ||
33 | |||
34 | /* center dialog box on screen */ | ||
35 | x = (COLS - width) / 2; | ||
36 | y = (LINES - height) / 2; | ||
37 | |||
38 | draw_shadow(stdscr, y, x, height, width); | ||
39 | |||
40 | dialog = newwin(height, width, y, x); | ||
41 | keypad(dialog, TRUE); | ||
42 | |||
43 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | ||
44 | |||
45 | print_title(dialog, title, width); | ||
46 | |||
47 | wattrset(dialog, dialog_attr); | ||
48 | print_autowrap(dialog, prompt, width - 2, 1, 2); | ||
49 | |||
50 | if (pause) { | ||
51 | wattrset(dialog, border_attr); | ||
52 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | ||
53 | for (i = 0; i < width - 2; i++) | ||
54 | waddch(dialog, ACS_HLINE); | ||
55 | wattrset(dialog, dialog_attr); | ||
56 | waddch(dialog, ACS_RTEE); | ||
57 | |||
58 | print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE); | ||
59 | |||
60 | wrefresh(dialog); | ||
61 | while (key != ESC && key != '\n' && key != ' ' && | ||
62 | key != 'O' && key != 'o' && key != 'X' && key != 'x') | ||
63 | key = wgetch(dialog); | ||
64 | } else { | ||
65 | key = '\n'; | ||
66 | wrefresh(dialog); | ||
67 | } | ||
68 | |||
69 | delwin(dialog); | ||
70 | return key == ESC ? -1 : 0; | ||
71 | } | ||
diff --git a/scripts/kconfig/lxdialog/textbox.c b/scripts/kconfig/lxdialog/textbox.c index 77848bb8e07f..fabfc1ad789d 100644 --- a/scripts/kconfig/lxdialog/textbox.c +++ b/scripts/kconfig/lxdialog/textbox.c | |||
@@ -25,56 +25,62 @@ 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); |
26 | static void print_line(WINDOW * win, int row, int width); | 26 | static void print_line(WINDOW * win, int row, int width); |
27 | static char *get_line(void); | 27 | static char *get_line(void); |
28 | static void print_position(WINDOW * win, int height, int width); | 28 | static void print_position(WINDOW * win); |
29 | |||
30 | static int hscroll; | ||
31 | static int begin_reached, end_reached, page_length; | ||
32 | static const char *buf; | ||
33 | static const char *page; | ||
34 | |||
35 | /* | ||
36 | * refresh window content | ||
37 | */ | ||
38 | static void refresh_text_box(WINDOW *dialog, WINDOW *box, int boxh, int boxw, | ||
39 | int cur_y, int cur_x) | ||
40 | { | ||
41 | print_page(box, boxh, boxw); | ||
42 | print_position(dialog); | ||
43 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | ||
44 | wrefresh(dialog); | ||
45 | } | ||
29 | 46 | ||
30 | static int hscroll, fd, file_size, bytes_read; | ||
31 | static int begin_reached = 1, end_reached, page_length; | ||
32 | static char *buf, *page; | ||
33 | 47 | ||
34 | /* | 48 | /* |
35 | * Display text from a file in a dialog box. | 49 | * Display text from a file in a dialog box. |
36 | */ | 50 | */ |
37 | int dialog_textbox(const char *title, const char *file, int height, int width) | 51 | int dialog_textbox(const char *title, const char *tbuf, |
52 | int initial_height, int initial_width) | ||
38 | { | 53 | { |
39 | int i, x, y, cur_x, cur_y, fpos, key = 0; | 54 | int i, x, y, cur_x, cur_y, key = 0; |
55 | int height, width, boxh, boxw; | ||
40 | int passed_end; | 56 | int passed_end; |
41 | char search_term[MAX_LEN + 1]; | 57 | WINDOW *dialog, *box; |
42 | WINDOW *dialog, *text; | ||
43 | |||
44 | search_term[0] = '\0'; /* no search term entered yet */ | ||
45 | 58 | ||
46 | /* Open input file for reading */ | 59 | begin_reached = 1; |
47 | if ((fd = open(file, O_RDONLY)) == -1) { | 60 | end_reached = 0; |
48 | endwin(); | 61 | page_length = 0; |
49 | fprintf(stderr, "\nCan't open input file in dialog_textbox().\n"); | 62 | hscroll = 0; |
50 | exit(-1); | 63 | buf = tbuf; |
51 | } | 64 | page = buf; /* page is pointer to start of page to be displayed */ |
52 | /* Get file size. Actually, 'file_size' is the real file size - 1, | 65 | |
53 | since it's only the last byte offset from the beginning */ | 66 | do_resize: |
54 | if ((file_size = lseek(fd, 0, SEEK_END)) == -1) { | 67 | getmaxyx(stdscr, height, width); |
55 | endwin(); | 68 | if (height < 8 || width < 8) |
56 | fprintf(stderr, "\nError getting file size in dialog_textbox().\n"); | 69 | return -ERRDISPLAYTOOSMALL; |
57 | exit(-1); | 70 | if (initial_height != 0) |
58 | } | 71 | height = initial_height; |
59 | /* Restore file pointer to beginning of file after getting file size */ | 72 | else |
60 | if (lseek(fd, 0, SEEK_SET) == -1) { | 73 | if (height > 4) |
61 | endwin(); | 74 | height -= 4; |
62 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | 75 | else |
63 | exit(-1); | 76 | height = 0; |
64 | } | 77 | if (initial_width != 0) |
65 | /* Allocate space for read buffer */ | 78 | width = initial_width; |
66 | if ((buf = malloc(BUF_SIZE + 1)) == NULL) { | 79 | else |
67 | endwin(); | 80 | if (width > 5) |
68 | fprintf(stderr, "\nCan't allocate memory in dialog_textbox().\n"); | 81 | width -= 5; |
69 | exit(-1); | 82 | else |
70 | } | 83 | width = 0; |
71 | if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { | ||
72 | endwin(); | ||
73 | fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | ||
74 | exit(-1); | ||
75 | } | ||
76 | buf[bytes_read] = '\0'; /* mark end of valid data */ | ||
77 | page = buf; /* page is pointer to start of page to be displayed */ | ||
78 | 84 | ||
79 | /* center dialog box on screen */ | 85 | /* center dialog box on screen */ |
80 | x = (COLS - width) / 2; | 86 | x = (COLS - width) / 2; |
@@ -85,22 +91,25 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
85 | dialog = newwin(height, width, y, x); | 91 | dialog = newwin(height, width, y, x); |
86 | keypad(dialog, TRUE); | 92 | keypad(dialog, TRUE); |
87 | 93 | ||
88 | /* Create window for text region, used for scrolling text */ | 94 | /* Create window for box region, used for scrolling text */ |
89 | text = subwin(dialog, height - 4, width - 2, y + 1, x + 1); | 95 | boxh = height - 4; |
90 | wattrset(text, dialog_attr); | 96 | boxw = width - 2; |
91 | wbkgdset(text, dialog_attr & A_COLOR); | 97 | box = subwin(dialog, boxh, boxw, y + 1, x + 1); |
98 | wattrset(box, dlg.dialog.atr); | ||
99 | wbkgdset(box, dlg.dialog.atr & A_COLOR); | ||
92 | 100 | ||
93 | keypad(text, TRUE); | 101 | keypad(box, TRUE); |
94 | 102 | ||
95 | /* register the new window, along with its borders */ | 103 | /* register the new window, along with its borders */ |
96 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | 104 | draw_box(dialog, 0, 0, height, width, |
105 | dlg.dialog.atr, dlg.border.atr); | ||
97 | 106 | ||
98 | wattrset(dialog, border_attr); | 107 | wattrset(dialog, dlg.border.atr); |
99 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 108 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
100 | for (i = 0; i < width - 2; i++) | 109 | for (i = 0; i < width - 2; i++) |
101 | waddch(dialog, ACS_HLINE); | 110 | waddch(dialog, ACS_HLINE); |
102 | wattrset(dialog, dialog_attr); | 111 | wattrset(dialog, dlg.dialog.atr); |
103 | wbkgdset(dialog, dialog_attr & A_COLOR); | 112 | wbkgdset(dialog, dlg.dialog.atr & A_COLOR); |
104 | waddch(dialog, ACS_RTEE); | 113 | waddch(dialog, ACS_RTEE); |
105 | 114 | ||
106 | print_title(dialog, title, width); | 115 | print_title(dialog, title, width); |
@@ -110,85 +119,37 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
110 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ | 119 | getyx(dialog, cur_y, cur_x); /* Save cursor position */ |
111 | 120 | ||
112 | /* Print first page of text */ | 121 | /* Print first page of text */ |
113 | attr_clear(text, height - 4, width - 2, dialog_attr); | 122 | attr_clear(box, boxh, boxw, dlg.dialog.atr); |
114 | print_page(text, height - 4, width - 2); | 123 | refresh_text_box(dialog, box, boxh, boxw, cur_y, cur_x); |
115 | print_position(dialog, height, width); | ||
116 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | ||
117 | wrefresh(dialog); | ||
118 | 124 | ||
119 | while ((key != ESC) && (key != '\n')) { | 125 | while ((key != KEY_ESC) && (key != '\n')) { |
120 | key = wgetch(dialog); | 126 | key = wgetch(dialog); |
121 | switch (key) { | 127 | switch (key) { |
122 | case 'E': /* Exit */ | 128 | case 'E': /* Exit */ |
123 | case 'e': | 129 | case 'e': |
124 | case 'X': | 130 | case 'X': |
125 | case 'x': | 131 | case 'x': |
132 | delwin(box); | ||
126 | delwin(dialog); | 133 | delwin(dialog); |
127 | free(buf); | ||
128 | close(fd); | ||
129 | return 0; | 134 | return 0; |
130 | case 'g': /* First page */ | 135 | case 'g': /* First page */ |
131 | case KEY_HOME: | 136 | case KEY_HOME: |
132 | if (!begin_reached) { | 137 | if (!begin_reached) { |
133 | begin_reached = 1; | 138 | begin_reached = 1; |
134 | /* First page not in buffer? */ | ||
135 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | ||
136 | endwin(); | ||
137 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | ||
138 | exit(-1); | ||
139 | } | ||
140 | if (fpos > bytes_read) { /* Yes, we have to read it in */ | ||
141 | if (lseek(fd, 0, SEEK_SET) == -1) { | ||
142 | endwin(); | ||
143 | fprintf(stderr, "\nError moving file pointer in " | ||
144 | "dialog_textbox().\n"); | ||
145 | exit(-1); | ||
146 | } | ||
147 | if ((bytes_read = | ||
148 | read(fd, buf, BUF_SIZE)) == -1) { | ||
149 | endwin(); | ||
150 | fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | ||
151 | exit(-1); | ||
152 | } | ||
153 | buf[bytes_read] = '\0'; | ||
154 | } | ||
155 | page = buf; | 139 | page = buf; |
156 | print_page(text, height - 4, width - 2); | 140 | refresh_text_box(dialog, box, boxh, boxw, |
157 | print_position(dialog, height, width); | 141 | cur_y, cur_x); |
158 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | ||
159 | wrefresh(dialog); | ||
160 | } | 142 | } |
161 | break; | 143 | break; |
162 | case 'G': /* Last page */ | 144 | case 'G': /* Last page */ |
163 | case KEY_END: | 145 | case KEY_END: |
164 | 146 | ||
165 | end_reached = 1; | 147 | end_reached = 1; |
166 | /* Last page not in buffer? */ | 148 | /* point to last char in buf */ |
167 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 149 | page = buf + strlen(buf); |
168 | endwin(); | 150 | back_lines(boxh); |
169 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | 151 | refresh_text_box(dialog, box, boxh, boxw, |
170 | exit(-1); | 152 | cur_y, cur_x); |
171 | } | ||
172 | if (fpos < file_size) { /* Yes, we have to read it in */ | ||
173 | if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) { | ||
174 | endwin(); | ||
175 | fprintf(stderr, "\nError moving file pointer in dialog_textbox().\n"); | ||
176 | exit(-1); | ||
177 | } | ||
178 | if ((bytes_read = | ||
179 | read(fd, buf, BUF_SIZE)) == -1) { | ||
180 | endwin(); | ||
181 | fprintf(stderr, "\nError reading file in dialog_textbox().\n"); | ||
182 | exit(-1); | ||
183 | } | ||
184 | buf[bytes_read] = '\0'; | ||
185 | } | ||
186 | page = buf + bytes_read; | ||
187 | back_lines(height - 4); | ||
188 | print_page(text, height - 4, width - 2); | ||
189 | print_position(dialog, height, width); | ||
190 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | ||
191 | wrefresh(dialog); | ||
192 | break; | 153 | break; |
193 | case 'K': /* Previous line */ | 154 | case 'K': /* Previous line */ |
194 | case 'k': | 155 | case 'k': |
@@ -196,21 +157,23 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
196 | if (!begin_reached) { | 157 | if (!begin_reached) { |
197 | back_lines(page_length + 1); | 158 | back_lines(page_length + 1); |
198 | 159 | ||
199 | /* We don't call print_page() here but use scrolling to ensure | 160 | /* We don't call print_page() here but use |
200 | faster screen update. However, 'end_reached' and | 161 | * scrolling to ensure faster screen update. |
201 | 'page_length' should still be updated, and 'page' should | 162 | * However, 'end_reached' and 'page_length' |
202 | point to start of next page. This is done by calling | 163 | * should still be updated, and 'page' should |
203 | get_line() in the following 'for' loop. */ | 164 | * point to start of next page. This is done |
204 | scrollok(text, TRUE); | 165 | * by calling get_line() in the following |
205 | wscrl(text, -1); /* Scroll text region down one line */ | 166 | * 'for' loop. */ |
206 | scrollok(text, FALSE); | 167 | scrollok(box, TRUE); |
168 | wscrl(box, -1); /* Scroll box region down one line */ | ||
169 | scrollok(box, FALSE); | ||
207 | page_length = 0; | 170 | page_length = 0; |
208 | passed_end = 0; | 171 | passed_end = 0; |
209 | for (i = 0; i < height - 4; i++) { | 172 | for (i = 0; i < boxh; i++) { |
210 | if (!i) { | 173 | if (!i) { |
211 | /* print first line of page */ | 174 | /* print first line of page */ |
212 | print_line(text, 0, width - 2); | 175 | print_line(box, 0, boxw); |
213 | wnoutrefresh(text); | 176 | wnoutrefresh(box); |
214 | } else | 177 | } else |
215 | /* Called to update 'end_reached' and 'page' */ | 178 | /* Called to update 'end_reached' and 'page' */ |
216 | get_line(); | 179 | get_line(); |
@@ -220,7 +183,7 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
220 | passed_end = 1; | 183 | passed_end = 1; |
221 | } | 184 | } |
222 | 185 | ||
223 | print_position(dialog, height, width); | 186 | print_position(dialog); |
224 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 187 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
225 | wrefresh(dialog); | 188 | wrefresh(dialog); |
226 | } | 189 | } |
@@ -230,23 +193,21 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
230 | case KEY_PPAGE: | 193 | case KEY_PPAGE: |
231 | if (begin_reached) | 194 | if (begin_reached) |
232 | break; | 195 | break; |
233 | back_lines(page_length + height - 4); | 196 | back_lines(page_length + boxh); |
234 | print_page(text, height - 4, width - 2); | 197 | refresh_text_box(dialog, box, boxh, boxw, |
235 | print_position(dialog, height, width); | 198 | cur_y, cur_x); |
236 | wmove(dialog, cur_y, cur_x); | ||
237 | wrefresh(dialog); | ||
238 | break; | 199 | break; |
239 | case 'J': /* Next line */ | 200 | case 'J': /* Next line */ |
240 | case 'j': | 201 | case 'j': |
241 | case KEY_DOWN: | 202 | case KEY_DOWN: |
242 | if (!end_reached) { | 203 | if (!end_reached) { |
243 | begin_reached = 0; | 204 | begin_reached = 0; |
244 | scrollok(text, TRUE); | 205 | scrollok(box, TRUE); |
245 | scroll(text); /* Scroll text region up one line */ | 206 | scroll(box); /* Scroll box region up one line */ |
246 | scrollok(text, FALSE); | 207 | scrollok(box, FALSE); |
247 | print_line(text, height - 5, width - 2); | 208 | print_line(box, boxh - 1, boxw); |
248 | wnoutrefresh(text); | 209 | wnoutrefresh(box); |
249 | print_position(dialog, height, width); | 210 | print_position(dialog); |
250 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ | 211 | wmove(dialog, cur_y, cur_x); /* Restore cursor position */ |
251 | wrefresh(dialog); | 212 | wrefresh(dialog); |
252 | } | 213 | } |
@@ -257,10 +218,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
257 | break; | 218 | break; |
258 | 219 | ||
259 | begin_reached = 0; | 220 | begin_reached = 0; |
260 | print_page(text, height - 4, width - 2); | 221 | refresh_text_box(dialog, box, boxh, boxw, |
261 | print_position(dialog, height, width); | 222 | cur_y, cur_x); |
262 | wmove(dialog, cur_y, cur_x); | ||
263 | wrefresh(dialog); | ||
264 | break; | 223 | break; |
265 | case '0': /* Beginning of line */ | 224 | case '0': /* Beginning of line */ |
266 | case 'H': /* Scroll left */ | 225 | case 'H': /* Scroll left */ |
@@ -275,9 +234,8 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
275 | hscroll--; | 234 | hscroll--; |
276 | /* Reprint current page to scroll horizontally */ | 235 | /* Reprint current page to scroll horizontally */ |
277 | back_lines(page_length); | 236 | back_lines(page_length); |
278 | print_page(text, height - 4, width - 2); | 237 | refresh_text_box(dialog, box, boxh, boxw, |
279 | wmove(dialog, cur_y, cur_x); | 238 | cur_y, cur_x); |
280 | wrefresh(dialog); | ||
281 | break; | 239 | break; |
282 | case 'L': /* Scroll right */ | 240 | case 'L': /* Scroll right */ |
283 | case 'l': | 241 | case 'l': |
@@ -287,131 +245,56 @@ int dialog_textbox(const char *title, const char *file, int height, int width) | |||
287 | hscroll++; | 245 | hscroll++; |
288 | /* Reprint current page to scroll horizontally */ | 246 | /* Reprint current page to scroll horizontally */ |
289 | back_lines(page_length); | 247 | back_lines(page_length); |
290 | print_page(text, height - 4, width - 2); | 248 | refresh_text_box(dialog, box, boxh, boxw, |
291 | wmove(dialog, cur_y, cur_x); | 249 | cur_y, cur_x); |
292 | wrefresh(dialog); | ||
293 | break; | 250 | break; |
294 | case ESC: | 251 | case KEY_ESC: |
252 | key = on_key_esc(dialog); | ||
295 | break; | 253 | break; |
254 | case KEY_RESIZE: | ||
255 | back_lines(height); | ||
256 | delwin(box); | ||
257 | delwin(dialog); | ||
258 | on_key_resize(); | ||
259 | goto do_resize; | ||
296 | } | 260 | } |
297 | } | 261 | } |
298 | 262 | delwin(box); | |
299 | delwin(dialog); | 263 | delwin(dialog); |
300 | free(buf); | 264 | return key; /* ESC pressed */ |
301 | close(fd); | ||
302 | return -1; /* ESC pressed */ | ||
303 | } | 265 | } |
304 | 266 | ||
305 | /* | 267 | /* |
306 | * Go back 'n' lines in text file. Called by dialog_textbox(). | 268 | * Go back 'n' lines in text. Called by dialog_textbox(). |
307 | * 'page' will be updated to point to the desired line in 'buf'. | 269 | * 'page' will be updated to point to the desired line in 'buf'. |
308 | */ | 270 | */ |
309 | static void back_lines(int n) | 271 | static void back_lines(int n) |
310 | { | 272 | { |
311 | int i, fpos; | 273 | int i; |
312 | 274 | ||
313 | begin_reached = 0; | 275 | begin_reached = 0; |
314 | /* We have to distinguish between end_reached and !end_reached | 276 | /* Go back 'n' lines */ |
315 | since at end of file, the line is not ended by a '\n'. | 277 | for (i = 0; i < n; i++) { |
316 | The code inside 'if' basically does a '--page' to move one | 278 | if (*page == '\0') { |
317 | character backward so as to skip '\n' of the previous line */ | 279 | if (end_reached) { |
318 | if (!end_reached) { | 280 | end_reached = 0; |
319 | /* Either beginning of buffer or beginning of file reached? */ | 281 | continue; |
320 | if (page == buf) { | ||
321 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | ||
322 | endwin(); | ||
323 | fprintf(stderr, "\nError moving file pointer in " | ||
324 | "back_lines().\n"); | ||
325 | exit(-1); | ||
326 | } | ||
327 | if (fpos > bytes_read) { /* Not beginning of file yet */ | ||
328 | /* We've reached beginning of buffer, but not beginning of | ||
329 | file yet, so read previous part of file into buffer. | ||
330 | Note that we only move backward for BUF_SIZE/2 bytes, | ||
331 | but not BUF_SIZE bytes to avoid re-reading again in | ||
332 | print_page() later */ | ||
333 | /* Really possible to move backward BUF_SIZE/2 bytes? */ | ||
334 | if (fpos < BUF_SIZE / 2 + bytes_read) { | ||
335 | /* No, move less then */ | ||
336 | if (lseek(fd, 0, SEEK_SET) == -1) { | ||
337 | endwin(); | ||
338 | fprintf(stderr, "\nError moving file pointer in " | ||
339 | "back_lines().\n"); | ||
340 | exit(-1); | ||
341 | } | ||
342 | page = buf + fpos - bytes_read; | ||
343 | } else { /* Move backward BUF_SIZE/2 bytes */ | ||
344 | if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { | ||
345 | endwin(); | ||
346 | fprintf(stderr, "\nError moving file pointer " | ||
347 | "in back_lines().\n"); | ||
348 | exit(-1); | ||
349 | } | ||
350 | page = buf + BUF_SIZE / 2; | ||
351 | } | ||
352 | if ((bytes_read = | ||
353 | read(fd, buf, BUF_SIZE)) == -1) { | ||
354 | endwin(); | ||
355 | fprintf(stderr, "\nError reading file in back_lines().\n"); | ||
356 | exit(-1); | ||
357 | } | ||
358 | buf[bytes_read] = '\0'; | ||
359 | } else { /* Beginning of file reached */ | ||
360 | begin_reached = 1; | ||
361 | return; | ||
362 | } | 282 | } |
363 | } | 283 | } |
364 | if (*(--page) != '\n') { /* '--page' here */ | 284 | if (page == buf) { |
365 | /* Something's wrong... */ | 285 | begin_reached = 1; |
366 | endwin(); | 286 | return; |
367 | fprintf(stderr, "\nInternal error in back_lines().\n"); | ||
368 | exit(-1); | ||
369 | } | 287 | } |
370 | } | 288 | page--; |
371 | /* Go back 'n' lines */ | ||
372 | for (i = 0; i < n; i++) | ||
373 | do { | 289 | do { |
374 | if (page == buf) { | 290 | if (page == buf) { |
375 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 291 | begin_reached = 1; |
376 | endwin(); | 292 | return; |
377 | fprintf(stderr, "\nError moving file pointer in back_lines().\n"); | ||
378 | exit(-1); | ||
379 | } | ||
380 | if (fpos > bytes_read) { | ||
381 | /* Really possible to move backward BUF_SIZE/2 bytes? */ | ||
382 | if (fpos < BUF_SIZE / 2 + bytes_read) { | ||
383 | /* No, move less then */ | ||
384 | if (lseek(fd, 0, SEEK_SET) == -1) { | ||
385 | endwin(); | ||
386 | fprintf(stderr, "\nError moving file pointer " | ||
387 | "in back_lines().\n"); | ||
388 | exit(-1); | ||
389 | } | ||
390 | page = buf + fpos - bytes_read; | ||
391 | } else { /* Move backward BUF_SIZE/2 bytes */ | ||
392 | if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { | ||
393 | endwin(); | ||
394 | fprintf(stderr, "\nError moving file pointer" | ||
395 | " in back_lines().\n"); | ||
396 | exit(-1); | ||
397 | } | ||
398 | page = buf + BUF_SIZE / 2; | ||
399 | } | ||
400 | if ((bytes_read = | ||
401 | read(fd, buf, BUF_SIZE)) == -1) { | ||
402 | endwin(); | ||
403 | fprintf(stderr, "\nError reading file in " | ||
404 | "back_lines().\n"); | ||
405 | exit(-1); | ||
406 | } | ||
407 | buf[bytes_read] = '\0'; | ||
408 | } else { /* Beginning of file reached */ | ||
409 | begin_reached = 1; | ||
410 | return; | ||
411 | } | ||
412 | } | 293 | } |
413 | } while (*(--page) != '\n'); | 294 | page--; |
414 | page++; | 295 | } while (*page != '\n'); |
296 | page++; | ||
297 | } | ||
415 | } | 298 | } |
416 | 299 | ||
417 | /* | 300 | /* |
@@ -466,33 +349,14 @@ static void print_line(WINDOW * win, int row, int width) | |||
466 | */ | 349 | */ |
467 | static char *get_line(void) | 350 | static char *get_line(void) |
468 | { | 351 | { |
469 | int i = 0, fpos; | 352 | int i = 0; |
470 | static char line[MAX_LEN + 1]; | 353 | static char line[MAX_LEN + 1]; |
471 | 354 | ||
472 | end_reached = 0; | 355 | end_reached = 0; |
473 | while (*page != '\n') { | 356 | while (*page != '\n') { |
474 | if (*page == '\0') { | 357 | if (*page == '\0') { |
475 | /* Either end of file or end of buffer reached */ | 358 | if (!end_reached) { |
476 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 359 | end_reached = 1; |
477 | endwin(); | ||
478 | fprintf(stderr, "\nError moving file pointer in " | ||
479 | "get_line().\n"); | ||
480 | exit(-1); | ||
481 | } | ||
482 | if (fpos < file_size) { /* Not end of file yet */ | ||
483 | /* We've reached end of buffer, but not end of file yet, | ||
484 | so read next part of file into buffer */ | ||
485 | if ((bytes_read = | ||
486 | read(fd, buf, BUF_SIZE)) == -1) { | ||
487 | endwin(); | ||
488 | fprintf(stderr, "\nError reading file in get_line().\n"); | ||
489 | exit(-1); | ||
490 | } | ||
491 | buf[bytes_read] = '\0'; | ||
492 | page = buf; | ||
493 | } else { | ||
494 | if (!end_reached) | ||
495 | end_reached = 1; | ||
496 | break; | 360 | break; |
497 | } | 361 | } |
498 | } else if (i < MAX_LEN) | 362 | } else if (i < MAX_LEN) |
@@ -515,19 +379,13 @@ static char *get_line(void) | |||
515 | /* | 379 | /* |
516 | * Print current position | 380 | * Print current position |
517 | */ | 381 | */ |
518 | static void print_position(WINDOW * win, int height, int width) | 382 | static void print_position(WINDOW * win) |
519 | { | 383 | { |
520 | int fpos, percent; | 384 | int percent; |
521 | 385 | ||
522 | if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { | 386 | wattrset(win, dlg.position_indicator.atr); |
523 | endwin(); | 387 | wbkgdset(win, dlg.position_indicator.atr & A_COLOR); |
524 | fprintf(stderr, "\nError moving file pointer in print_position().\n"); | 388 | percent = (page - buf) * 100 / strlen(buf); |
525 | exit(-1); | 389 | wmove(win, getmaxy(win) - 3, getmaxx(win) - 9); |
526 | } | ||
527 | wattrset(win, position_indicator_attr); | ||
528 | wbkgdset(win, position_indicator_attr & A_COLOR); | ||
529 | percent = !file_size ? | ||
530 | 100 : ((fpos - bytes_read + page - buf) * 100) / file_size; | ||
531 | wmove(win, height - 3, width - 9); | ||
532 | wprintw(win, "(%3d%%)", percent); | 390 | wprintw(win, "(%3d%%)", percent); |
533 | } | 391 | } |
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c index f82cebb9ff06..ebc781b493d7 100644 --- a/scripts/kconfig/lxdialog/util.c +++ b/scripts/kconfig/lxdialog/util.c | |||
@@ -21,85 +21,217 @@ | |||
21 | 21 | ||
22 | #include "dialog.h" | 22 | #include "dialog.h" |
23 | 23 | ||
24 | /* use colors by default? */ | 24 | struct dialog_info dlg; |
25 | bool use_colors = 1; | ||
26 | 25 | ||
27 | const char *backtitle = NULL; | 26 | static void set_mono_theme(void) |
27 | { | ||
28 | dlg.screen.atr = A_NORMAL; | ||
29 | dlg.shadow.atr = A_NORMAL; | ||
30 | dlg.dialog.atr = A_NORMAL; | ||
31 | dlg.title.atr = A_BOLD; | ||
32 | dlg.border.atr = A_NORMAL; | ||
33 | dlg.button_active.atr = A_REVERSE; | ||
34 | dlg.button_inactive.atr = A_DIM; | ||
35 | dlg.button_key_active.atr = A_REVERSE; | ||
36 | dlg.button_key_inactive.atr = A_BOLD; | ||
37 | dlg.button_label_active.atr = A_REVERSE; | ||
38 | dlg.button_label_inactive.atr = A_NORMAL; | ||
39 | dlg.inputbox.atr = A_NORMAL; | ||
40 | dlg.inputbox_border.atr = A_NORMAL; | ||
41 | dlg.searchbox.atr = A_NORMAL; | ||
42 | dlg.searchbox_title.atr = A_BOLD; | ||
43 | dlg.searchbox_border.atr = A_NORMAL; | ||
44 | dlg.position_indicator.atr = A_BOLD; | ||
45 | dlg.menubox.atr = A_NORMAL; | ||
46 | dlg.menubox_border.atr = A_NORMAL; | ||
47 | dlg.item.atr = A_NORMAL; | ||
48 | dlg.item_selected.atr = A_REVERSE; | ||
49 | dlg.tag.atr = A_BOLD; | ||
50 | dlg.tag_selected.atr = A_REVERSE; | ||
51 | dlg.tag_key.atr = A_BOLD; | ||
52 | dlg.tag_key_selected.atr = A_REVERSE; | ||
53 | dlg.check.atr = A_BOLD; | ||
54 | dlg.check_selected.atr = A_REVERSE; | ||
55 | dlg.uarrow.atr = A_BOLD; | ||
56 | dlg.darrow.atr = A_BOLD; | ||
57 | } | ||
58 | |||
59 | #define DLG_COLOR(dialog, f, b, h) \ | ||
60 | do { \ | ||
61 | dlg.dialog.fg = (f); \ | ||
62 | dlg.dialog.bg = (b); \ | ||
63 | dlg.dialog.hl = (h); \ | ||
64 | } while (0) | ||
65 | |||
66 | static void set_classic_theme(void) | ||
67 | { | ||
68 | DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true); | ||
69 | DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true); | ||
70 | DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false); | ||
71 | DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true); | ||
72 | DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true); | ||
73 | DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true); | ||
74 | DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false); | ||
75 | DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true); | ||
76 | DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false); | ||
77 | DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true); | ||
78 | DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true); | ||
79 | DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false); | ||
80 | DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false); | ||
81 | DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false); | ||
82 | DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true); | ||
83 | DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true); | ||
84 | DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true); | ||
85 | DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false); | ||
86 | DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true); | ||
87 | DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false); | ||
88 | DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true); | ||
89 | DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true); | ||
90 | DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true); | ||
91 | DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true); | ||
92 | DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true); | ||
93 | DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false); | ||
94 | DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true); | ||
95 | DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true); | ||
96 | DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true); | ||
97 | } | ||
98 | |||
99 | static void set_blackbg_theme(void) | ||
100 | { | ||
101 | DLG_COLOR(screen, COLOR_RED, COLOR_BLACK, true); | ||
102 | DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, false); | ||
103 | DLG_COLOR(dialog, COLOR_WHITE, COLOR_BLACK, false); | ||
104 | DLG_COLOR(title, COLOR_RED, COLOR_BLACK, false); | ||
105 | DLG_COLOR(border, COLOR_BLACK, COLOR_BLACK, true); | ||
106 | |||
107 | DLG_COLOR(button_active, COLOR_YELLOW, COLOR_RED, false); | ||
108 | DLG_COLOR(button_inactive, COLOR_YELLOW, COLOR_BLACK, false); | ||
109 | DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_RED, true); | ||
110 | DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_BLACK, false); | ||
111 | DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_RED, false); | ||
112 | DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_BLACK, true); | ||
113 | |||
114 | DLG_COLOR(inputbox, COLOR_YELLOW, COLOR_BLACK, false); | ||
115 | DLG_COLOR(inputbox_border, COLOR_YELLOW, COLOR_BLACK, false); | ||
116 | |||
117 | DLG_COLOR(searchbox, COLOR_YELLOW, COLOR_BLACK, false); | ||
118 | DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_BLACK, true); | ||
119 | DLG_COLOR(searchbox_border, COLOR_BLACK, COLOR_BLACK, true); | ||
120 | |||
121 | DLG_COLOR(position_indicator, COLOR_RED, COLOR_BLACK, false); | ||
122 | |||
123 | DLG_COLOR(menubox, COLOR_YELLOW, COLOR_BLACK, false); | ||
124 | DLG_COLOR(menubox_border, COLOR_BLACK, COLOR_BLACK, true); | ||
125 | |||
126 | DLG_COLOR(item, COLOR_WHITE, COLOR_BLACK, false); | ||
127 | DLG_COLOR(item_selected, COLOR_WHITE, COLOR_RED, false); | ||
128 | |||
129 | DLG_COLOR(tag, COLOR_RED, COLOR_BLACK, false); | ||
130 | DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_RED, true); | ||
131 | DLG_COLOR(tag_key, COLOR_RED, COLOR_BLACK, false); | ||
132 | DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_RED, true); | ||
133 | |||
134 | DLG_COLOR(check, COLOR_YELLOW, COLOR_BLACK, false); | ||
135 | DLG_COLOR(check_selected, COLOR_YELLOW, COLOR_RED, true); | ||
136 | |||
137 | DLG_COLOR(uarrow, COLOR_RED, COLOR_BLACK, false); | ||
138 | DLG_COLOR(darrow, COLOR_RED, COLOR_BLACK, false); | ||
139 | } | ||
140 | |||
141 | static void set_bluetitle_theme(void) | ||
142 | { | ||
143 | set_classic_theme(); | ||
144 | DLG_COLOR(title, COLOR_BLUE, COLOR_WHITE, true); | ||
145 | DLG_COLOR(button_key_active, COLOR_YELLOW, COLOR_BLUE, true); | ||
146 | DLG_COLOR(button_label_active, COLOR_WHITE, COLOR_BLUE, true); | ||
147 | DLG_COLOR(searchbox_title, COLOR_BLUE, COLOR_WHITE, true); | ||
148 | DLG_COLOR(position_indicator, COLOR_BLUE, COLOR_WHITE, true); | ||
149 | DLG_COLOR(tag, COLOR_BLUE, COLOR_WHITE, true); | ||
150 | DLG_COLOR(tag_key, COLOR_BLUE, COLOR_WHITE, true); | ||
151 | |||
152 | } | ||
28 | 153 | ||
29 | /* | 154 | /* |
30 | * Attribute values, default is for mono display | 155 | * Select color theme |
31 | */ | 156 | */ |
32 | chtype attributes[] = { | 157 | static int set_theme(const char *theme) |
33 | A_NORMAL, /* screen_attr */ | 158 | { |
34 | A_NORMAL, /* shadow_attr */ | 159 | int use_color = 1; |
35 | A_NORMAL, /* dialog_attr */ | 160 | if (!theme) |
36 | A_BOLD, /* title_attr */ | 161 | set_bluetitle_theme(); |
37 | A_NORMAL, /* border_attr */ | 162 | else if (strcmp(theme, "classic") == 0) |
38 | A_REVERSE, /* button_active_attr */ | 163 | set_classic_theme(); |
39 | A_DIM, /* button_inactive_attr */ | 164 | else if (strcmp(theme, "bluetitle") == 0) |
40 | A_REVERSE, /* button_key_active_attr */ | 165 | set_bluetitle_theme(); |
41 | A_BOLD, /* button_key_inactive_attr */ | 166 | else if (strcmp(theme, "blackbg") == 0) |
42 | A_REVERSE, /* button_label_active_attr */ | 167 | set_blackbg_theme(); |
43 | A_NORMAL, /* button_label_inactive_attr */ | 168 | else if (strcmp(theme, "mono") == 0) |
44 | A_NORMAL, /* inputbox_attr */ | 169 | use_color = 0; |
45 | A_NORMAL, /* inputbox_border_attr */ | 170 | |
46 | A_NORMAL, /* searchbox_attr */ | 171 | return use_color; |
47 | A_BOLD, /* searchbox_title_attr */ | 172 | } |
48 | A_NORMAL, /* searchbox_border_attr */ | 173 | |
49 | A_BOLD, /* position_indicator_attr */ | 174 | static void init_one_color(struct dialog_color *color) |
50 | A_NORMAL, /* menubox_attr */ | 175 | { |
51 | A_NORMAL, /* menubox_border_attr */ | 176 | static int pair = 0; |
52 | A_NORMAL, /* item_attr */ | 177 | |
53 | A_REVERSE, /* item_selected_attr */ | 178 | pair++; |
54 | A_BOLD, /* tag_attr */ | 179 | init_pair(pair, color->fg, color->bg); |
55 | A_REVERSE, /* tag_selected_attr */ | 180 | if (color->hl) |
56 | A_BOLD, /* tag_key_attr */ | 181 | color->atr = A_BOLD | COLOR_PAIR(pair); |
57 | A_REVERSE, /* tag_key_selected_attr */ | 182 | else |
58 | A_BOLD, /* check_attr */ | 183 | color->atr = COLOR_PAIR(pair); |
59 | A_REVERSE, /* check_selected_attr */ | 184 | } |
60 | A_BOLD, /* uarrow_attr */ | 185 | |
61 | A_BOLD /* darrow_attr */ | 186 | static void init_dialog_colors(void) |
62 | }; | 187 | { |
63 | 188 | init_one_color(&dlg.screen); | |
64 | #include "colors.h" | 189 | init_one_color(&dlg.shadow); |
190 | init_one_color(&dlg.dialog); | ||
191 | init_one_color(&dlg.title); | ||
192 | init_one_color(&dlg.border); | ||
193 | init_one_color(&dlg.button_active); | ||
194 | init_one_color(&dlg.button_inactive); | ||
195 | init_one_color(&dlg.button_key_active); | ||
196 | init_one_color(&dlg.button_key_inactive); | ||
197 | init_one_color(&dlg.button_label_active); | ||
198 | init_one_color(&dlg.button_label_inactive); | ||
199 | init_one_color(&dlg.inputbox); | ||
200 | init_one_color(&dlg.inputbox_border); | ||
201 | init_one_color(&dlg.searchbox); | ||
202 | init_one_color(&dlg.searchbox_title); | ||
203 | init_one_color(&dlg.searchbox_border); | ||
204 | init_one_color(&dlg.position_indicator); | ||
205 | init_one_color(&dlg.menubox); | ||
206 | init_one_color(&dlg.menubox_border); | ||
207 | init_one_color(&dlg.item); | ||
208 | init_one_color(&dlg.item_selected); | ||
209 | init_one_color(&dlg.tag); | ||
210 | init_one_color(&dlg.tag_selected); | ||
211 | init_one_color(&dlg.tag_key); | ||
212 | init_one_color(&dlg.tag_key_selected); | ||
213 | init_one_color(&dlg.check); | ||
214 | init_one_color(&dlg.check_selected); | ||
215 | init_one_color(&dlg.uarrow); | ||
216 | init_one_color(&dlg.darrow); | ||
217 | } | ||
65 | 218 | ||
66 | /* | 219 | /* |
67 | * Table of color values | 220 | * Setup for color display |
68 | */ | 221 | */ |
69 | int color_table[][3] = { | 222 | static void color_setup(const char *theme) |
70 | {SCREEN_FG, SCREEN_BG, SCREEN_HL}, | 223 | { |
71 | {SHADOW_FG, SHADOW_BG, SHADOW_HL}, | 224 | if (set_theme(theme)) { |
72 | {DIALOG_FG, DIALOG_BG, DIALOG_HL}, | 225 | if (has_colors()) { /* Terminal supports color? */ |
73 | {TITLE_FG, TITLE_BG, TITLE_HL}, | 226 | start_color(); |
74 | {BORDER_FG, BORDER_BG, BORDER_HL}, | 227 | init_dialog_colors(); |
75 | {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, | 228 | } |
76 | {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, | 229 | } |
77 | {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, | 230 | else |
78 | {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, | 231 | { |
79 | BUTTON_KEY_INACTIVE_HL}, | 232 | set_mono_theme(); |
80 | {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, | 233 | } |
81 | BUTTON_LABEL_ACTIVE_HL}, | 234 | } |
82 | {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG, | ||
83 | BUTTON_LABEL_INACTIVE_HL}, | ||
84 | {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL}, | ||
85 | {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL}, | ||
86 | {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL}, | ||
87 | {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL}, | ||
88 | {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL}, | ||
89 | {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL}, | ||
90 | {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL}, | ||
91 | {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL}, | ||
92 | {ITEM_FG, ITEM_BG, ITEM_HL}, | ||
93 | {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL}, | ||
94 | {TAG_FG, TAG_BG, TAG_HL}, | ||
95 | {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL}, | ||
96 | {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL}, | ||
97 | {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL}, | ||
98 | {CHECK_FG, CHECK_BG, CHECK_HL}, | ||
99 | {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL}, | ||
100 | {UARROW_FG, UARROW_BG, UARROW_HL}, | ||
101 | {DARROW_FG, DARROW_BG, DARROW_HL}, | ||
102 | }; /* color_table */ | ||
103 | 235 | ||
104 | /* | 236 | /* |
105 | * Set window to attribute 'attr' | 237 | * Set window to attribute 'attr' |
@@ -119,13 +251,13 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr) | |||
119 | 251 | ||
120 | void dialog_clear(void) | 252 | void dialog_clear(void) |
121 | { | 253 | { |
122 | attr_clear(stdscr, LINES, COLS, screen_attr); | 254 | attr_clear(stdscr, LINES, COLS, dlg.screen.atr); |
123 | /* Display background title if it exists ... - SLH */ | 255 | /* Display background title if it exists ... - SLH */ |
124 | if (backtitle != NULL) { | 256 | if (dlg.backtitle != NULL) { |
125 | int i; | 257 | int i; |
126 | 258 | ||
127 | wattrset(stdscr, screen_attr); | 259 | wattrset(stdscr, dlg.screen.atr); |
128 | mvwaddstr(stdscr, 0, 1, (char *)backtitle); | 260 | mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle); |
129 | wmove(stdscr, 1, 1); | 261 | wmove(stdscr, 1, 1); |
130 | for (i = 1; i < COLS - 1; i++) | 262 | for (i = 1; i < COLS - 1; i++) |
131 | waddch(stdscr, ACS_HLINE); | 263 | waddch(stdscr, ACS_HLINE); |
@@ -136,40 +268,22 @@ void dialog_clear(void) | |||
136 | /* | 268 | /* |
137 | * Do some initialization for dialog | 269 | * Do some initialization for dialog |
138 | */ | 270 | */ |
139 | void init_dialog(void) | 271 | void init_dialog(const char *backtitle) |
272 | { | ||
273 | dlg.backtitle = backtitle; | ||
274 | color_setup(getenv("MENUCONFIG_COLOR")); | ||
275 | } | ||
276 | |||
277 | void reset_dialog(void) | ||
140 | { | 278 | { |
141 | initscr(); /* Init curses */ | 279 | initscr(); /* Init curses */ |
142 | keypad(stdscr, TRUE); | 280 | keypad(stdscr, TRUE); |
143 | cbreak(); | 281 | cbreak(); |
144 | noecho(); | 282 | noecho(); |
145 | |||
146 | if (use_colors) /* Set up colors */ | ||
147 | color_setup(); | ||
148 | |||
149 | dialog_clear(); | 283 | dialog_clear(); |
150 | } | 284 | } |
151 | 285 | ||
152 | /* | 286 | /* |
153 | * Setup for color display | ||
154 | */ | ||
155 | void color_setup(void) | ||
156 | { | ||
157 | int i; | ||
158 | |||
159 | if (has_colors()) { /* Terminal supports color? */ | ||
160 | start_color(); | ||
161 | |||
162 | /* Initialize color pairs */ | ||
163 | for (i = 0; i < ATTRIBUTE_COUNT; i++) | ||
164 | init_pair(i + 1, color_table[i][0], color_table[i][1]); | ||
165 | |||
166 | /* Setup color attributes */ | ||
167 | for (i = 0; i < ATTRIBUTE_COUNT; i++) | ||
168 | attributes[i] = C_ATTR(color_table[i][2], i + 1); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | /* | ||
173 | * End using dialog functions. | 287 | * End using dialog functions. |
174 | */ | 288 | */ |
175 | void end_dialog(void) | 289 | void end_dialog(void) |
@@ -184,7 +298,7 @@ void print_title(WINDOW *dialog, const char *title, int width) | |||
184 | { | 298 | { |
185 | if (title) { | 299 | if (title) { |
186 | int tlen = MIN(width - 2, strlen(title)); | 300 | int tlen = MIN(width - 2, strlen(title)); |
187 | wattrset(dialog, title_attr); | 301 | wattrset(dialog, dlg.title.atr); |
188 | mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); | 302 | mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); |
189 | mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); | 303 | mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); |
190 | waddch(dialog, ' '); | 304 | waddch(dialog, ' '); |
@@ -264,21 +378,23 @@ void print_button(WINDOW * win, const char *label, int y, int x, int selected) | |||
264 | int i, temp; | 378 | int i, temp; |
265 | 379 | ||
266 | wmove(win, y, x); | 380 | wmove(win, y, x); |
267 | wattrset(win, selected ? button_active_attr : button_inactive_attr); | 381 | wattrset(win, selected ? dlg.button_active.atr |
382 | : dlg.button_inactive.atr); | ||
268 | waddstr(win, "<"); | 383 | waddstr(win, "<"); |
269 | temp = strspn(label, " "); | 384 | temp = strspn(label, " "); |
270 | label += temp; | 385 | label += temp; |
271 | wattrset(win, selected ? button_label_active_attr | 386 | wattrset(win, selected ? dlg.button_label_active.atr |
272 | : button_label_inactive_attr); | 387 | : dlg.button_label_inactive.atr); |
273 | for (i = 0; i < temp; i++) | 388 | for (i = 0; i < temp; i++) |
274 | waddch(win, ' '); | 389 | waddch(win, ' '); |
275 | wattrset(win, selected ? button_key_active_attr | 390 | wattrset(win, selected ? dlg.button_key_active.atr |
276 | : button_key_inactive_attr); | 391 | : dlg.button_key_inactive.atr); |
277 | waddch(win, label[0]); | 392 | waddch(win, label[0]); |
278 | wattrset(win, selected ? button_label_active_attr | 393 | wattrset(win, selected ? dlg.button_label_active.atr |
279 | : button_label_inactive_attr); | 394 | : dlg.button_label_inactive.atr); |
280 | waddstr(win, (char *)label + 1); | 395 | waddstr(win, (char *)label + 1); |
281 | wattrset(win, selected ? button_active_attr : button_inactive_attr); | 396 | wattrset(win, selected ? dlg.button_active.atr |
397 | : dlg.button_inactive.atr); | ||
282 | waddstr(win, ">"); | 398 | waddstr(win, ">"); |
283 | wmove(win, y, x + temp + 1); | 399 | wmove(win, y, x + temp + 1); |
284 | } | 400 | } |
@@ -326,7 +442,7 @@ void draw_shadow(WINDOW * win, int y, int x, int height, int width) | |||
326 | int i; | 442 | int i; |
327 | 443 | ||
328 | if (has_colors()) { /* Whether terminal supports color? */ | 444 | if (has_colors()) { /* Whether terminal supports color? */ |
329 | wattrset(win, shadow_attr); | 445 | wattrset(win, dlg.shadow.atr); |
330 | wmove(win, y + height, x + 2); | 446 | wmove(win, y + height, x + 2); |
331 | for (i = 0; i < width; i++) | 447 | for (i = 0; i < width; i++) |
332 | waddch(win, winch(win) & A_CHARTEXT); | 448 | waddch(win, winch(win) & A_CHARTEXT); |
@@ -360,3 +476,167 @@ int first_alpha(const char *string, const char *exempt) | |||
360 | 476 | ||
361 | return 0; | 477 | return 0; |
362 | } | 478 | } |
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 | */ | ||
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 | /* redraw screen in new size */ | ||
513 | int on_key_resize(void) | ||
514 | { | ||
515 | dialog_clear(); | ||
516 | return KEY_RESIZE; | ||
517 | } | ||
518 | |||
519 | struct dialog_list *item_cur; | ||
520 | struct dialog_list item_nil; | ||
521 | struct dialog_list *item_head; | ||
522 | |||
523 | void item_reset(void) | ||
524 | { | ||
525 | struct dialog_list *p, *next; | ||
526 | |||
527 | for (p = item_head; p; p = next) { | ||
528 | next = p->next; | ||
529 | free(p); | ||
530 | } | ||
531 | item_head = NULL; | ||
532 | item_cur = &item_nil; | ||
533 | } | ||
534 | |||
535 | void item_make(const char *fmt, ...) | ||
536 | { | ||
537 | va_list ap; | ||
538 | struct dialog_list *p = malloc(sizeof(*p)); | ||
539 | |||
540 | if (item_head) | ||
541 | item_cur->next = p; | ||
542 | else | ||
543 | item_head = p; | ||
544 | item_cur = p; | ||
545 | memset(p, 0, sizeof(*p)); | ||
546 | |||
547 | va_start(ap, fmt); | ||
548 | vsnprintf(item_cur->node.str, sizeof(item_cur->node.str), fmt, ap); | ||
549 | va_end(ap); | ||
550 | } | ||
551 | |||
552 | void item_add_str(const char *fmt, ...) | ||
553 | { | ||
554 | va_list ap; | ||
555 | size_t avail; | ||
556 | |||
557 | avail = sizeof(item_cur->node.str) - strlen(item_cur->node.str); | ||
558 | |||
559 | va_start(ap, fmt); | ||
560 | vsnprintf(item_cur->node.str + strlen(item_cur->node.str), | ||
561 | avail, fmt, ap); | ||
562 | item_cur->node.str[sizeof(item_cur->node.str) - 1] = '\0'; | ||
563 | va_end(ap); | ||
564 | } | ||
565 | |||
566 | void item_set_tag(char tag) | ||
567 | { | ||
568 | item_cur->node.tag = tag; | ||
569 | } | ||
570 | void item_set_data(void *ptr) | ||
571 | { | ||
572 | item_cur->node.data = ptr; | ||
573 | } | ||
574 | |||
575 | void item_set_selected(int val) | ||
576 | { | ||
577 | item_cur->node.selected = val; | ||
578 | } | ||
579 | |||
580 | int item_activate_selected(void) | ||
581 | { | ||
582 | item_foreach() | ||
583 | if (item_is_selected()) | ||
584 | return 1; | ||
585 | return 0; | ||
586 | } | ||
587 | |||
588 | void *item_data(void) | ||
589 | { | ||
590 | return item_cur->node.data; | ||
591 | } | ||
592 | |||
593 | char item_tag(void) | ||
594 | { | ||
595 | return item_cur->node.tag; | ||
596 | } | ||
597 | |||
598 | int item_count(void) | ||
599 | { | ||
600 | int n = 0; | ||
601 | struct dialog_list *p; | ||
602 | |||
603 | for (p = item_head; p; p = p->next) | ||
604 | n++; | ||
605 | return n; | ||
606 | } | ||
607 | |||
608 | void item_set(int n) | ||
609 | { | ||
610 | int i = 0; | ||
611 | item_foreach() | ||
612 | if (i++ == n) | ||
613 | return; | ||
614 | } | ||
615 | |||
616 | int item_n(void) | ||
617 | { | ||
618 | int n = 0; | ||
619 | struct dialog_list *p; | ||
620 | |||
621 | for (p = item_head; p; p = p->next) { | ||
622 | if (p == item_cur) | ||
623 | return n; | ||
624 | n++; | ||
625 | } | ||
626 | return 0; | ||
627 | } | ||
628 | |||
629 | const char *item_str(void) | ||
630 | { | ||
631 | return item_cur->node.str; | ||
632 | } | ||
633 | |||
634 | int item_is_selected(void) | ||
635 | { | ||
636 | return (item_cur->node.selected != 0); | ||
637 | } | ||
638 | |||
639 | int item_is_tag(char tag) | ||
640 | { | ||
641 | return (item_cur->node.tag == tag); | ||
642 | } | ||
diff --git a/scripts/kconfig/lxdialog/yesno.c b/scripts/kconfig/lxdialog/yesno.c index cb2568aae3ed..ee0a04e3e012 100644 --- a/scripts/kconfig/lxdialog/yesno.c +++ b/scripts/kconfig/lxdialog/yesno.c | |||
@@ -44,6 +44,12 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) | |||
44 | int i, x, y, key = 0, button = 0; | 44 | int i, x, y, key = 0, button = 0; |
45 | WINDOW *dialog; | 45 | WINDOW *dialog; |
46 | 46 | ||
47 | do_resize: | ||
48 | if (getmaxy(stdscr) < (height + 4)) | ||
49 | return -ERRDISPLAYTOOSMALL; | ||
50 | if (getmaxx(stdscr) < (width + 4)) | ||
51 | return -ERRDISPLAYTOOSMALL; | ||
52 | |||
47 | /* center dialog box on screen */ | 53 | /* center dialog box on screen */ |
48 | x = (COLS - width) / 2; | 54 | x = (COLS - width) / 2; |
49 | y = (LINES - height) / 2; | 55 | y = (LINES - height) / 2; |
@@ -53,22 +59,23 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) | |||
53 | dialog = newwin(height, width, y, x); | 59 | dialog = newwin(height, width, y, x); |
54 | keypad(dialog, TRUE); | 60 | keypad(dialog, TRUE); |
55 | 61 | ||
56 | draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); | 62 | draw_box(dialog, 0, 0, height, width, |
57 | wattrset(dialog, border_attr); | 63 | dlg.dialog.atr, dlg.border.atr); |
64 | wattrset(dialog, dlg.border.atr); | ||
58 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); | 65 | mvwaddch(dialog, height - 3, 0, ACS_LTEE); |
59 | for (i = 0; i < width - 2; i++) | 66 | for (i = 0; i < width - 2; i++) |
60 | waddch(dialog, ACS_HLINE); | 67 | waddch(dialog, ACS_HLINE); |
61 | wattrset(dialog, dialog_attr); | 68 | wattrset(dialog, dlg.dialog.atr); |
62 | waddch(dialog, ACS_RTEE); | 69 | waddch(dialog, ACS_RTEE); |
63 | 70 | ||
64 | print_title(dialog, title, width); | 71 | print_title(dialog, title, width); |
65 | 72 | ||
66 | wattrset(dialog, dialog_attr); | 73 | wattrset(dialog, dlg.dialog.atr); |
67 | print_autowrap(dialog, prompt, width - 2, 1, 3); | 74 | print_autowrap(dialog, prompt, width - 2, 1, 3); |
68 | 75 | ||
69 | print_buttons(dialog, height, width, 0); | 76 | print_buttons(dialog, height, width, 0); |
70 | 77 | ||
71 | while (key != ESC) { | 78 | while (key != KEY_ESC) { |
72 | key = wgetch(dialog); | 79 | key = wgetch(dialog); |
73 | switch (key) { | 80 | switch (key) { |
74 | case 'Y': | 81 | case 'Y': |
@@ -92,11 +99,16 @@ int dialog_yesno(const char *title, const char *prompt, int height, int width) | |||
92 | case '\n': | 99 | case '\n': |
93 | delwin(dialog); | 100 | delwin(dialog); |
94 | return button; | 101 | return button; |
95 | case ESC: | 102 | case KEY_ESC: |
103 | key = on_key_esc(dialog); | ||
96 | break; | 104 | break; |
105 | case KEY_RESIZE: | ||
106 | delwin(dialog); | ||
107 | on_key_resize(); | ||
108 | goto do_resize; | ||
97 | } | 109 | } |
98 | } | 110 | } |
99 | 111 | ||
100 | delwin(dialog); | 112 | delwin(dialog); |
101 | return -1; /* ESC pressed */ | 113 | return key; /* ESC pressed */ |
102 | } | 114 | } |