aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/lxdialog/checklist.c656
-rw-r--r--scripts/lxdialog/colors.h1
-rw-r--r--scripts/lxdialog/dialog.h59
-rw-r--r--scripts/lxdialog/inputbox.c408
-rw-r--r--scripts/lxdialog/lxdialog.c238
-rw-r--r--scripts/lxdialog/menubox.c724
-rw-r--r--scripts/lxdialog/msgbox.c89
-rw-r--r--scripts/lxdialog/textbox.c968
-rw-r--r--scripts/lxdialog/util.c467
-rw-r--r--scripts/lxdialog/yesno.c158
10 files changed, 1921 insertions, 1847 deletions
diff --git a/scripts/lxdialog/checklist.c b/scripts/lxdialog/checklist.c
index 7aba17c72e64..1857c5378ce8 100644
--- a/scripts/lxdialog/checklist.c
+++ b/scripts/lxdialog/checklist.c
@@ -29,87 +29,83 @@ static int list_width, check_x, item_x, checkflag;
29 * Print list item 29 * Print list item
30 */ 30 */
31static void 31static void
32print_item (WINDOW * win, const char *item, int status, 32print_item(WINDOW * win, const char *item, int status, int choice, int selected)
33 int choice, int selected)
34{ 33{
35 int i; 34 int i;
36 35
37 /* Clear 'residue' of last item */ 36 /* Clear 'residue' of last item */
38 wattrset (win, menubox_attr); 37 wattrset(win, menubox_attr);
39 wmove (win, choice, 0); 38 wmove(win, choice, 0);
40 for (i = 0; i < list_width; i++) 39 for (i = 0; i < list_width; i++)
41 waddch (win, ' '); 40 waddch(win, ' ');
42 41
43 wmove (win, choice, check_x); 42 wmove(win, choice, check_x);
44 wattrset (win, selected ? check_selected_attr : check_attr); 43 wattrset(win, selected ? check_selected_attr : check_attr);
45 if (checkflag == FLAG_CHECK) 44 if (checkflag == FLAG_CHECK)
46 wprintw (win, "[%c]", status ? 'X' : ' '); 45 wprintw(win, "[%c]", status ? 'X' : ' ');
47 else 46 else
48 wprintw (win, "(%c)", status ? 'X' : ' '); 47 wprintw(win, "(%c)", status ? 'X' : ' ');
49 48
50 wattrset (win, selected ? tag_selected_attr : tag_attr); 49 wattrset(win, selected ? tag_selected_attr : tag_attr);
51 mvwaddch(win, choice, item_x, item[0]); 50 mvwaddch(win, choice, item_x, item[0]);
52 wattrset (win, selected ? item_selected_attr : item_attr); 51 wattrset(win, selected ? item_selected_attr : item_attr);
53 waddstr (win, (char *)item+1); 52 waddstr(win, (char *)item + 1);
54 if (selected) { 53 if (selected) {
55 wmove (win, choice, check_x+1); 54 wmove(win, choice, check_x + 1);
56 wrefresh (win); 55 wrefresh(win);
57 } 56 }
58} 57}
59 58
60/* 59/*
61 * Print the scroll indicators. 60 * Print the scroll indicators.
62 */ 61 */
63static void 62static void
64print_arrows (WINDOW * win, int choice, int item_no, int scroll, 63print_arrows(WINDOW * win, int choice, int item_no, int scroll,
65 int y, int x, int height) 64 int y, int x, int height)
66{ 65{
67 wmove(win, y, x); 66 wmove(win, y, x);
68 67
69 if (scroll > 0) { 68 if (scroll > 0) {
70 wattrset (win, uarrow_attr); 69 wattrset(win, uarrow_attr);
71 waddch (win, ACS_UARROW); 70 waddch(win, ACS_UARROW);
72 waddstr (win, "(-)"); 71 waddstr(win, "(-)");
73 } 72 } else {
74 else { 73 wattrset(win, menubox_attr);
75 wattrset (win, menubox_attr); 74 waddch(win, ACS_HLINE);
76 waddch (win, ACS_HLINE); 75 waddch(win, ACS_HLINE);
77 waddch (win, ACS_HLINE); 76 waddch(win, ACS_HLINE);
78 waddch (win, ACS_HLINE); 77 waddch(win, ACS_HLINE);
79 waddch (win, ACS_HLINE); 78 }
80 } 79
81 80 y = y + height + 1;
82 y = y + height + 1; 81 wmove(win, y, x);
83 wmove(win, y, x); 82
84 83 if ((height < item_no) && (scroll + choice < item_no - 1)) {
85 if ((height < item_no) && (scroll + choice < item_no - 1)) { 84 wattrset(win, darrow_attr);
86 wattrset (win, darrow_attr); 85 waddch(win, ACS_DARROW);
87 waddch (win, ACS_DARROW); 86 waddstr(win, "(+)");
88 waddstr (win, "(+)"); 87 } else {
89 } 88 wattrset(win, menubox_border_attr);
90 else { 89 waddch(win, ACS_HLINE);
91 wattrset (win, menubox_border_attr); 90 waddch(win, ACS_HLINE);
92 waddch (win, ACS_HLINE); 91 waddch(win, ACS_HLINE);
93 waddch (win, ACS_HLINE); 92 waddch(win, ACS_HLINE);
94 waddch (win, ACS_HLINE); 93 }
95 waddch (win, ACS_HLINE);
96 }
97} 94}
98 95
99/* 96/*
100 * Display the termination buttons 97 * Display the termination buttons
101 */ 98 */
102static void 99static void print_buttons(WINDOW * dialog, int height, int width, int selected)
103print_buttons( WINDOW *dialog, int height, int width, int selected)
104{ 100{
105 int x = width / 2 - 11; 101 int x = width / 2 - 11;
106 int y = height - 2; 102 int y = height - 2;
107 103
108 print_button (dialog, "Select", y, x, selected == 0); 104 print_button(dialog, "Select", y, x, selected == 0);
109 print_button (dialog, " Help ", y, x + 14, selected == 1); 105 print_button(dialog, " Help ", y, x + 14, selected == 1);
110 106
111 wmove(dialog, y, x+1 + 14*selected); 107 wmove(dialog, y, x + 1 + 14 * selected);
112 wrefresh (dialog); 108 wrefresh(dialog);
113} 109}
114 110
115/* 111/*
@@ -117,257 +113,293 @@ print_buttons( WINDOW *dialog, int height, int width, int selected)
117 * The `flag' parameter is used to select between radiolist and checklist. 113 * The `flag' parameter is used to select between radiolist and checklist.
118 */ 114 */
119int 115int
120dialog_checklist (const char *title, const char *prompt, int height, int width, 116dialog_checklist(const char *title, const char *prompt, int height, int width,
121 int list_height, int item_no, const char * const * items, int flag) 117 int list_height, int item_no, const char *const *items,
122 118 int flag)
123{ 119{
124 int i, x, y, box_x, box_y; 120 int i, x, y, box_x, box_y;
125 int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status; 121 int key = 0, button = 0, choice = 0, scroll = 0, max_choice, *status;
126 WINDOW *dialog, *list; 122 WINDOW *dialog, *list;
127 123
128 checkflag = flag; 124 checkflag = flag;
129 125
130 /* Allocate space for storing item on/off status */ 126 /* Allocate space for storing item on/off status */
131 if ((status = malloc (sizeof (int) * item_no)) == NULL) { 127 if ((status = malloc(sizeof(int) * item_no)) == NULL) {
132 endwin (); 128 endwin();
133 fprintf (stderr, 129 fprintf(stderr,
134 "\nCan't allocate memory in dialog_checklist().\n"); 130 "\nCan't allocate memory in dialog_checklist().\n");
135 exit (-1); 131 exit(-1);
136 }
137
138 /* Initializes status */
139 for (i = 0; i < item_no; i++) {
140 status[i] = !strcasecmp (items[i * 3 + 2], "on");
141 if ((!choice && status[i]) || !strcasecmp (items[i * 3 + 2], "selected"))
142 choice = i + 1;
143 }
144 if (choice)
145 choice--;
146
147 max_choice = MIN (list_height, item_no);
148
149 /* center dialog box on screen */
150 x = (COLS - width) / 2;
151 y = (LINES - height) / 2;
152
153 draw_shadow (stdscr, y, x, height, width);
154
155 dialog = newwin (height, width, y, x);
156 keypad (dialog, TRUE);
157
158 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
159 wattrset (dialog, border_attr);
160 mvwaddch (dialog, height-3, 0, ACS_LTEE);
161 for (i = 0; i < width - 2; i++)
162 waddch (dialog, ACS_HLINE);
163 wattrset (dialog, dialog_attr);
164 waddch (dialog, ACS_RTEE);
165
166 if (title != NULL && strlen(title) >= width-2 ) {
167 /* truncate long title -- mec */
168 char * title2 = malloc(width-2+1);
169 memcpy( title2, title, width-2 );
170 title2[width-2] = '\0';
171 title = title2;
172 }
173
174 if (title != NULL) {
175 wattrset (dialog, title_attr);
176 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
177 waddstr (dialog, (char *)title);
178 waddch (dialog, ' ');
179 }
180
181 wattrset (dialog, dialog_attr);
182 print_autowrap (dialog, prompt, width - 2, 1, 3);
183
184 list_width = width - 6;
185 box_y = height - list_height - 5;
186 box_x = (width - list_width) / 2 - 1;
187
188 /* create new window for the list */
189 list = subwin (dialog, list_height, list_width, y+box_y+1, x+box_x+1);
190
191 keypad (list, TRUE);
192
193 /* draw a box around the list items */
194 draw_box (dialog, box_y, box_x, list_height + 2, list_width + 2,
195 menubox_border_attr, menubox_attr);
196
197 /* Find length of longest item in order to center checklist */
198 check_x = 0;
199 for (i = 0; i < item_no; i++)
200 check_x = MAX (check_x, + strlen (items[i * 3 + 1]) + 4);
201
202 check_x = (list_width - check_x) / 2;
203 item_x = check_x + 4;
204
205 if (choice >= list_height) {
206 scroll = choice - list_height + 1;
207 choice -= scroll;
208 }
209
210 /* Print the list */
211 for (i = 0; i < max_choice; i++) {
212 print_item (list, items[(scroll+i) * 3 + 1],
213 status[i+scroll], i, i == choice);
214 }
215
216 print_arrows(dialog, choice, item_no, scroll,
217 box_y, box_x + check_x + 5, list_height);
218
219 print_buttons(dialog, height, width, 0);
220
221 wnoutrefresh (list);
222 wnoutrefresh (dialog);
223 doupdate ();
224
225 while (key != ESC) {
226 key = wgetch (dialog);
227
228 for (i = 0; i < max_choice; i++)
229 if (toupper(key) == toupper(items[(scroll+i)*3+1][0]))
230 break;
231
232
233 if ( i < max_choice || key == KEY_UP || key == KEY_DOWN ||
234 key == '+' || key == '-' ) {
235 if (key == KEY_UP || key == '-') {
236 if (!choice) {
237 if (!scroll)
238 continue;
239 /* Scroll list down */
240 if (list_height > 1) {
241 /* De-highlight current first item */
242 print_item (list, items[scroll * 3 + 1],
243 status[scroll], 0, FALSE);
244 scrollok (list, TRUE);
245 wscrl (list, -1);
246 scrollok (list, FALSE);
247 }
248 scroll--;
249 print_item (list, items[scroll * 3 + 1],
250 status[scroll], 0, TRUE);
251 wnoutrefresh (list);
252
253 print_arrows(dialog, choice, item_no, scroll,
254 box_y, box_x + check_x + 5, list_height);
255
256 wrefresh (dialog);
257
258 continue; /* wait for another key press */
259 } else
260 i = choice - 1;
261 } else if (key == KEY_DOWN || key == '+') {
262 if (choice == max_choice - 1) {
263 if (scroll + choice >= item_no - 1)
264 continue;
265 /* Scroll list up */
266 if (list_height > 1) {
267 /* De-highlight current last item before scrolling up */
268 print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
269 status[scroll + max_choice - 1],
270 max_choice - 1, FALSE);
271 scrollok (list, TRUE);
272 wscrl (list, 1);
273 scrollok (list, FALSE);
274 }
275 scroll++;
276 print_item (list, items[(scroll + max_choice - 1) * 3 + 1],
277 status[scroll + max_choice - 1],
278 max_choice - 1, TRUE);
279 wnoutrefresh (list);
280
281 print_arrows(dialog, choice, item_no, scroll,
282 box_y, box_x + check_x + 5, list_height);
283
284 wrefresh (dialog);
285
286 continue; /* wait for another key press */
287 } else
288 i = choice + 1;
289 }
290 if (i != choice) {
291 /* De-highlight current item */
292 print_item (list, items[(scroll + choice) * 3 + 1],
293 status[scroll + choice], choice, FALSE);
294 /* Highlight new item */
295 choice = i;
296 print_item (list, items[(scroll + choice) * 3 + 1],
297 status[scroll + choice], choice, TRUE);
298 wnoutrefresh (list);
299 wrefresh (dialog);
300 }
301 continue; /* wait for another key press */
302 } 132 }
303 switch (key) {
304 case 'H':
305 case 'h':
306 case '?':
307 fprintf (stderr, "%s", items[(scroll + choice) * 3]);
308 delwin (dialog);
309 free (status);
310 return 1;
311 case TAB:
312 case KEY_LEFT:
313 case KEY_RIGHT:
314 button = ((key == KEY_LEFT ? --button : ++button) < 0)
315 ? 1 : (button > 1 ? 0 : button);
316
317 print_buttons(dialog, height, width, button);
318 wrefresh (dialog);
319 break;
320 case 'S':
321 case 's':
322 case ' ':
323 case '\n':
324 if (!button) {
325 if (flag == FLAG_CHECK) {
326 status[scroll + choice] = !status[scroll + choice];
327 wmove (list, choice, check_x);
328 wattrset (list, check_selected_attr);
329 wprintw (list, "[%c]", status[scroll + choice] ? 'X' : ' ');
330 } else {
331 if (!status[scroll + choice]) {
332 for (i = 0; i < item_no; i++)
333 status[i] = 0;
334 status[scroll + choice] = 1;
335 for (i = 0; i < max_choice; i++)
336 print_item (list, items[(scroll + i) * 3 + 1],
337 status[scroll + i], i, i == choice);
338 }
339 }
340 wnoutrefresh (list);
341 wrefresh (dialog);
342
343 for (i = 0; i < item_no; i++) {
344 if (status[i]) {
345 if (flag == FLAG_CHECK) {
346 fprintf (stderr, "\"%s\" ", items[i * 3]);
347 } else {
348 fprintf (stderr, "%s", items[i * 3]);
349 }
350 133
351 } 134 /* Initializes status */
352 } 135 for (i = 0; i < item_no; i++) {
353 } else 136 status[i] = !strcasecmp(items[i * 3 + 2], "on");
354 fprintf (stderr, "%s", items[(scroll + choice) * 3]); 137 if ((!choice && status[i])
355 delwin (dialog); 138 || !strcasecmp(items[i * 3 + 2], "selected"))
356 free (status); 139 choice = i + 1;
357 return button; 140 }
358 case 'X': 141 if (choice)
359 case 'x': 142 choice--;
360 key = ESC; 143
361 case ESC: 144 max_choice = MIN(list_height, item_no);
362 break; 145
146 /* center dialog box on screen */
147 x = (COLS - width) / 2;
148 y = (LINES - height) / 2;
149
150 draw_shadow(stdscr, y, x, height, width);
151
152 dialog = newwin(height, width, y, x);
153 keypad(dialog, TRUE);
154
155 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
156 wattrset(dialog, border_attr);
157 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
158 for (i = 0; i < width - 2; i++)
159 waddch(dialog, ACS_HLINE);
160 wattrset(dialog, dialog_attr);
161 waddch(dialog, ACS_RTEE);
162
163 if (title != NULL && strlen(title) >= width - 2) {
164 /* truncate long title -- mec */
165 char *title2 = malloc(width - 2 + 1);
166 memcpy(title2, title, width - 2);
167 title2[width - 2] = '\0';
168 title = title2;
169 }
170
171 if (title != NULL) {
172 wattrset(dialog, title_attr);
173 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
174 waddstr(dialog, (char *)title);
175 waddch(dialog, ' ');
176 }
177
178 wattrset(dialog, dialog_attr);
179 print_autowrap(dialog, prompt, width - 2, 1, 3);
180
181 list_width = width - 6;
182 box_y = height - list_height - 5;
183 box_x = (width - list_width) / 2 - 1;
184
185 /* create new window for the list */
186 list =
187 subwin(dialog, list_height, list_width, y + box_y + 1,
188 x + box_x + 1);
189
190 keypad(list, TRUE);
191
192 /* draw a box around the list items */
193 draw_box(dialog, box_y, box_x, list_height + 2, list_width + 2,
194 menubox_border_attr, menubox_attr);
195
196 /* Find length of longest item in order to center checklist */
197 check_x = 0;
198 for (i = 0; i < item_no; i++)
199 check_x = MAX(check_x, +strlen(items[i * 3 + 1]) + 4);
200
201 check_x = (list_width - check_x) / 2;
202 item_x = check_x + 4;
203
204 if (choice >= list_height) {
205 scroll = choice - list_height + 1;
206 choice -= scroll;
207 }
208
209 /* Print the list */
210 for (i = 0; i < max_choice; i++) {
211 print_item(list, items[(scroll + i) * 3 + 1],
212 status[i + scroll], i, i == choice);
363 } 213 }
364 214
365 /* Now, update everything... */ 215 print_arrows(dialog, choice, item_no, scroll,
366 doupdate (); 216 box_y, box_x + check_x + 5, list_height);
367 } 217
368 218 print_buttons(dialog, height, width, 0);
219
220 wnoutrefresh(list);
221 wnoutrefresh(dialog);
222 doupdate();
223
224 while (key != ESC) {
225 key = wgetch(dialog);
226
227 for (i = 0; i < max_choice; i++)
228 if (toupper(key) ==
229 toupper(items[(scroll + i) * 3 + 1][0]))
230 break;
231
232 if (i < max_choice || key == KEY_UP || key == KEY_DOWN ||
233 key == '+' || key == '-') {
234 if (key == KEY_UP || key == '-') {
235 if (!choice) {
236 if (!scroll)
237 continue;
238 /* Scroll list down */
239 if (list_height > 1) {
240 /* De-highlight current first item */
241 print_item(list,
242 items[scroll * 3 +
243 1],
244 status[scroll], 0,
245 FALSE);
246 scrollok(list, TRUE);
247 wscrl(list, -1);
248 scrollok(list, FALSE);
249 }
250 scroll--;
251 print_item(list, items[scroll * 3 + 1],
252 status[scroll], 0, TRUE);
253 wnoutrefresh(list);
254
255 print_arrows(dialog, choice, item_no,
256 scroll, box_y,
257 box_x + check_x + 5,
258 list_height);
259
260 wrefresh(dialog);
261
262 continue; /* wait for another key press */
263 } else
264 i = choice - 1;
265 } else if (key == KEY_DOWN || key == '+') {
266 if (choice == max_choice - 1) {
267 if (scroll + choice >= item_no - 1)
268 continue;
269 /* Scroll list up */
270 if (list_height > 1) {
271 /* De-highlight current last item before scrolling up */
272 print_item(list,
273 items[(scroll +
274 max_choice -
275 1) * 3 + 1],
276 status[scroll +
277 max_choice -
278 1],
279 max_choice - 1,
280 FALSE);
281 scrollok(list, TRUE);
282 wscrl(list, 1);
283 scrollok(list, FALSE);
284 }
285 scroll++;
286 print_item(list,
287 items[(scroll + max_choice -
288 1) * 3 + 1],
289 status[scroll + max_choice -
290 1], max_choice - 1,
291 TRUE);
292 wnoutrefresh(list);
293
294 print_arrows(dialog, choice, item_no,
295 scroll, box_y,
296 box_x + check_x + 5,
297 list_height);
298
299 wrefresh(dialog);
300
301 continue; /* wait for another key press */
302 } else
303 i = choice + 1;
304 }
305 if (i != choice) {
306 /* De-highlight current item */
307 print_item(list,
308 items[(scroll + choice) * 3 + 1],
309 status[scroll + choice], choice,
310 FALSE);
311 /* Highlight new item */
312 choice = i;
313 print_item(list,
314 items[(scroll + choice) * 3 + 1],
315 status[scroll + choice], choice,
316 TRUE);
317 wnoutrefresh(list);
318 wrefresh(dialog);
319 }
320 continue; /* wait for another key press */
321 }
322 switch (key) {
323 case 'H':
324 case 'h':
325 case '?':
326 fprintf(stderr, "%s", items[(scroll + choice) * 3]);
327 delwin(dialog);
328 free(status);
329 return 1;
330 case TAB:
331 case KEY_LEFT:
332 case KEY_RIGHT:
333 button = ((key == KEY_LEFT ? --button : ++button) < 0)
334 ? 1 : (button > 1 ? 0 : button);
335
336 print_buttons(dialog, height, width, button);
337 wrefresh(dialog);
338 break;
339 case 'S':
340 case 's':
341 case ' ':
342 case '\n':
343 if (!button) {
344 if (flag == FLAG_CHECK) {
345 status[scroll + choice] =
346 !status[scroll + choice];
347 wmove(list, choice, check_x);
348 wattrset(list, check_selected_attr);
349 wprintw(list, "[%c]",
350 status[scroll +
351 choice] ? 'X' : ' ');
352 } else {
353 if (!status[scroll + choice]) {
354 for (i = 0; i < item_no; i++)
355 status[i] = 0;
356 status[scroll + choice] = 1;
357 for (i = 0; i < max_choice; i++)
358 print_item(list,
359 items[(scroll
360 +
361 i) *
362 3 + 1],
363 status[scroll
364 + i],
365 i,
366 i == choice);
367 }
368 }
369 wnoutrefresh(list);
370 wrefresh(dialog);
371
372 for (i = 0; i < item_no; i++) {
373 if (status[i]) {
374 if (flag == FLAG_CHECK) {
375 fprintf(stderr,
376 "\"%s\" ",
377 items[i * 3]);
378 } else {
379 fprintf(stderr, "%s",
380 items[i * 3]);
381 }
382
383 }
384 }
385 } else
386 fprintf(stderr, "%s",
387 items[(scroll + choice) * 3]);
388 delwin(dialog);
389 free(status);
390 return button;
391 case 'X':
392 case 'x':
393 key = ESC;
394 case ESC:
395 break;
396 }
397
398 /* Now, update everything... */
399 doupdate();
400 }
369 401
370 delwin (dialog); 402 delwin(dialog);
371 free (status); 403 free(status);
372 return -1; /* ESC pressed */ 404 return -1; /* ESC pressed */
373} 405}
diff --git a/scripts/lxdialog/colors.h b/scripts/lxdialog/colors.h
index 25c59528a251..db071df12bbb 100644
--- a/scripts/lxdialog/colors.h
+++ b/scripts/lxdialog/colors.h
@@ -18,7 +18,6 @@
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21
22/* 21/*
23 * Default color definitions 22 * Default color definitions
24 * 23 *
diff --git a/scripts/lxdialog/dialog.h b/scripts/lxdialog/dialog.h
index eb63e1bb63a3..c86801f981fe 100644
--- a/scripts/lxdialog/dialog.h
+++ b/scripts/lxdialog/dialog.h
@@ -42,7 +42,7 @@
42#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE) 42#if defined(NCURSES_VERSION) && defined(_NEED_WRAP) && !defined(GCC_PRINTFLIKE)
43#define OLD_NCURSES 1 43#define OLD_NCURSES 1
44#undef wbkgdset 44#undef wbkgdset
45#define wbkgdset(w,p) /*nothing*/ 45#define wbkgdset(w,p) /*nothing */
46#else 46#else
47#define OLD_NCURSES 0 47#define OLD_NCURSES 0
48#endif 48#endif
@@ -56,7 +56,6 @@
56#define MIN(x,y) (x < y ? x : y) 56#define MIN(x,y) (x < y ? x : y)
57#define MAX(x,y) (x > y ? x : y) 57#define MAX(x,y) (x > y ? x : y)
58 58
59
60#ifndef ACS_ULCORNER 59#ifndef ACS_ULCORNER
61#define ACS_ULCORNER '+' 60#define ACS_ULCORNER '+'
62#endif 61#endif
@@ -137,35 +136,34 @@ extern const char *backtitle;
137/* 136/*
138 * Function prototypes 137 * Function prototypes
139 */ 138 */
140extern void create_rc (const char *filename); 139extern void create_rc(const char *filename);
141extern int parse_rc (void); 140extern int parse_rc(void);
142 141
143 142void init_dialog(void);
144void init_dialog (void); 143void end_dialog(void);
145void end_dialog (void); 144void attr_clear(WINDOW * win, int height, int width, chtype attr);
146void attr_clear (WINDOW * win, int height, int width, chtype attr); 145void dialog_clear(void);
147void dialog_clear (void); 146void color_setup(void);
148void color_setup (void); 147void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x);
149void print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x); 148void print_button(WINDOW * win, const char *label, int y, int x, int selected);
150void print_button (WINDOW * win, const char *label, int y, int x, int selected); 149void draw_box(WINDOW * win, int y, int x, int height, int width, chtype box,
151void draw_box (WINDOW * win, int y, int x, int height, int width, chtype box, 150 chtype border);
152 chtype border); 151void draw_shadow(WINDOW * win, int y, int x, int height, int width);
153void draw_shadow (WINDOW * win, int y, int x, int height, int width); 152
154 153int first_alpha(const char *string, const char *exempt);
155int first_alpha (const char *string, const char *exempt); 154int dialog_yesno(const char *title, const char *prompt, int height, int width);
156int dialog_yesno (const char *title, const char *prompt, int height, int width); 155int dialog_msgbox(const char *title, const char *prompt, int height,
157int dialog_msgbox (const char *title, const char *prompt, int height, 156 int width, int pause);
158 int width, int pause); 157int dialog_textbox(const char *title, const char *file, int height, int width);
159int dialog_textbox (const char *title, const char *file, int height, int width); 158int dialog_menu(const char *title, const char *prompt, int height, int width,
160int dialog_menu (const char *title, const char *prompt, int height, int width, 159 int menu_height, const char *choice, int item_no,
161 int menu_height, const char *choice, int item_no, 160 const char *const *items);
162 const char * const * items); 161int dialog_checklist(const char *title, const char *prompt, int height,
163int dialog_checklist (const char *title, const char *prompt, int height, 162 int width, int list_height, int item_no,
164 int width, int list_height, int item_no, 163 const char *const *items, int flag);
165 const char * const * items, int flag);
166extern char dialog_input_result[]; 164extern char dialog_input_result[];
167int dialog_inputbox (const char *title, const char *prompt, int height, 165int dialog_inputbox(const char *title, const char *prompt, int height,
168 int width, const char *init); 166 int width, const char *init);
169 167
170/* 168/*
171 * This is the base for fictitious keys, which activate 169 * This is the base for fictitious keys, which activate
@@ -178,7 +176,6 @@ int dialog_inputbox (const char *title, const char *prompt, int height,
178 */ 176 */
179#define M_EVENT (KEY_MAX+1) 177#define M_EVENT (KEY_MAX+1)
180 178
181
182/* 179/*
183 * The `flag' parameter in checklist is used to select between 180 * The `flag' parameter in checklist is used to select between
184 * radiolist and checklist 181 * radiolist and checklist
diff --git a/scripts/lxdialog/inputbox.c b/scripts/lxdialog/inputbox.c
index 074d2d68bd31..9e9691567269 100644
--- a/scripts/lxdialog/inputbox.c
+++ b/scripts/lxdialog/inputbox.c
@@ -26,215 +26,231 @@ char dialog_input_result[MAX_LEN + 1];
26/* 26/*
27 * Print the termination buttons 27 * Print the termination buttons
28 */ 28 */
29static void 29static void print_buttons(WINDOW * dialog, int height, int width, int selected)
30print_buttons(WINDOW *dialog, int height, int width, int selected)
31{ 30{
32 int x = width / 2 - 11; 31 int x = width / 2 - 11;
33 int y = height - 2; 32 int y = height - 2;
34 33
35 print_button (dialog, " Ok ", y, x, selected==0); 34 print_button(dialog, " Ok ", y, x, selected == 0);
36 print_button (dialog, " Help ", y, x + 14, selected==1); 35 print_button(dialog, " Help ", y, x + 14, selected == 1);
37 36
38 wmove(dialog, y, x+1+14*selected); 37 wmove(dialog, y, x + 1 + 14 * selected);
39 wrefresh(dialog); 38 wrefresh(dialog);
40} 39}
41 40
42/* 41/*
43 * Display a dialog box for inputing a string 42 * Display a dialog box for inputing a string
44 */ 43 */
45int 44int
46dialog_inputbox (const char *title, const char *prompt, int height, int width, 45dialog_inputbox(const char *title, const char *prompt, int height, int width,
47 const char *init) 46 const char *init)
48{ 47{
49 int i, x, y, box_y, box_x, box_width; 48 int i, x, y, box_y, box_x, box_width;
50 int input_x = 0, scroll = 0, key = 0, button = -1; 49 int input_x = 0, scroll = 0, key = 0, button = -1;
51 char *instr = dialog_input_result; 50 char *instr = dialog_input_result;
52 WINDOW *dialog; 51 WINDOW *dialog;
53 52
54 /* center dialog box on screen */ 53 /* center dialog box on screen */
55 x = (COLS - width) / 2; 54 x = (COLS - width) / 2;
56 y = (LINES - height) / 2; 55 y = (LINES - height) / 2;
57 56
58 57 draw_shadow(stdscr, y, x, height, width);
59 draw_shadow (stdscr, y, x, height, width); 58
60 59 dialog = newwin(height, width, y, x);
61 dialog = newwin (height, width, y, x); 60 keypad(dialog, TRUE);
62 keypad (dialog, TRUE); 61
63 62 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
64 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); 63 wattrset(dialog, border_attr);
65 wattrset (dialog, border_attr); 64 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
66 mvwaddch (dialog, height-3, 0, ACS_LTEE); 65 for (i = 0; i < width - 2; i++)
67 for (i = 0; i < width - 2; i++) 66 waddch(dialog, ACS_HLINE);
68 waddch (dialog, ACS_HLINE); 67 wattrset(dialog, dialog_attr);
69 wattrset (dialog, dialog_attr); 68 waddch(dialog, ACS_RTEE);
70 waddch (dialog, ACS_RTEE); 69
71 70 if (title != NULL && strlen(title) >= width - 2) {
72 if (title != NULL && strlen(title) >= width-2 ) { 71 /* truncate long title -- mec */
73 /* truncate long title -- mec */ 72 char *title2 = malloc(width - 2 + 1);
74 char * title2 = malloc(width-2+1); 73 memcpy(title2, title, width - 2);
75 memcpy( title2, title, width-2 ); 74 title2[width - 2] = '\0';
76 title2[width-2] = '\0'; 75 title = title2;
77 title = title2; 76 }
78 } 77
79 78 if (title != NULL) {
80 if (title != NULL) { 79 wattrset(dialog, title_attr);
81 wattrset (dialog, title_attr); 80 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
82 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 81 waddstr(dialog, (char *)title);
83 waddstr (dialog, (char *)title); 82 waddch(dialog, ' ');
84 waddch (dialog, ' '); 83 }
85 } 84
86 85 wattrset(dialog, dialog_attr);
87 wattrset (dialog, dialog_attr); 86 print_autowrap(dialog, prompt, width - 2, 1, 3);
88 print_autowrap (dialog, prompt, width - 2, 1, 3); 87
89 88 /* Draw the input field box */
90 /* Draw the input field box */ 89 box_width = width - 6;
91 box_width = width - 6; 90 getyx(dialog, y, x);
92 getyx (dialog, y, x); 91 box_y = y + 2;
93 box_y = y + 2; 92 box_x = (width - box_width) / 2;
94 box_x = (width - box_width) / 2; 93 draw_box(dialog, y + 1, box_x - 1, 3, box_width + 2,
95 draw_box (dialog, y + 1, box_x - 1, 3, box_width + 2, 94 border_attr, dialog_attr);
96 border_attr, dialog_attr); 95
97 96 print_buttons(dialog, height, width, 0);
98 print_buttons(dialog, height, width, 0); 97
99 98 /* Set up the initial value */
100 /* Set up the initial value */ 99 wmove(dialog, box_y, box_x);
101 wmove (dialog, box_y, box_x); 100 wattrset(dialog, inputbox_attr);
102 wattrset (dialog, inputbox_attr); 101
103 102 if (!init)
104 if (!init) 103 instr[0] = '\0';
105 instr[0] = '\0'; 104 else
106 else 105 strcpy(instr, init);
107 strcpy (instr, init); 106
108 107 input_x = strlen(instr);
109 input_x = strlen (instr); 108
110 109 if (input_x >= box_width) {
111 if (input_x >= box_width) { 110 scroll = input_x - box_width + 1;
112 scroll = input_x - box_width + 1; 111 input_x = box_width - 1;
113 input_x = box_width - 1; 112 for (i = 0; i < box_width - 1; i++)
114 for (i = 0; i < box_width - 1; i++) 113 waddch(dialog, instr[scroll + i]);
115 waddch (dialog, instr[scroll + i]); 114 } else
116 } else 115 waddstr(dialog, instr);
117 waddstr (dialog, instr); 116
118 117 wmove(dialog, box_y, box_x + input_x);
119 wmove (dialog, box_y, box_x + input_x); 118
120 119 wrefresh(dialog);
121 wrefresh (dialog); 120
122 121 while (key != ESC) {
123 while (key != ESC) { 122 key = wgetch(dialog);
124 key = wgetch (dialog); 123
125 124 if (button == -1) { /* Input box selected */
126 if (button == -1) { /* Input box selected */ 125 switch (key) {
127 switch (key) { 126 case TAB:
128 case TAB: 127 case KEY_UP:
129 case KEY_UP: 128 case KEY_DOWN:
130 case KEY_DOWN: 129 break;
131 break; 130 case KEY_LEFT:
132 case KEY_LEFT: 131 continue;
133 continue; 132 case KEY_RIGHT:
134 case KEY_RIGHT: 133 continue;
135 continue; 134 case KEY_BACKSPACE:
136 case KEY_BACKSPACE: 135 case 127:
137 case 127: 136 if (input_x || scroll) {
138 if (input_x || scroll) { 137 wattrset(dialog, inputbox_attr);
139 wattrset (dialog, inputbox_attr); 138 if (!input_x) {
140 if (!input_x) { 139 scroll =
141 scroll = scroll < box_width - 1 ? 140 scroll <
142 0 : scroll - (box_width - 1); 141 box_width - 1 ? 0 : scroll -
143 wmove (dialog, box_y, box_x); 142 (box_width - 1);
144 for (i = 0; i < box_width; i++) 143 wmove(dialog, box_y, box_x);
145 waddch (dialog, instr[scroll + input_x + i] ? 144 for (i = 0; i < box_width; i++)
146 instr[scroll + input_x + i] : ' '); 145 waddch(dialog,
147 input_x = strlen (instr) - scroll; 146 instr[scroll +
148 } else 147 input_x +
149 input_x--; 148 i] ?
150 instr[scroll + input_x] = '\0'; 149 instr[scroll +
151 mvwaddch (dialog, box_y, input_x + box_x, ' '); 150 input_x +
152 wmove (dialog, box_y, input_x + box_x); 151 i] : ' ');
153 wrefresh (dialog); 152 input_x =
153 strlen(instr) - scroll;
154 } else
155 input_x--;
156 instr[scroll + input_x] = '\0';
157 mvwaddch(dialog, box_y, input_x + box_x,
158 ' ');
159 wmove(dialog, box_y, input_x + box_x);
160 wrefresh(dialog);
161 }
162 continue;
163 default:
164 if (key < 0x100 && isprint(key)) {
165 if (scroll + input_x < MAX_LEN) {
166 wattrset(dialog, inputbox_attr);
167 instr[scroll + input_x] = key;
168 instr[scroll + input_x + 1] =
169 '\0';
170 if (input_x == box_width - 1) {
171 scroll++;
172 wmove(dialog, box_y,
173 box_x);
174 for (i = 0;
175 i < box_width - 1;
176 i++)
177 waddch(dialog,
178 instr
179 [scroll +
180 i]);
181 } else {
182 wmove(dialog, box_y,
183 input_x++ +
184 box_x);
185 waddch(dialog, key);
186 }
187 wrefresh(dialog);
188 } else
189 flash(); /* Alarm user about overflow */
190 continue;
191 }
192 }
154 } 193 }
155 continue; 194 switch (key) {
156 default: 195 case 'O':
157 if (key < 0x100 && isprint (key)) { 196 case 'o':
158 if (scroll + input_x < MAX_LEN) { 197 delwin(dialog);
159 wattrset (dialog, inputbox_attr); 198 return 0;
160 instr[scroll + input_x] = key; 199 case 'H':
161 instr[scroll + input_x + 1] = '\0'; 200 case 'h':
162 if (input_x == box_width - 1) { 201 delwin(dialog);
163 scroll++; 202 return 1;
164 wmove (dialog, box_y, box_x); 203 case KEY_UP:
165 for (i = 0; i < box_width - 1; i++) 204 case KEY_LEFT:
166 waddch (dialog, instr[scroll + i]); 205 switch (button) {
167 } else { 206 case -1:
168 wmove (dialog, box_y, input_x++ + box_x); 207 button = 1; /* Indicates "Cancel" button is selected */
169 waddch (dialog, key); 208 print_buttons(dialog, height, width, 1);
209 break;
210 case 0:
211 button = -1; /* Indicates input box is selected */
212 print_buttons(dialog, height, width, 0);
213 wmove(dialog, box_y, box_x + input_x);
214 wrefresh(dialog);
215 break;
216 case 1:
217 button = 0; /* Indicates "OK" button is selected */
218 print_buttons(dialog, height, width, 0);
219 break;
170 } 220 }
171 wrefresh (dialog); 221 break;
172 } else 222 case TAB:
173 flash (); /* Alarm user about overflow */ 223 case KEY_DOWN:
174 continue; 224 case KEY_RIGHT:
225 switch (button) {
226 case -1:
227 button = 0; /* Indicates "OK" button is selected */
228 print_buttons(dialog, height, width, 0);
229 break;
230 case 0:
231 button = 1; /* Indicates "Cancel" button is selected */
232 print_buttons(dialog, height, width, 1);
233 break;
234 case 1:
235 button = -1; /* Indicates input box is selected */
236 print_buttons(dialog, height, width, 0);
237 wmove(dialog, box_y, box_x + input_x);
238 wrefresh(dialog);
239 break;
240 }
241 break;
242 case ' ':
243 case '\n':
244 delwin(dialog);
245 return (button == -1 ? 0 : button);
246 case 'X':
247 case 'x':
248 key = ESC;
249 case ESC:
250 break;
175 } 251 }
176 }
177 }
178 switch (key) {
179 case 'O':
180 case 'o':
181 delwin (dialog);
182 return 0;
183 case 'H':
184 case 'h':
185 delwin (dialog);
186 return 1;
187 case KEY_UP:
188 case KEY_LEFT:
189 switch (button) {
190 case -1:
191 button = 1; /* Indicates "Cancel" button is selected */
192 print_buttons(dialog, height, width, 1);
193 break;
194 case 0:
195 button = -1; /* Indicates input box is selected */
196 print_buttons(dialog, height, width, 0);
197 wmove (dialog, box_y, box_x + input_x);
198 wrefresh (dialog);
199 break;
200 case 1:
201 button = 0; /* Indicates "OK" button is selected */
202 print_buttons(dialog, height, width, 0);
203 break;
204 }
205 break;
206 case TAB:
207 case KEY_DOWN:
208 case KEY_RIGHT:
209 switch (button) {
210 case -1:
211 button = 0; /* Indicates "OK" button is selected */
212 print_buttons(dialog, height, width, 0);
213 break;
214 case 0:
215 button = 1; /* Indicates "Cancel" button is selected */
216 print_buttons(dialog, height, width, 1);
217 break;
218 case 1:
219 button = -1; /* Indicates input box is selected */
220 print_buttons(dialog, height, width, 0);
221 wmove (dialog, box_y, box_x + input_x);
222 wrefresh (dialog);
223 break;
224 }
225 break;
226 case ' ':
227 case '\n':
228 delwin (dialog);
229 return (button == -1 ? 0 : button);
230 case 'X':
231 case 'x':
232 key = ESC;
233 case ESC:
234 break;
235 } 252 }
236 }
237 253
238 delwin (dialog); 254 delwin(dialog);
239 return -1; /* ESC pressed */ 255 return -1; /* ESC pressed */
240} 256}
diff --git a/scripts/lxdialog/lxdialog.c b/scripts/lxdialog/lxdialog.c
index f283a8545426..2c34ea1e0a41 100644
--- a/scripts/lxdialog/lxdialog.c
+++ b/scripts/lxdialog/lxdialog.c
@@ -21,30 +21,29 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24static void Usage (const char *name); 24static void Usage(const char *name);
25 25
26typedef int (jumperFn) (const char *title, int argc, const char * const * argv); 26typedef int (jumperFn) (const char *title, int argc, const char *const *argv);
27 27
28struct Mode { 28struct Mode {
29 char *name; 29 char *name;
30 int argmin, argmax, argmod; 30 int argmin, argmax, argmod;
31 jumperFn *jumper; 31 jumperFn *jumper;
32}; 32};
33 33
34jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox; 34jumperFn j_menu, j_checklist, j_radiolist, j_yesno, j_textbox, j_inputbox;
35jumperFn j_msgbox, j_infobox; 35jumperFn j_msgbox, j_infobox;
36 36
37static struct Mode modes[] = 37static struct Mode modes[] = {
38{ 38 {"--menu", 9, 0, 3, j_menu},
39 {"--menu", 9, 0, 3, j_menu}, 39 {"--checklist", 9, 0, 3, j_checklist},
40 {"--checklist", 9, 0, 3, j_checklist}, 40 {"--radiolist", 9, 0, 3, j_radiolist},
41 {"--radiolist", 9, 0, 3, j_radiolist}, 41 {"--yesno", 5, 5, 1, j_yesno},
42 {"--yesno", 5,5,1, j_yesno}, 42 {"--textbox", 5, 5, 1, j_textbox},
43 {"--textbox", 5,5,1, j_textbox}, 43 {"--inputbox", 5, 6, 1, j_inputbox},
44 {"--inputbox", 5, 6, 1, j_inputbox}, 44 {"--msgbox", 5, 5, 1, j_msgbox},
45 {"--msgbox", 5, 5, 1, j_msgbox}, 45 {"--infobox", 5, 5, 1, j_infobox},
46 {"--infobox", 5, 5, 1, j_infobox}, 46 {NULL, 0, 0, 0, NULL}
47 {NULL, 0, 0, 0, NULL}
48}; 47};
49 48
50static struct Mode *modePtr; 49static struct Mode *modePtr;
@@ -53,96 +52,92 @@ static struct Mode *modePtr;
53#include <locale.h> 52#include <locale.h>
54#endif 53#endif
55 54
56int 55int main(int argc, const char *const *argv)
57main (int argc, const char * const * argv)
58{ 56{
59 int offset = 0, opt_clear = 0, end_common_opts = 0, retval; 57 int offset = 0, opt_clear = 0, end_common_opts = 0, retval;
60 const char *title = NULL; 58 const char *title = NULL;
61 59
62#ifdef LOCALE 60#ifdef LOCALE
63 (void) setlocale (LC_ALL, ""); 61 (void)setlocale(LC_ALL, "");
64#endif 62#endif
65 63
66#ifdef TRACE 64#ifdef TRACE
67 trace(TRACE_CALLS|TRACE_UPDATE); 65 trace(TRACE_CALLS | TRACE_UPDATE);
68#endif 66#endif
69 if (argc < 2) { 67 if (argc < 2) {
70 Usage (argv[0]); 68 Usage(argv[0]);
71 exit (-1); 69 exit(-1);
72 } 70 }
73 71
74 while (offset < argc - 1 && !end_common_opts) { /* Common options */ 72 while (offset < argc - 1 && !end_common_opts) { /* Common options */
75 if (!strcmp (argv[offset + 1], "--title")) { 73 if (!strcmp(argv[offset + 1], "--title")) {
76 if (argc - offset < 3 || title != NULL) { 74 if (argc - offset < 3 || title != NULL) {
77 Usage (argv[0]); 75 Usage(argv[0]);
78 exit (-1); 76 exit(-1);
79 } else { 77 } else {
80 title = argv[offset + 2]; 78 title = argv[offset + 2];
81 offset += 2; 79 offset += 2;
82 } 80 }
83 } else if (!strcmp (argv[offset + 1], "--backtitle")) { 81 } else if (!strcmp(argv[offset + 1], "--backtitle")) {
84 if (backtitle != NULL) { 82 if (backtitle != NULL) {
85 Usage (argv[0]); 83 Usage(argv[0]);
86 exit (-1); 84 exit(-1);
87 } else { 85 } else {
88 backtitle = argv[offset + 2]; 86 backtitle = argv[offset + 2];
89 offset += 2; 87 offset += 2;
90 } 88 }
91 } else if (!strcmp (argv[offset + 1], "--clear")) { 89 } else if (!strcmp(argv[offset + 1], "--clear")) {
92 if (opt_clear) { /* Hey, "--clear" can't appear twice! */ 90 if (opt_clear) { /* Hey, "--clear" can't appear twice! */
93 Usage (argv[0]); 91 Usage(argv[0]);
94 exit (-1); 92 exit(-1);
95 } else if (argc == 2) { /* we only want to clear the screen */ 93 } else if (argc == 2) { /* we only want to clear the screen */
96 init_dialog (); 94 init_dialog();
97 refresh (); /* init_dialog() will clear the screen for us */ 95 refresh(); /* init_dialog() will clear the screen for us */
98 end_dialog (); 96 end_dialog();
99 return 0; 97 return 0;
100 } else { 98 } else {
101 opt_clear = 1; 99 opt_clear = 1;
102 offset++; 100 offset++;
103 } 101 }
104 } else /* no more common options */ 102 } else /* no more common options */
105 end_common_opts = 1; 103 end_common_opts = 1;
106 } 104 }
107 105
108 if (argc - 1 == offset) { /* no more options */ 106 if (argc - 1 == offset) { /* no more options */
109 Usage (argv[0]); 107 Usage(argv[0]);
110 exit (-1); 108 exit(-1);
111 } 109 }
112 /* use a table to look for the requested mode, to avoid code duplication */ 110 /* use a table to look for the requested mode, to avoid code duplication */
113 111
114 for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */ 112 for (modePtr = modes; modePtr->name; modePtr++) /* look for the mode */
115 if (!strcmp (argv[offset + 1], modePtr->name)) 113 if (!strcmp(argv[offset + 1], modePtr->name))
116 break; 114 break;
117 115
118 if (!modePtr->name) 116 if (!modePtr->name)
119 Usage (argv[0]); 117 Usage(argv[0]);
120 if (argc - offset < modePtr->argmin) 118 if (argc - offset < modePtr->argmin)
121 Usage (argv[0]); 119 Usage(argv[0]);
122 if (modePtr->argmax && argc - offset > modePtr->argmax) 120 if (modePtr->argmax && argc - offset > modePtr->argmax)
123 Usage (argv[0]); 121 Usage(argv[0]);
124 122
125 123 init_dialog();
126 124 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset);
127 init_dialog (); 125
128 retval = (*(modePtr->jumper)) (title, argc - offset, argv + offset); 126 if (opt_clear) { /* clear screen before exit */
129 127 attr_clear(stdscr, LINES, COLS, screen_attr);
130 if (opt_clear) { /* clear screen before exit */ 128 refresh();
131 attr_clear (stdscr, LINES, COLS, screen_attr); 129 }
132 refresh (); 130 end_dialog();
133 } 131
134 end_dialog(); 132 exit(retval);
135
136 exit (retval);
137} 133}
138 134
139/* 135/*
140 * Print program usage 136 * Print program usage
141 */ 137 */
142static void 138static void Usage(const char *name)
143Usage (const char *name)
144{ 139{
145 fprintf (stderr, "\ 140 fprintf(stderr, "\
146\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\ 141\ndialog, by Savio Lam (lam836@cs.cuhk.hk).\
147\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\ 142\n patched by Stuart Herbert (S.Herbert@shef.ac.uk)\
148\n modified/gutted for use as a Linux kernel config tool by \ 143\n modified/gutted for use as a Linux kernel config tool by \
@@ -162,65 +157,56 @@ Usage (const char *name)
162\n --inputbox <text> <height> <width> [<init>]\ 157\n --inputbox <text> <height> <width> [<init>]\
163\n --yesno <text> <height> <width>\ 158\n --yesno <text> <height> <width>\
164\n", name, name); 159\n", name, name);
165 exit (-1); 160 exit(-1);
166} 161}
167 162
168/* 163/*
169 * These are the program jumpers 164 * These are the program jumpers
170 */ 165 */
171 166
172int 167int j_menu(const char *t, int ac, const char *const *av)
173j_menu (const char *t, int ac, const char * const * av)
174{ 168{
175 return dialog_menu (t, av[2], atoi (av[3]), atoi (av[4]), 169 return dialog_menu(t, av[2], atoi(av[3]), atoi(av[4]),
176 atoi (av[5]), av[6], (ac - 6) / 2, av + 7); 170 atoi(av[5]), av[6], (ac - 6) / 2, av + 7);
177} 171}
178 172
179int 173int j_checklist(const char *t, int ac, const char *const *av)
180j_checklist (const char *t, int ac, const char * const * av)
181{ 174{
182 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 175 return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
183 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK); 176 atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_CHECK);
184} 177}
185 178
186int 179int j_radiolist(const char *t, int ac, const char *const *av)
187j_radiolist (const char *t, int ac, const char * const * av)
188{ 180{
189 return dialog_checklist (t, av[2], atoi (av[3]), atoi (av[4]), 181 return dialog_checklist(t, av[2], atoi(av[3]), atoi(av[4]),
190 atoi (av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO); 182 atoi(av[5]), (ac - 6) / 3, av + 6, FLAG_RADIO);
191} 183}
192 184
193int 185int j_textbox(const char *t, int ac, const char *const *av)
194j_textbox (const char *t, int ac, const char * const * av)
195{ 186{
196 return dialog_textbox (t, av[2], atoi (av[3]), atoi (av[4])); 187 return dialog_textbox(t, av[2], atoi(av[3]), atoi(av[4]));
197} 188}
198 189
199int 190int j_yesno(const char *t, int ac, const char *const *av)
200j_yesno (const char *t, int ac, const char * const * av)
201{ 191{
202 return dialog_yesno (t, av[2], atoi (av[3]), atoi (av[4])); 192 return dialog_yesno(t, av[2], atoi(av[3]), atoi(av[4]));
203} 193}
204 194
205int 195int j_inputbox(const char *t, int ac, const char *const *av)
206j_inputbox (const char *t, int ac, const char * const * av)
207{ 196{
208 int ret = dialog_inputbox (t, av[2], atoi (av[3]), atoi (av[4]), 197 int ret = dialog_inputbox(t, av[2], atoi(av[3]), atoi(av[4]),
209 ac == 6 ? av[5] : (char *) NULL); 198 ac == 6 ? av[5] : (char *)NULL);
210 if (ret == 0) 199 if (ret == 0)
211 fprintf(stderr, dialog_input_result); 200 fprintf(stderr, dialog_input_result);
212 return ret; 201 return ret;
213} 202}
214 203
215int 204int j_msgbox(const char *t, int ac, const char *const *av)
216j_msgbox (const char *t, int ac, const char * const * av)
217{ 205{
218 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 1); 206 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 1);
219} 207}
220 208
221int 209int j_infobox(const char *t, int ac, const char *const *av)
222j_infobox (const char *t, int ac, const char * const * av)
223{ 210{
224 return dialog_msgbox (t, av[2], atoi (av[3]), atoi (av[4]), 0); 211 return dialog_msgbox(t, av[2], atoi(av[3]), atoi(av[4]), 0);
225} 212}
226
diff --git a/scripts/lxdialog/menubox.c b/scripts/lxdialog/menubox.c
index 91d82ba17f8d..083f13de558c 100644
--- a/scripts/lxdialog/menubox.c
+++ b/scripts/lxdialog/menubox.c
@@ -64,382 +64,420 @@ static int menu_width, item_x;
64 * Print menu item 64 * Print menu item
65 */ 65 */
66static void 66static void
67print_item (WINDOW * win, const char *item, int choice, int selected, int hotkey) 67print_item(WINDOW * win, const char *item, int choice, int selected, int hotkey)
68{ 68{
69 int j; 69 int j;
70 char menu_item[menu_width+1]; 70 char menu_item[menu_width + 1];
71 71
72 strncpy(menu_item, item, menu_width); 72 strncpy(menu_item, item, menu_width);
73 menu_item[menu_width] = 0; 73 menu_item[menu_width] = 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, menubox_attr);
78 wmove (win, choice, 0); 78 wmove(win, choice, 0);
79#if OLD_NCURSES 79#if OLD_NCURSES
80 { 80 {
81 int i; 81 int i;
82 for (i = 0; i < menu_width; i++) 82 for (i = 0; i < menu_width; i++)
83 waddch (win, ' '); 83 waddch(win, ' ');
84 } 84 }
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 ? item_selected_attr : item_attr);
89 mvwaddstr (win, choice, item_x, menu_item); 89 mvwaddstr(win, choice, 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 ? tag_key_selected_attr : tag_key_attr);
92 mvwaddch(win, choice, item_x+j, menu_item[j]); 92 mvwaddch(win, choice, item_x + j, menu_item[j]);
93 } 93 }
94 if (selected) { 94 if (selected) {
95 wmove (win, choice, item_x+1); 95 wmove(win, choice, item_x + 1);
96 wrefresh (win); 96 wrefresh(win);
97 } 97 }
98} 98}
99 99
100/* 100/*
101 * Print the scroll indicators. 101 * Print the scroll indicators.
102 */ 102 */
103static void 103static void
104print_arrows (WINDOW * win, int item_no, int scroll, 104print_arrows(WINDOW * win, int item_no, int scroll, int y, int x, int height)
105 int y, int x, int height)
106{ 105{
107 int cur_y, cur_x; 106 int cur_y, cur_x;
108 107
109 getyx(win, cur_y, cur_x); 108 getyx(win, cur_y, cur_x);
110 109
111 wmove(win, y, x); 110 wmove(win, y, x);
112 111
113 if (scroll > 0) { 112 if (scroll > 0) {
114 wattrset (win, uarrow_attr); 113 wattrset(win, uarrow_attr);
115 waddch (win, ACS_UARROW); 114 waddch(win, ACS_UARROW);
116 waddstr (win, "(-)"); 115 waddstr(win, "(-)");
117 } 116 } else {
118 else { 117 wattrset(win, menubox_attr);
119 wattrset (win, menubox_attr); 118 waddch(win, ACS_HLINE);
120 waddch (win, ACS_HLINE); 119 waddch(win, ACS_HLINE);
121 waddch (win, ACS_HLINE); 120 waddch(win, ACS_HLINE);
122 waddch (win, ACS_HLINE); 121 waddch(win, ACS_HLINE);
123 waddch (win, ACS_HLINE); 122 }
124 } 123
125 124 y = y + height + 1;
126 y = y + height + 1; 125 wmove(win, y, x);
127 wmove(win, y, x); 126
128 127 if ((height < item_no) && (scroll + height < item_no)) {
129 if ((height < item_no) && (scroll + height < item_no)) { 128 wattrset(win, darrow_attr);
130 wattrset (win, darrow_attr); 129 waddch(win, ACS_DARROW);
131 waddch (win, ACS_DARROW); 130 waddstr(win, "(+)");
132 waddstr (win, "(+)"); 131 } else {
133 } 132 wattrset(win, menubox_border_attr);
134 else { 133 waddch(win, ACS_HLINE);
135 wattrset (win, menubox_border_attr); 134 waddch(win, ACS_HLINE);
136 waddch (win, ACS_HLINE); 135 waddch(win, ACS_HLINE);
137 waddch (win, ACS_HLINE); 136 waddch(win, ACS_HLINE);
138 waddch (win, ACS_HLINE); 137 }
139 waddch (win, ACS_HLINE); 138
140 } 139 wmove(win, cur_y, cur_x);
141
142 wmove(win, cur_y, cur_x);
143} 140}
144 141
145/* 142/*
146 * Display the termination buttons. 143 * Display the termination buttons.
147 */ 144 */
148static void 145static void print_buttons(WINDOW * win, int height, int width, int selected)
149print_buttons (WINDOW *win, int height, int width, int selected)
150{ 146{
151 int x = width / 2 - 16; 147 int x = width / 2 - 16;
152 int y = height - 2; 148 int y = height - 2;
153 149
154 print_button (win, "Select", y, x, selected == 0); 150 print_button(win, "Select", y, x, selected == 0);
155 print_button (win, " Exit ", y, x + 12, selected == 1); 151 print_button(win, " Exit ", y, x + 12, selected == 1);
156 print_button (win, " Help ", y, x + 24, selected == 2); 152 print_button(win, " Help ", y, x + 24, selected == 2);
157 153
158 wmove(win, y, x+1+12*selected); 154 wmove(win, y, x + 1 + 12 * selected);
159 wrefresh (win); 155 wrefresh(win);
160} 156}
161 157
162/* 158/*
163 * Display a menu for choosing among a number of options 159 * Display a menu for choosing among a number of options
164 */ 160 */
165int 161int
166dialog_menu (const char *title, const char *prompt, int height, int width, 162dialog_menu(const char *title, const char *prompt, int height, int width,
167 int menu_height, const char *current, int item_no, 163 int menu_height, const char *current, int item_no,
168 const char * const * items) 164 const char *const *items)
169
170{ 165{
171 int i, j, x, y, box_x, box_y; 166 int i, j, x, y, box_x, box_y;
172 int key = 0, button = 0, scroll = 0, choice = 0, first_item = 0, max_choice; 167 int key = 0, button = 0, scroll = 0, choice = 0, first_item =
173 WINDOW *dialog, *menu; 168 0, max_choice;
174 FILE *f; 169 WINDOW *dialog, *menu;
175 170 FILE *f;
176 max_choice = MIN (menu_height, item_no); 171
177 172 max_choice = MIN(menu_height, item_no);
178 /* center dialog box on screen */ 173
179 x = (COLS - width) / 2; 174 /* center dialog box on screen */
180 y = (LINES - height) / 2; 175 x = (COLS - width) / 2;
181 176 y = (LINES - height) / 2;
182 draw_shadow (stdscr, y, x, height, width); 177
183 178 draw_shadow(stdscr, y, x, height, width);
184 dialog = newwin (height, width, y, x); 179
185 keypad (dialog, TRUE); 180 dialog = newwin(height, width, y, x);
186 181 keypad(dialog, TRUE);
187 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); 182
188 wattrset (dialog, border_attr); 183 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
189 mvwaddch (dialog, height - 3, 0, ACS_LTEE); 184 wattrset(dialog, border_attr);
190 for (i = 0; i < width - 2; i++) 185 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
191 waddch (dialog, ACS_HLINE); 186 for (i = 0; i < width - 2; i++)
192 wattrset (dialog, dialog_attr); 187 waddch(dialog, ACS_HLINE);
193 wbkgdset (dialog, dialog_attr & A_COLOR); 188 wattrset(dialog, dialog_attr);
194 waddch (dialog, ACS_RTEE); 189 wbkgdset(dialog, dialog_attr & A_COLOR);
195 190 waddch(dialog, ACS_RTEE);
196 if (title != NULL && strlen(title) >= width-2 ) { 191
197 /* truncate long title -- mec */ 192 if (title != NULL && strlen(title) >= width - 2) {
198 char * title2 = malloc(width-2+1); 193 /* truncate long title -- mec */
199 memcpy( title2, title, width-2 ); 194 char *title2 = malloc(width - 2 + 1);
200 title2[width-2] = '\0'; 195 memcpy(title2, title, width - 2);
201 title = title2; 196 title2[width - 2] = '\0';
202 } 197 title = title2;
203
204 if (title != NULL) {
205 wattrset (dialog, title_attr);
206 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
207 waddstr (dialog, (char *)title);
208 waddch (dialog, ' ');
209 }
210
211 wattrset (dialog, dialog_attr);
212 print_autowrap (dialog, prompt, width - 2, 1, 3);
213
214 menu_width = width - 6;
215 box_y = height - menu_height - 5;
216 box_x = (width - menu_width) / 2 - 1;
217
218 /* create new window for the menu */
219 menu = subwin (dialog, menu_height, menu_width,
220 y + box_y + 1, x + box_x + 1);
221 keypad (menu, TRUE);
222
223 /* draw a box around the menu items */
224 draw_box (dialog, box_y, box_x, menu_height + 2, menu_width + 2,
225 menubox_border_attr, menubox_attr);
226
227 /*
228 * Find length of longest item in order to center menu.
229 * Set 'choice' to default item.
230 */
231 item_x = 0;
232 for (i = 0; i < item_no; i++) {
233 item_x = MAX (item_x, MIN(menu_width, strlen (items[i * 2 + 1]) + 2));
234 if (strcmp(current, items[i*2]) == 0) choice = i;
235 }
236
237 item_x = (menu_width - item_x) / 2;
238
239 /* get the scroll info from the temp file */
240 if ( (f=fopen("lxdialog.scrltmp","r")) != NULL ) {
241 if ( (fscanf(f,"%d\n",&scroll) == 1) && (scroll <= choice) &&
242 (scroll+max_choice > choice) && (scroll >= 0) &&
243 (scroll+max_choice <= item_no) ) {
244 first_item = scroll;
245 choice = choice - scroll;
246 fclose(f);
247 } else {
248 scroll=0;
249 remove("lxdialog.scrltmp");
250 fclose(f);
251 f=NULL;
252 } 198 }
253 } 199
254 if ( (choice >= max_choice) || (f==NULL && choice >= max_choice/2) ) { 200 if (title != NULL) {
255 if (choice >= item_no-max_choice/2) 201 wattrset(dialog, title_attr);
256 scroll = first_item = item_no-max_choice; 202 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
257 else 203 waddstr(dialog, (char *)title);
258 scroll = first_item = choice - max_choice/2; 204 waddch(dialog, ' ');
259 choice = choice - scroll;
260 }
261
262 /* Print the menu */
263 for (i=0; i < max_choice; i++) {
264 print_item (menu, items[(first_item + i) * 2 + 1], i, i == choice,
265 (items[(first_item + i)*2][0] != ':'));
266 }
267
268 wnoutrefresh (menu);
269
270 print_arrows(dialog, item_no, scroll,
271 box_y, box_x+item_x+1, menu_height);
272
273 print_buttons (dialog, height, width, 0);
274 wmove (menu, choice, item_x+1);
275 wrefresh (menu);
276
277 while (key != ESC) {
278 key = wgetch(menu);
279
280 if (key < 256 && isalpha(key)) key = tolower(key);
281
282 if (strchr("ynmh", key))
283 i = max_choice;
284 else {
285 for (i = choice+1; i < max_choice; i++) {
286 j = first_alpha(items[(scroll+i)*2+1], "YyNnMmHh");
287 if (key == tolower(items[(scroll+i)*2+1][j]))
288 break;
289 } 205 }
290 if (i == max_choice) 206
291 for (i = 0; i < max_choice; i++) { 207 wattrset(dialog, dialog_attr);
292 j = first_alpha(items[(scroll+i)*2+1], "YyNnMmHh"); 208 print_autowrap(dialog, prompt, width - 2, 1, 3);
293 if (key == tolower(items[(scroll+i)*2+1][j])) 209
294 break; 210 menu_width = width - 6;
211 box_y = height - menu_height - 5;
212 box_x = (width - menu_width) / 2 - 1;
213
214 /* create new window for the menu */
215 menu = subwin(dialog, menu_height, menu_width,
216 y + box_y + 1, x + box_x + 1);
217 keypad(menu, TRUE);
218
219 /* draw a box around the menu items */
220 draw_box(dialog, box_y, box_x, menu_height + 2, menu_width + 2,
221 menubox_border_attr, menubox_attr);
222
223 /*
224 * Find length of longest item in order to center menu.
225 * Set 'choice' to default item.
226 */
227 item_x = 0;
228 for (i = 0; i < item_no; i++) {
229 item_x =
230 MAX(item_x, MIN(menu_width, strlen(items[i * 2 + 1]) + 2));
231 if (strcmp(current, items[i * 2]) == 0)
232 choice = i;
233 }
234
235 item_x = (menu_width - item_x) / 2;
236
237 /* get the scroll info from the temp file */
238 if ((f = fopen("lxdialog.scrltmp", "r")) != NULL) {
239 if ((fscanf(f, "%d\n", &scroll) == 1) && (scroll <= choice) &&
240 (scroll + max_choice > choice) && (scroll >= 0) &&
241 (scroll + max_choice <= item_no)) {
242 first_item = scroll;
243 choice = choice - scroll;
244 fclose(f);
245 } else {
246 scroll = 0;
247 remove("lxdialog.scrltmp");
248 fclose(f);
249 f = NULL;
295 } 250 }
296 } 251 }
252 if ((choice >= max_choice) || (f == NULL && choice >= max_choice / 2)) {
253 if (choice >= item_no - max_choice / 2)
254 scroll = first_item = item_no - max_choice;
255 else
256 scroll = first_item = choice - max_choice / 2;
257 choice = choice - scroll;
258 }
297 259
298 if (i < max_choice || 260 /* Print the menu */
299 key == KEY_UP || key == KEY_DOWN || 261 for (i = 0; i < max_choice; i++) {
300 key == '-' || key == '+' || 262 print_item(menu, items[(first_item + i) * 2 + 1], i,
301 key == KEY_PPAGE || key == KEY_NPAGE) { 263 i == choice,
302 264 (items[(first_item + i) * 2][0] != ':'));
303 print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, 265 }
304 (items[(scroll+choice)*2][0] != ':')); 266
305 267 wnoutrefresh(menu);
306 if (key == KEY_UP || key == '-') { 268
307 if (choice < 2 && scroll) { 269 print_arrows(dialog, item_no, scroll,
308 /* Scroll menu down */ 270 box_y, box_x + item_x + 1, menu_height);
309 scrollok (menu, TRUE); 271
310 wscrl (menu, -1); 272 print_buttons(dialog, height, width, 0);
311 scrollok (menu, FALSE); 273 wmove(menu, choice, item_x + 1);
312 274 wrefresh(menu);
313 scroll--; 275
314 276 while (key != ESC) {
315 print_item (menu, items[scroll * 2 + 1], 0, FALSE, 277 key = wgetch(menu);
316 (items[scroll*2][0] != ':')); 278
317 } else 279 if (key < 256 && isalpha(key))
318 choice = MAX(choice - 1, 0); 280 key = tolower(key);
319 281
320 } else if (key == KEY_DOWN || key == '+') { 282 if (strchr("ynmh", key))
321 283 i = max_choice;
322 print_item (menu, items[(scroll+choice)*2+1], choice, FALSE, 284 else {
323 (items[(scroll+choice)*2][0] != ':')); 285 for (i = choice + 1; i < max_choice; i++) {
324 286 j = first_alpha(items[(scroll + i) * 2 + 1],
325 if ((choice > max_choice-3) && 287 "YyNnMmHh");
326 (scroll + max_choice < item_no) 288 if (key ==
327 ) { 289 tolower(items[(scroll + i) * 2 + 1][j]))
328 /* Scroll menu up */ 290 break;
329 scrollok (menu, TRUE); 291 }
330 wscrl (menu, 1); 292 if (i == max_choice)
331 scrollok (menu, FALSE); 293 for (i = 0; i < max_choice; i++) {
332 294 j = first_alpha(items
333 scroll++; 295 [(scroll + i) * 2 + 1],
334 296 "YyNnMmHh");
335 print_item (menu, items[(scroll+max_choice-1)*2+1], 297 if (key ==
336 max_choice-1, FALSE, 298 tolower(items[(scroll + i) * 2 + 1]
337 (items[(scroll+max_choice-1)*2][0] != ':')); 299 [j]))
338 } else 300 break;
339 choice = MIN(choice+1, max_choice-1); 301 }
340 302 }
341 } else if (key == KEY_PPAGE) { 303
342 scrollok (menu, TRUE); 304 if (i < max_choice ||
343 for (i=0; (i < max_choice); i++) { 305 key == KEY_UP || key == KEY_DOWN ||
344 if (scroll > 0) { 306 key == '-' || key == '+' ||
345 wscrl (menu, -1); 307 key == KEY_PPAGE || key == KEY_NPAGE) {
346 scroll--; 308
347 print_item (menu, items[scroll * 2 + 1], 0, FALSE, 309 print_item(menu, items[(scroll + choice) * 2 + 1],
348 (items[scroll*2][0] != ':')); 310 choice, FALSE,
349 } else { 311 (items[(scroll + choice) * 2][0] != ':'));
350 if (choice > 0) 312
351 choice--; 313 if (key == KEY_UP || key == '-') {
352 } 314 if (choice < 2 && scroll) {
353 } 315 /* Scroll menu down */
354 scrollok (menu, FALSE); 316 scrollok(menu, TRUE);
355 317 wscrl(menu, -1);
356 } else if (key == KEY_NPAGE) { 318 scrollok(menu, FALSE);
357 for (i=0; (i < max_choice); i++) { 319
358 if (scroll+max_choice < item_no) { 320 scroll--;
359 scrollok (menu, TRUE); 321
360 wscrl (menu, 1); 322 print_item(menu, items[scroll * 2 + 1],
361 scrollok (menu, FALSE); 323 0, FALSE,
362 scroll++; 324 (items[scroll * 2][0] !=
363 print_item (menu, items[(scroll+max_choice-1)*2+1], 325 ':'));
364 max_choice-1, FALSE, 326 } else
365 (items[(scroll+max_choice-1)*2][0] != ':')); 327 choice = MAX(choice - 1, 0);
366 } else { 328
367 if (choice+1 < max_choice) 329 } else if (key == KEY_DOWN || key == '+') {
368 choice++; 330
369 } 331 print_item(menu,
370 } 332 items[(scroll + choice) * 2 + 1],
371 333 choice, FALSE,
372 } else 334 (items[(scroll + choice) * 2][0] !=
373 choice = i; 335 ':'));
374 336
375 print_item (menu, items[(scroll+choice)*2+1], choice, TRUE, 337 if ((choice > max_choice - 3) &&
376 (items[(scroll+choice)*2][0] != ':')); 338 (scroll + max_choice < item_no)
377 339 ) {
378 print_arrows(dialog, item_no, scroll, 340 /* Scroll menu up */
379 box_y, box_x+item_x+1, menu_height); 341 scrollok(menu, TRUE);
380 342 wscrl(menu, 1);
381 wnoutrefresh (dialog); 343 scrollok(menu, FALSE);
382 wrefresh (menu); 344
383 345 scroll++;
384 continue; /* wait for another key press */ 346
385 } 347 print_item(menu,
386 348 items[(scroll + max_choice -
387 switch (key) { 349 1) * 2 + 1],
388 case KEY_LEFT: 350 max_choice - 1, FALSE,
389 case TAB: 351 (items
390 case KEY_RIGHT: 352 [(scroll + max_choice -
391 button = ((key == KEY_LEFT ? --button : ++button) < 0) 353 1) * 2][0] != ':'));
392 ? 2 : (button > 2 ? 0 : button); 354 } else
393 355 choice =
394 print_buttons(dialog, height, width, button); 356 MIN(choice + 1, max_choice - 1);
395 wrefresh (menu); 357
396 break; 358 } else if (key == KEY_PPAGE) {
397 case ' ': 359 scrollok(menu, TRUE);
398 case 's': 360 for (i = 0; (i < max_choice); i++) {
399 case 'y': 361 if (scroll > 0) {
400 case 'n': 362 wscrl(menu, -1);
401 case 'm': 363 scroll--;
402 case '/': 364 print_item(menu,
403 /* save scroll info */ 365 items[scroll * 2 +
404 if ( (f=fopen("lxdialog.scrltmp","w")) != NULL ) { 366 1], 0, FALSE,
405 fprintf(f,"%d\n",scroll); 367 (items[scroll * 2][0]
406 fclose(f); 368 != ':'));
407 } 369 } else {
408 delwin (dialog); 370 if (choice > 0)
409 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 371 choice--;
410 switch (key) { 372 }
411 case 's': return 3; 373 }
412 case 'y': return 3; 374 scrollok(menu, FALSE);
413 case 'n': return 4; 375
414 case 'm': return 5; 376 } else if (key == KEY_NPAGE) {
415 case ' ': return 6; 377 for (i = 0; (i < max_choice); i++) {
416 case '/': return 7; 378 if (scroll + max_choice < item_no) {
417 } 379 scrollok(menu, TRUE);
418 return 0; 380 wscrl(menu, 1);
419 case 'h': 381 scrollok(menu, FALSE);
420 case '?': 382 scroll++;
421 button = 2; 383 print_item(menu,
422 case '\n': 384 items[(scroll +
423 delwin (dialog); 385 max_choice -
424 if (button == 2) 386 1) * 2 + 1],
425 fprintf(stderr, "%s \"%s\"\n", 387 max_choice - 1,
426 items[(scroll + choice) * 2], 388 FALSE,
427 items[(scroll + choice) * 2 + 1] + 389 (items
428 first_alpha(items[(scroll + choice) * 2 + 1],"")); 390 [(scroll +
429 else 391 max_choice -
430 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]); 392 1) * 2][0] !=
431 393 ':'));
432 remove("lxdialog.scrltmp"); 394 } else {
433 return button; 395 if (choice + 1 < max_choice)
434 case 'e': 396 choice++;
435 case 'x': 397 }
436 key = ESC; 398 }
437 case ESC: 399
438 break; 400 } else
401 choice = i;
402
403 print_item(menu, items[(scroll + choice) * 2 + 1],
404 choice, TRUE,
405 (items[(scroll + choice) * 2][0] != ':'));
406
407 print_arrows(dialog, item_no, scroll,
408 box_y, box_x + item_x + 1, menu_height);
409
410 wnoutrefresh(dialog);
411 wrefresh(menu);
412
413 continue; /* wait for another key press */
414 }
415
416 switch (key) {
417 case KEY_LEFT:
418 case TAB:
419 case KEY_RIGHT:
420 button = ((key == KEY_LEFT ? --button : ++button) < 0)
421 ? 2 : (button > 2 ? 0 : button);
422
423 print_buttons(dialog, height, width, button);
424 wrefresh(menu);
425 break;
426 case ' ':
427 case 's':
428 case 'y':
429 case 'n':
430 case 'm':
431 case '/':
432 /* save scroll info */
433 if ((f = fopen("lxdialog.scrltmp", "w")) != NULL) {
434 fprintf(f, "%d\n", scroll);
435 fclose(f);
436 }
437 delwin(dialog);
438 fprintf(stderr, "%s\n", items[(scroll + choice) * 2]);
439 switch (key) {
440 case 's':
441 return 3;
442 case 'y':
443 return 3;
444 case 'n':
445 return 4;
446 case 'm':
447 return 5;
448 case ' ':
449 return 6;
450 case '/':
451 return 7;
452 }
453 return 0;
454 case 'h':
455 case '?':
456 button = 2;
457 case '\n':
458 delwin(dialog);
459 if (button == 2)
460 fprintf(stderr, "%s \"%s\"\n",
461 items[(scroll + choice) * 2],
462 items[(scroll + choice) * 2 + 1] +
463 first_alpha(items
464 [(scroll + choice) * 2 + 1],
465 ""));
466 else
467 fprintf(stderr, "%s\n",
468 items[(scroll + choice) * 2]);
469
470 remove("lxdialog.scrltmp");
471 return button;
472 case 'e':
473 case 'x':
474 key = ESC;
475 case ESC:
476 break;
477 }
439 } 478 }
440 }
441 479
442 delwin (dialog); 480 delwin(dialog);
443 remove("lxdialog.scrltmp"); 481 remove("lxdialog.scrltmp");
444 return -1; /* ESC pressed */ 482 return -1; /* ESC pressed */
445} 483}
diff --git a/scripts/lxdialog/msgbox.c b/scripts/lxdialog/msgbox.c
index 93692e1fbcc2..76f358ca1fda 100644
--- a/scripts/lxdialog/msgbox.c
+++ b/scripts/lxdialog/msgbox.c
@@ -26,60 +26,59 @@
26 * if the parameter 'pause' is non-zero. 26 * if the parameter 'pause' is non-zero.
27 */ 27 */
28int 28int
29dialog_msgbox (const char *title, const char *prompt, int height, int width, 29dialog_msgbox(const char *title, const char *prompt, int height, int width,
30 int pause) 30 int pause)
31{ 31{
32 int i, x, y, key = 0; 32 int i, x, y, key = 0;
33 WINDOW *dialog; 33 WINDOW *dialog;
34 34
35 /* center dialog box on screen */ 35 /* center dialog box on screen */
36 x = (COLS - width) / 2; 36 x = (COLS - width) / 2;
37 y = (LINES - height) / 2; 37 y = (LINES - height) / 2;
38 38
39 draw_shadow (stdscr, y, x, height, width); 39 draw_shadow(stdscr, y, x, height, width);
40 40
41 dialog = newwin (height, width, y, x); 41 dialog = newwin(height, width, y, x);
42 keypad (dialog, TRUE); 42 keypad(dialog, TRUE);
43 43
44 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); 44 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
45 45
46 if (title != NULL && strlen(title) >= width-2 ) { 46 if (title != NULL && strlen(title) >= width - 2) {
47 /* truncate long title -- mec */ 47 /* truncate long title -- mec */
48 char * title2 = malloc(width-2+1); 48 char *title2 = malloc(width - 2 + 1);
49 memcpy( title2, title, width-2 ); 49 memcpy(title2, title, width - 2);
50 title2[width-2] = '\0'; 50 title2[width - 2] = '\0';
51 title = title2; 51 title = title2;
52 } 52 }
53 53
54 if (title != NULL) { 54 if (title != NULL) {
55 wattrset (dialog, title_attr); 55 wattrset(dialog, title_attr);
56 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' '); 56 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
57 waddstr (dialog, (char *)title); 57 waddstr(dialog, (char *)title);
58 waddch (dialog, ' '); 58 waddch(dialog, ' ');
59 } 59 }
60 wattrset (dialog, dialog_attr); 60 wattrset(dialog, dialog_attr);
61 print_autowrap (dialog, prompt, width - 2, 1, 2); 61 print_autowrap(dialog, prompt, width - 2, 1, 2);
62 62
63 if (pause) { 63 if (pause) {
64 wattrset (dialog, border_attr); 64 wattrset(dialog, border_attr);
65 mvwaddch (dialog, height - 3, 0, ACS_LTEE); 65 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
66 for (i = 0; i < width - 2; i++) 66 for (i = 0; i < width - 2; i++)
67 waddch (dialog, ACS_HLINE); 67 waddch(dialog, ACS_HLINE);
68 wattrset (dialog, dialog_attr); 68 wattrset(dialog, dialog_attr);
69 waddch (dialog, ACS_RTEE); 69 waddch(dialog, ACS_RTEE);
70 70
71 print_button (dialog, " Ok ", 71 print_button(dialog, " Ok ", height - 2, width / 2 - 4, TRUE);
72 height - 2, width / 2 - 4, TRUE);
73 72
74 wrefresh (dialog); 73 wrefresh(dialog);
75 while (key != ESC && key != '\n' && key != ' ' && 74 while (key != ESC && key != '\n' && key != ' ' &&
76 key != 'O' && key != 'o' && key != 'X' && key != 'x') 75 key != 'O' && key != 'o' && key != 'X' && key != 'x')
77 key = wgetch (dialog); 76 key = wgetch(dialog);
78 } else { 77 } else {
79 key = '\n'; 78 key = '\n';
80 wrefresh (dialog); 79 wrefresh(dialog);
81 } 80 }
82 81
83 delwin (dialog); 82 delwin(dialog);
84 return key == ESC ? -1 : 0; 83 return key == ESC ? -1 : 0;
85} 84}
diff --git a/scripts/lxdialog/textbox.c b/scripts/lxdialog/textbox.c
index ed23df2d096a..d6e7f2afe31a 100644
--- a/scripts/lxdialog/textbox.c
+++ b/scripts/lxdialog/textbox.c
@@ -21,11 +21,11 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24static void back_lines (int n); 24static void back_lines(int n);
25static void print_page (WINDOW * win, int height, int width); 25static void print_page(WINDOW * win, int height, int width);
26static void print_line (WINDOW * win, int row, int width); 26static void print_line(WINDOW * win, int row, int width);
27static char *get_line (void); 27static char *get_line(void);
28static void print_position (WINDOW * win, int height, int width); 28static void print_position(WINDOW * win, int height, int width);
29 29
30static int hscroll, fd, file_size, bytes_read; 30static int hscroll, fd, file_size, bytes_read;
31static int begin_reached = 1, end_reached, page_length; 31static int begin_reached = 1, end_reached, page_length;
@@ -34,450 +34,466 @@ static char *buf, *page;
34/* 34/*
35 * Display text from a file in a dialog box. 35 * Display text from a file in a dialog box.
36 */ 36 */
37int 37int dialog_textbox(const char *title, const char *file, int height, int width)
38dialog_textbox (const char *title, const char *file, int height, int width)
39{ 38{
40 int i, x, y, cur_x, cur_y, fpos, key = 0; 39 int i, x, y, cur_x, cur_y, fpos, key = 0;
41 int passed_end; 40 int passed_end;
42 char search_term[MAX_LEN + 1]; 41 char search_term[MAX_LEN + 1];
43 WINDOW *dialog, *text; 42 WINDOW *dialog, *text;
44 43
45 search_term[0] = '\0'; /* no search term entered yet */ 44 search_term[0] = '\0'; /* no search term entered yet */
46 45
47 /* Open input file for reading */ 46 /* Open input file for reading */
48 if ((fd = open (file, O_RDONLY)) == -1) { 47 if ((fd = open(file, O_RDONLY)) == -1) {
49 endwin (); 48 endwin();
50 fprintf (stderr, 49 fprintf(stderr,
51 "\nCan't open input file in dialog_textbox().\n"); 50 "\nCan't open input file in dialog_textbox().\n");
52 exit (-1); 51 exit(-1);
53 } 52 }
54 /* Get file size. Actually, 'file_size' is the real file size - 1, 53 /* Get file size. Actually, 'file_size' is the real file size - 1,
55 since it's only the last byte offset from the beginning */ 54 since it's only the last byte offset from the beginning */
56 if ((file_size = lseek (fd, 0, SEEK_END)) == -1) { 55 if ((file_size = lseek(fd, 0, SEEK_END)) == -1) {
57 endwin (); 56 endwin();
58 fprintf (stderr, "\nError getting file size in dialog_textbox().\n"); 57 fprintf(stderr,
59 exit (-1); 58 "\nError getting file size in dialog_textbox().\n");
60 } 59 exit(-1);
61 /* Restore file pointer to beginning of file after getting file size */ 60 }
62 if (lseek (fd, 0, SEEK_SET) == -1) { 61 /* Restore file pointer to beginning of file after getting file size */
63 endwin (); 62 if (lseek(fd, 0, SEEK_SET) == -1) {
64 fprintf (stderr, "\nError moving file pointer in dialog_textbox().\n"); 63 endwin();
65 exit (-1); 64 fprintf(stderr,
66 } 65 "\nError moving file pointer in dialog_textbox().\n");
67 /* Allocate space for read buffer */ 66 exit(-1);
68 if ((buf = malloc (BUF_SIZE + 1)) == NULL) { 67 }
69 endwin (); 68 /* Allocate space for read buffer */
70 fprintf (stderr, "\nCan't allocate memory in dialog_textbox().\n"); 69 if ((buf = malloc(BUF_SIZE + 1)) == NULL) {
71 exit (-1); 70 endwin();
72 } 71 fprintf(stderr,
73 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { 72 "\nCan't allocate memory in dialog_textbox().\n");
74 endwin (); 73 exit(-1);
75 fprintf (stderr, "\nError reading file in dialog_textbox().\n"); 74 }
76 exit (-1); 75 if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) {
77 } 76 endwin();
78 buf[bytes_read] = '\0'; /* mark end of valid data */ 77 fprintf(stderr, "\nError reading file in dialog_textbox().\n");
79 page = buf; /* page is pointer to start of page to be displayed */ 78 exit(-1);
80 79 }
81 /* center dialog box on screen */ 80 buf[bytes_read] = '\0'; /* mark end of valid data */
82 x = (COLS - width) / 2; 81 page = buf; /* page is pointer to start of page to be displayed */
83 y = (LINES - height) / 2; 82
84 83 /* center dialog box on screen */
85 84 x = (COLS - width) / 2;
86 draw_shadow (stdscr, y, x, height, width); 85 y = (LINES - height) / 2;
87 86
88 dialog = newwin (height, width, y, x); 87 draw_shadow(stdscr, y, x, height, width);
89 keypad (dialog, TRUE); 88
90 89 dialog = newwin(height, width, y, x);
91 /* Create window for text region, used for scrolling text */ 90 keypad(dialog, TRUE);
92 text = subwin (dialog, height - 4, width - 2, y + 1, x + 1); 91
93 wattrset (text, dialog_attr); 92 /* Create window for text region, used for scrolling text */
94 wbkgdset (text, dialog_attr & A_COLOR); 93 text = subwin(dialog, height - 4, width - 2, y + 1, x + 1);
95 94 wattrset(text, dialog_attr);
96 keypad (text, TRUE); 95 wbkgdset(text, dialog_attr & A_COLOR);
97 96
98 /* register the new window, along with its borders */ 97 keypad(text, TRUE);
99 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); 98
100 99 /* register the new window, along with its borders */
101 wattrset (dialog, border_attr); 100 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
102 mvwaddch (dialog, height-3, 0, ACS_LTEE); 101
103 for (i = 0; i < width - 2; i++) 102 wattrset(dialog, border_attr);
104 waddch (dialog, ACS_HLINE); 103 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
105 wattrset (dialog, dialog_attr); 104 for (i = 0; i < width - 2; i++)
106 wbkgdset (dialog, dialog_attr & A_COLOR); 105 waddch(dialog, ACS_HLINE);
107 waddch (dialog, ACS_RTEE); 106 wattrset(dialog, dialog_attr);
108 107 wbkgdset(dialog, dialog_attr & A_COLOR);
109 if (title != NULL && strlen(title) >= width-2 ) { 108 waddch(dialog, ACS_RTEE);
110 /* truncate long title -- mec */ 109
111 char * title2 = malloc(width-2+1); 110 if (title != NULL && strlen(title) >= width - 2) {
112 memcpy( title2, title, width-2 ); 111 /* truncate long title -- mec */
113 title2[width-2] = '\0'; 112 char *title2 = malloc(width - 2 + 1);
114 title = title2; 113 memcpy(title2, title, width - 2);
115 } 114 title2[width - 2] = '\0';
116 115 title = title2;
117 if (title != NULL) { 116 }
118 wattrset (dialog, title_attr);
119 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
120 waddstr (dialog, (char *)title);
121 waddch (dialog, ' ');
122 }
123 print_button (dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
124 wnoutrefresh (dialog);
125 getyx (dialog, cur_y, cur_x); /* Save cursor position */
126
127 /* Print first page of text */
128 attr_clear (text, height - 4, width - 2, dialog_attr);
129 print_page (text, height - 4, width - 2);
130 print_position (dialog, height, width);
131 wmove (dialog, cur_y, cur_x); /* Restore cursor position */
132 wrefresh (dialog);
133
134 while ((key != ESC) && (key != '\n')) {
135 key = wgetch (dialog);
136 switch (key) {
137 case 'E': /* Exit */
138 case 'e':
139 case 'X':
140 case 'x':
141 delwin (dialog);
142 free (buf);
143 close (fd);
144 return 0;
145 case 'g': /* First page */
146 case KEY_HOME:
147 if (!begin_reached) {
148 begin_reached = 1;
149 /* First page not in buffer? */
150 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
151 endwin ();
152 fprintf (stderr,
153 "\nError moving file pointer in dialog_textbox().\n");
154 exit (-1);
155 }
156 if (fpos > bytes_read) { /* Yes, we have to read it in */
157 if (lseek (fd, 0, SEEK_SET) == -1) {
158 endwin ();
159 fprintf (stderr, "\nError moving file pointer in "
160 "dialog_textbox().\n");
161 exit (-1);
162 }
163 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
164 endwin ();
165 fprintf (stderr,
166 "\nError reading file in dialog_textbox().\n");
167 exit (-1);
168 }
169 buf[bytes_read] = '\0';
170 }
171 page = buf;
172 print_page (text, height - 4, width - 2);
173 print_position (dialog, height, width);
174 wmove (dialog, cur_y, cur_x); /* Restore cursor position */
175 wrefresh (dialog);
176 }
177 break;
178 case 'G': /* Last page */
179 case KEY_END:
180
181 end_reached = 1;
182 /* Last page not in buffer? */
183 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {
184 endwin ();
185 fprintf (stderr,
186 "\nError moving file pointer in dialog_textbox().\n");
187 exit (-1);
188 }
189 if (fpos < file_size) { /* Yes, we have to read it in */
190 if (lseek (fd, -BUF_SIZE, SEEK_END) == -1) {
191 endwin ();
192 fprintf (stderr,
193 "\nError moving file pointer in dialog_textbox().\n");
194 exit (-1);
195 }
196 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
197 endwin ();
198 fprintf (stderr,
199 "\nError reading file in dialog_textbox().\n");
200 exit (-1);
201 }
202 buf[bytes_read] = '\0';
203 }
204 page = buf + bytes_read;
205 back_lines (height - 4);
206 print_page (text, height - 4, width - 2);
207 print_position (dialog, height, width);
208 wmove (dialog, cur_y, cur_x); /* Restore cursor position */
209 wrefresh (dialog);
210 break;
211 case 'K': /* Previous line */
212 case 'k':
213 case KEY_UP:
214 if (!begin_reached) {
215 back_lines (page_length + 1);
216
217 /* We don't call print_page() here but use scrolling to ensure
218 faster screen update. However, 'end_reached' and
219 'page_length' should still be updated, and 'page' should
220 point to start of next page. This is done by calling
221 get_line() in the following 'for' loop. */
222 scrollok (text, TRUE);
223 wscrl (text, -1); /* Scroll text region down one line */
224 scrollok (text, FALSE);
225 page_length = 0;
226 passed_end = 0;
227 for (i = 0; i < height - 4; i++) {
228 if (!i) {
229 /* print first line of page */
230 print_line (text, 0, width - 2);
231 wnoutrefresh (text);
232 } else
233 /* Called to update 'end_reached' and 'page' */
234 get_line ();
235 if (!passed_end)
236 page_length++;
237 if (end_reached && !passed_end)
238 passed_end = 1;
239 }
240 117
241 print_position (dialog, height, width); 118 if (title != NULL) {
242 wmove (dialog, cur_y, cur_x); /* Restore cursor position */ 119 wattrset(dialog, title_attr);
243 wrefresh (dialog); 120 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
244 } 121 waddstr(dialog, (char *)title);
245 break; 122 waddch(dialog, ' ');
246 case 'B': /* Previous page */ 123 }
247 case 'b': 124 print_button(dialog, " Exit ", height - 2, width / 2 - 4, TRUE);
248 case KEY_PPAGE: 125 wnoutrefresh(dialog);
249 if (begin_reached) 126 getyx(dialog, cur_y, cur_x); /* Save cursor position */
250 break; 127
251 back_lines (page_length + height - 4); 128 /* Print first page of text */
252 print_page (text, height - 4, width - 2); 129 attr_clear(text, height - 4, width - 2, dialog_attr);
253 print_position (dialog, height, width); 130 print_page(text, height - 4, width - 2);
254 wmove (dialog, cur_y, cur_x); 131 print_position(dialog, height, width);
255 wrefresh (dialog); 132 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
256 break; 133 wrefresh(dialog);
257 case 'J': /* Next line */ 134
258 case 'j': 135 while ((key != ESC) && (key != '\n')) {
259 case KEY_DOWN: 136 key = wgetch(dialog);
260 if (!end_reached) { 137 switch (key) {
261 begin_reached = 0; 138 case 'E': /* Exit */
262 scrollok (text, TRUE); 139 case 'e':
263 scroll (text); /* Scroll text region up one line */ 140 case 'X':
264 scrollok (text, FALSE); 141 case 'x':
265 print_line (text, height - 5, width - 2); 142 delwin(dialog);
266 wnoutrefresh (text); 143 free(buf);
267 print_position (dialog, height, width); 144 close(fd);
268 wmove (dialog, cur_y, cur_x); /* Restore cursor position */ 145 return 0;
269 wrefresh (dialog); 146 case 'g': /* First page */
270 } 147 case KEY_HOME:
271 break; 148 if (!begin_reached) {
272 case KEY_NPAGE: /* Next page */ 149 begin_reached = 1;
273 case ' ': 150 /* First page not in buffer? */
274 if (end_reached) 151 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
275 break; 152 endwin();
276 153 fprintf(stderr,
277 begin_reached = 0; 154 "\nError moving file pointer in dialog_textbox().\n");
278 print_page (text, height - 4, width - 2); 155 exit(-1);
279 print_position (dialog, height, width); 156 }
280 wmove (dialog, cur_y, cur_x); 157 if (fpos > bytes_read) { /* Yes, we have to read it in */
281 wrefresh (dialog); 158 if (lseek(fd, 0, SEEK_SET) == -1) {
282 break; 159 endwin();
283 case '0': /* Beginning of line */ 160 fprintf(stderr,
284 case 'H': /* Scroll left */ 161 "\nError moving file pointer in "
285 case 'h': 162 "dialog_textbox().\n");
286 case KEY_LEFT: 163 exit(-1);
287 if (hscroll <= 0) 164 }
288 break; 165 if ((bytes_read =
289 166 read(fd, buf, BUF_SIZE)) == -1) {
290 if (key == '0') 167 endwin();
291 hscroll = 0; 168 fprintf(stderr,
292 else 169 "\nError reading file in dialog_textbox().\n");
293 hscroll--; 170 exit(-1);
294 /* Reprint current page to scroll horizontally */ 171 }
295 back_lines (page_length); 172 buf[bytes_read] = '\0';
296 print_page (text, height - 4, width - 2); 173 }
297 wmove (dialog, cur_y, cur_x); 174 page = buf;
298 wrefresh (dialog); 175 print_page(text, height - 4, width - 2);
299 break; 176 print_position(dialog, height, width);
300 case 'L': /* Scroll right */ 177 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
301 case 'l': 178 wrefresh(dialog);
302 case KEY_RIGHT: 179 }
303 if (hscroll >= MAX_LEN) 180 break;
304 break; 181 case 'G': /* Last page */
305 hscroll++; 182 case KEY_END:
306 /* Reprint current page to scroll horizontally */ 183
307 back_lines (page_length); 184 end_reached = 1;
308 print_page (text, height - 4, width - 2); 185 /* Last page not in buffer? */
309 wmove (dialog, cur_y, cur_x); 186 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
310 wrefresh (dialog); 187 endwin();
311 break; 188 fprintf(stderr,
312 case ESC: 189 "\nError moving file pointer in dialog_textbox().\n");
313 break; 190 exit(-1);
191 }
192 if (fpos < file_size) { /* Yes, we have to read it in */
193 if (lseek(fd, -BUF_SIZE, SEEK_END) == -1) {
194 endwin();
195 fprintf(stderr,
196 "\nError moving file pointer in dialog_textbox().\n");
197 exit(-1);
198 }
199 if ((bytes_read =
200 read(fd, buf, BUF_SIZE)) == -1) {
201 endwin();
202 fprintf(stderr,
203 "\nError reading file in dialog_textbox().\n");
204 exit(-1);
205 }
206 buf[bytes_read] = '\0';
207 }
208 page = buf + bytes_read;
209 back_lines(height - 4);
210 print_page(text, height - 4, width - 2);
211 print_position(dialog, height, width);
212 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
213 wrefresh(dialog);
214 break;
215 case 'K': /* Previous line */
216 case 'k':
217 case KEY_UP:
218 if (!begin_reached) {
219 back_lines(page_length + 1);
220
221 /* We don't call print_page() here but use scrolling to ensure
222 faster screen update. However, 'end_reached' and
223 'page_length' should still be updated, and 'page' should
224 point to start of next page. This is done by calling
225 get_line() in the following 'for' loop. */
226 scrollok(text, TRUE);
227 wscrl(text, -1); /* Scroll text region down one line */
228 scrollok(text, FALSE);
229 page_length = 0;
230 passed_end = 0;
231 for (i = 0; i < height - 4; i++) {
232 if (!i) {
233 /* print first line of page */
234 print_line(text, 0, width - 2);
235 wnoutrefresh(text);
236 } else
237 /* Called to update 'end_reached' and 'page' */
238 get_line();
239 if (!passed_end)
240 page_length++;
241 if (end_reached && !passed_end)
242 passed_end = 1;
243 }
244
245 print_position(dialog, height, width);
246 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
247 wrefresh(dialog);
248 }
249 break;
250 case 'B': /* Previous page */
251 case 'b':
252 case KEY_PPAGE:
253 if (begin_reached)
254 break;
255 back_lines(page_length + height - 4);
256 print_page(text, height - 4, width - 2);
257 print_position(dialog, height, width);
258 wmove(dialog, cur_y, cur_x);
259 wrefresh(dialog);
260 break;
261 case 'J': /* Next line */
262 case 'j':
263 case KEY_DOWN:
264 if (!end_reached) {
265 begin_reached = 0;
266 scrollok(text, TRUE);
267 scroll(text); /* Scroll text region up one line */
268 scrollok(text, FALSE);
269 print_line(text, height - 5, width - 2);
270 wnoutrefresh(text);
271 print_position(dialog, height, width);
272 wmove(dialog, cur_y, cur_x); /* Restore cursor position */
273 wrefresh(dialog);
274 }
275 break;
276 case KEY_NPAGE: /* Next page */
277 case ' ':
278 if (end_reached)
279 break;
280
281 begin_reached = 0;
282 print_page(text, height - 4, width - 2);
283 print_position(dialog, height, width);
284 wmove(dialog, cur_y, cur_x);
285 wrefresh(dialog);
286 break;
287 case '0': /* Beginning of line */
288 case 'H': /* Scroll left */
289 case 'h':
290 case KEY_LEFT:
291 if (hscroll <= 0)
292 break;
293
294 if (key == '0')
295 hscroll = 0;
296 else
297 hscroll--;
298 /* Reprint current page to scroll horizontally */
299 back_lines(page_length);
300 print_page(text, height - 4, width - 2);
301 wmove(dialog, cur_y, cur_x);
302 wrefresh(dialog);
303 break;
304 case 'L': /* Scroll right */
305 case 'l':
306 case KEY_RIGHT:
307 if (hscroll >= MAX_LEN)
308 break;
309 hscroll++;
310 /* Reprint current page to scroll horizontally */
311 back_lines(page_length);
312 print_page(text, height - 4, width - 2);
313 wmove(dialog, cur_y, cur_x);
314 wrefresh(dialog);
315 break;
316 case ESC:
317 break;
318 }
314 } 319 }
315 }
316 320
317 delwin (dialog); 321 delwin(dialog);
318 free (buf); 322 free(buf);
319 close (fd); 323 close(fd);
320 return -1; /* ESC pressed */ 324 return -1; /* ESC pressed */
321} 325}
322 326
323/* 327/*
324 * Go back 'n' lines in text file. Called by dialog_textbox(). 328 * Go back 'n' lines in text file. Called by dialog_textbox().
325 * 'page' will be updated to point to the desired line in 'buf'. 329 * 'page' will be updated to point to the desired line in 'buf'.
326 */ 330 */
327static void 331static void back_lines(int n)
328back_lines (int n)
329{ 332{
330 int i, fpos; 333 int i, fpos;
331 334
332 begin_reached = 0; 335 begin_reached = 0;
333 /* We have to distinguish between end_reached and !end_reached 336 /* We have to distinguish between end_reached and !end_reached
334 since at end of file, the line is not ended by a '\n'. 337 since at end of file, the line is not ended by a '\n'.
335 The code inside 'if' basically does a '--page' to move one 338 The code inside 'if' basically does a '--page' to move one
336 character backward so as to skip '\n' of the previous line */ 339 character backward so as to skip '\n' of the previous line */
337 if (!end_reached) { 340 if (!end_reached) {
338 /* Either beginning of buffer or beginning of file reached? */ 341 /* Either beginning of buffer or beginning of file reached? */
339 if (page == buf) { 342 if (page == buf) {
340 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { 343 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
341 endwin (); 344 endwin();
342 fprintf (stderr, "\nError moving file pointer in " 345 fprintf(stderr,
343 "back_lines().\n"); 346 "\nError moving file pointer in "
344 exit (-1); 347 "back_lines().\n");
345 } 348 exit(-1);
346 if (fpos > bytes_read) { /* Not beginning of file yet */ 349 }
347 /* We've reached beginning of buffer, but not beginning of 350 if (fpos > bytes_read) { /* Not beginning of file yet */
348 file yet, so read previous part of file into buffer. 351 /* We've reached beginning of buffer, but not beginning of
349 Note that we only move backward for BUF_SIZE/2 bytes, 352 file yet, so read previous part of file into buffer.
350 but not BUF_SIZE bytes to avoid re-reading again in 353 Note that we only move backward for BUF_SIZE/2 bytes,
351 print_page() later */ 354 but not BUF_SIZE bytes to avoid re-reading again in
352 /* Really possible to move backward BUF_SIZE/2 bytes? */ 355 print_page() later */
353 if (fpos < BUF_SIZE / 2 + bytes_read) { 356 /* Really possible to move backward BUF_SIZE/2 bytes? */
354 /* No, move less then */ 357 if (fpos < BUF_SIZE / 2 + bytes_read) {
355 if (lseek (fd, 0, SEEK_SET) == -1) { 358 /* No, move less then */
356 endwin (); 359 if (lseek(fd, 0, SEEK_SET) == -1) {
357 fprintf (stderr, "\nError moving file pointer in " 360 endwin();
358 "back_lines().\n"); 361 fprintf(stderr,
359 exit (-1); 362 "\nError moving file pointer in "
360 } 363 "back_lines().\n");
361 page = buf + fpos - bytes_read; 364 exit(-1);
362 } else { /* Move backward BUF_SIZE/2 bytes */ 365 }
363 if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) 366 page = buf + fpos - bytes_read;
364 == -1) { 367 } else { /* Move backward BUF_SIZE/2 bytes */
365 endwin (); 368 if (lseek
366 fprintf (stderr, "\nError moving file pointer " 369 (fd, -(BUF_SIZE / 2 + bytes_read),
367 "in back_lines().\n"); 370 SEEK_CUR)
368 exit (-1); 371 == -1) {
369 } 372 endwin();
370 page = buf + BUF_SIZE / 2; 373 fprintf(stderr,
374 "\nError moving file pointer "
375 "in back_lines().\n");
376 exit(-1);
377 }
378 page = buf + BUF_SIZE / 2;
379 }
380 if ((bytes_read =
381 read(fd, buf, BUF_SIZE)) == -1) {
382 endwin();
383 fprintf(stderr,
384 "\nError reading file in back_lines().\n");
385 exit(-1);
386 }
387 buf[bytes_read] = '\0';
388 } else { /* Beginning of file reached */
389 begin_reached = 1;
390 return;
391 }
371 } 392 }
372 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { 393 if (*(--page) != '\n') { /* '--page' here */
373 endwin (); 394 /* Something's wrong... */
374 fprintf (stderr, "\nError reading file in back_lines().\n"); 395 endwin();
375 exit (-1); 396 fprintf(stderr, "\nInternal error in back_lines().\n");
397 exit(-1);
376 } 398 }
377 buf[bytes_read] = '\0';
378 } else { /* Beginning of file reached */
379 begin_reached = 1;
380 return;
381 }
382 }
383 if (*(--page) != '\n') { /* '--page' here */
384 /* Something's wrong... */
385 endwin ();
386 fprintf (stderr, "\nInternal error in back_lines().\n");
387 exit (-1);
388 } 399 }
389 } 400 /* Go back 'n' lines */
390 /* Go back 'n' lines */ 401 for (i = 0; i < n; i++)
391 for (i = 0; i < n; i++) 402 do {
392 do { 403 if (page == buf) {
393 if (page == buf) { 404 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
394 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { 405 endwin();
395 endwin (); 406 fprintf(stderr,
396 fprintf (stderr, 407 "\nError moving file pointer in back_lines().\n");
397 "\nError moving file pointer in back_lines().\n"); 408 exit(-1);
398 exit (-1); 409 }
399 } 410 if (fpos > bytes_read) {
400 if (fpos > bytes_read) { 411 /* Really possible to move backward BUF_SIZE/2 bytes? */
401 /* Really possible to move backward BUF_SIZE/2 bytes? */ 412 if (fpos < BUF_SIZE / 2 + bytes_read) {
402 if (fpos < BUF_SIZE / 2 + bytes_read) { 413 /* No, move less then */
403 /* No, move less then */ 414 if (lseek(fd, 0, SEEK_SET) ==
404 if (lseek (fd, 0, SEEK_SET) == -1) { 415 -1) {
405 endwin (); 416 endwin();
406 fprintf (stderr, "\nError moving file pointer " 417 fprintf(stderr,
407 "in back_lines().\n"); 418 "\nError moving file pointer "
408 exit (-1); 419 "in back_lines().\n");
409 } 420 exit(-1);
410 page = buf + fpos - bytes_read; 421 }
411 } else { /* Move backward BUF_SIZE/2 bytes */ 422 page = buf + fpos - bytes_read;
412 if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), 423 } else { /* Move backward BUF_SIZE/2 bytes */
413 SEEK_CUR) == -1) { 424 if (lseek
414 endwin (); 425 (fd,
415 fprintf (stderr, "\nError moving file pointer" 426 -(BUF_SIZE / 2 +
416 " in back_lines().\n"); 427 bytes_read),
417 exit (-1); 428 SEEK_CUR) == -1) {
429 endwin();
430 fprintf(stderr,
431 "\nError moving file pointer"
432 " in back_lines().\n");
433 exit(-1);
434 }
435 page = buf + BUF_SIZE / 2;
436 }
437 if ((bytes_read =
438 read(fd, buf, BUF_SIZE)) == -1) {
439 endwin();
440 fprintf(stderr,
441 "\nError reading file in "
442 "back_lines().\n");
443 exit(-1);
444 }
445 buf[bytes_read] = '\0';
446 } else { /* Beginning of file reached */
447 begin_reached = 1;
448 return;
449 }
418 } 450 }
419 page = buf + BUF_SIZE / 2; 451 } while (*(--page) != '\n');
420 } 452 page++;
421 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {
422 endwin ();
423 fprintf (stderr, "\nError reading file in "
424 "back_lines().\n");
425 exit (-1);
426 }
427 buf[bytes_read] = '\0';
428 } else { /* Beginning of file reached */
429 begin_reached = 1;
430 return;
431 }
432 }
433 } while (*(--page) != '\n');
434 page++;
435} 453}
436 454
437/* 455/*
438 * Print a new page of text. Called by dialog_textbox(). 456 * Print a new page of text. Called by dialog_textbox().
439 */ 457 */
440static void 458static void print_page(WINDOW * win, int height, int width)
441print_page (WINDOW * win, int height, int width)
442{ 459{
443 int i, passed_end = 0; 460 int i, passed_end = 0;
444 461
445 page_length = 0; 462 page_length = 0;
446 for (i = 0; i < height; i++) { 463 for (i = 0; i < height; i++) {
447 print_line (win, i, width); 464 print_line(win, i, width);
448 if (!passed_end) 465 if (!passed_end)
449 page_length++; 466 page_length++;
450 if (end_reached && !passed_end) 467 if (end_reached && !passed_end)
451 passed_end = 1; 468 passed_end = 1;
452 } 469 }
453 wnoutrefresh (win); 470 wnoutrefresh(win);
454} 471}
455 472
456/* 473/*
457 * Print a new line of text. Called by dialog_textbox() and print_page(). 474 * Print a new line of text. Called by dialog_textbox() and print_page().
458 */ 475 */
459static void 476static void print_line(WINDOW * win, int row, int width)
460print_line (WINDOW * win, int row, int width)
461{ 477{
462 int y, x; 478 int y, x;
463 char *line; 479 char *line;
464 480
465 line = get_line (); 481 line = get_line();
466 line += MIN (strlen (line), hscroll); /* Scroll horizontally */ 482 line += MIN(strlen(line), hscroll); /* Scroll horizontally */
467 wmove (win, row, 0); /* move cursor to correct line */ 483 wmove(win, row, 0); /* move cursor to correct line */
468 waddch (win, ' '); 484 waddch(win, ' ');
469 waddnstr (win, line, MIN (strlen (line), width - 2)); 485 waddnstr(win, line, MIN(strlen(line), width - 2));
470 486
471 getyx (win, y, x); 487 getyx(win, y, x);
472 /* Clear 'residue' of previous line */ 488 /* Clear 'residue' of previous line */
473#if OLD_NCURSES 489#if OLD_NCURSES
474 { 490 {
475 int i; 491 int i;
476 for (i = 0; i < width - x; i++) 492 for (i = 0; i < width - x; i++)
477 waddch (win, ' '); 493 waddch(win, ' ');
478 } 494 }
479#else 495#else
480 wclrtoeol(win); 496 wclrtoeol(win);
481#endif 497#endif
482} 498}
483 499
@@ -486,71 +502,73 @@ print_line (WINDOW * win, int row, int width)
486 * 'page' should point to start of current line before calling, and will be 502 * 'page' should point to start of current line before calling, and will be
487 * updated to point to start of next line. 503 * updated to point to start of next line.
488 */ 504 */
489static char * 505static char *get_line(void)
490get_line (void)
491{ 506{
492 int i = 0, fpos; 507 int i = 0, fpos;
493 static char line[MAX_LEN + 1]; 508 static char line[MAX_LEN + 1];
494 509
495 end_reached = 0; 510 end_reached = 0;
496 while (*page != '\n') { 511 while (*page != '\n') {
497 if (*page == '\0') { 512 if (*page == '\0') {
498 /* Either end of file or end of buffer reached */ 513 /* Either end of file or end of buffer reached */
499 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { 514 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
500 endwin (); 515 endwin();
501 fprintf (stderr, "\nError moving file pointer in " 516 fprintf(stderr,
502 "get_line().\n"); 517 "\nError moving file pointer in "
503 exit (-1); 518 "get_line().\n");
504 } 519 exit(-1);
505 if (fpos < file_size) { /* Not end of file yet */ 520 }
506 /* We've reached end of buffer, but not end of file yet, 521 if (fpos < file_size) { /* Not end of file yet */
507 so read next part of file into buffer */ 522 /* We've reached end of buffer, but not end of file yet,
508 if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) { 523 so read next part of file into buffer */
509 endwin (); 524 if ((bytes_read =
510 fprintf (stderr, "\nError reading file in get_line().\n"); 525 read(fd, buf, BUF_SIZE)) == -1) {
511 exit (-1); 526 endwin();
527 fprintf(stderr,
528 "\nError reading file in get_line().\n");
529 exit(-1);
530 }
531 buf[bytes_read] = '\0';
532 page = buf;
533 } else {
534 if (!end_reached)
535 end_reached = 1;
536 break;
537 }
538 } else if (i < MAX_LEN)
539 line[i++] = *(page++);
540 else {
541 /* Truncate lines longer than MAX_LEN characters */
542 if (i == MAX_LEN)
543 line[i++] = '\0';
544 page++;
512 } 545 }
513 buf[bytes_read] = '\0';
514 page = buf;
515 } else {
516 if (!end_reached)
517 end_reached = 1;
518 break;
519 }
520 } else if (i < MAX_LEN)
521 line[i++] = *(page++);
522 else {
523 /* Truncate lines longer than MAX_LEN characters */
524 if (i == MAX_LEN)
525 line[i++] = '\0';
526 page++;
527 } 546 }
528 } 547 if (i <= MAX_LEN)
529 if (i <= MAX_LEN) 548 line[i] = '\0';
530 line[i] = '\0'; 549 if (!end_reached)
531 if (!end_reached) 550 page++; /* move pass '\n' */
532 page++; /* move pass '\n' */
533 551
534 return line; 552 return line;
535} 553}
536 554
537/* 555/*
538 * Print current position 556 * Print current position
539 */ 557 */
540static void 558static void print_position(WINDOW * win, int height, int width)
541print_position (WINDOW * win, int height, int width)
542{ 559{
543 int fpos, percent; 560 int fpos, percent;
544 561
545 if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { 562 if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) {
546 endwin (); 563 endwin();
547 fprintf (stderr, "\nError moving file pointer in print_position().\n"); 564 fprintf(stderr,
548 exit (-1); 565 "\nError moving file pointer in print_position().\n");
549 } 566 exit(-1);
550 wattrset (win, position_indicator_attr); 567 }
551 wbkgdset (win, position_indicator_attr & A_COLOR); 568 wattrset(win, position_indicator_attr);
552 percent = !file_size ? 569 wbkgdset(win, position_indicator_attr & A_COLOR);
553 100 : ((fpos - bytes_read + page - buf) * 100) / file_size; 570 percent = !file_size ?
554 wmove (win, height - 3, width - 9); 571 100 : ((fpos - bytes_read + page - buf) * 100) / file_size;
555 wprintw (win, "(%3d%%)", percent); 572 wmove(win, height - 3, width - 9);
573 wprintw(win, "(%3d%%)", percent);
556} 574}
diff --git a/scripts/lxdialog/util.c b/scripts/lxdialog/util.c
index e7bce9be69c3..232b32c4fc38 100644
--- a/scripts/lxdialog/util.c
+++ b/scripts/lxdialog/util.c
@@ -21,7 +21,6 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24
25/* use colors by default? */ 24/* use colors by default? */
26bool use_colors = 1; 25bool use_colors = 1;
27 26
@@ -32,326 +31,318 @@ const char *dialog_result;
32/* 31/*
33 * Attribute values, default is for mono display 32 * Attribute values, default is for mono display
34 */ 33 */
35chtype attributes[] = 34chtype attributes[] = {
36{ 35 A_NORMAL, /* screen_attr */
37 A_NORMAL, /* screen_attr */ 36 A_NORMAL, /* shadow_attr */
38 A_NORMAL, /* shadow_attr */ 37 A_NORMAL, /* dialog_attr */
39 A_NORMAL, /* dialog_attr */ 38 A_BOLD, /* title_attr */
40 A_BOLD, /* title_attr */ 39 A_NORMAL, /* border_attr */
41 A_NORMAL, /* border_attr */ 40 A_REVERSE, /* button_active_attr */
42 A_REVERSE, /* button_active_attr */ 41 A_DIM, /* button_inactive_attr */
43 A_DIM, /* button_inactive_attr */ 42 A_REVERSE, /* button_key_active_attr */
44 A_REVERSE, /* button_key_active_attr */ 43 A_BOLD, /* button_key_inactive_attr */
45 A_BOLD, /* button_key_inactive_attr */ 44 A_REVERSE, /* button_label_active_attr */
46 A_REVERSE, /* button_label_active_attr */ 45 A_NORMAL, /* button_label_inactive_attr */
47 A_NORMAL, /* button_label_inactive_attr */ 46 A_NORMAL, /* inputbox_attr */
48 A_NORMAL, /* inputbox_attr */ 47 A_NORMAL, /* inputbox_border_attr */
49 A_NORMAL, /* inputbox_border_attr */ 48 A_NORMAL, /* searchbox_attr */
50 A_NORMAL, /* searchbox_attr */ 49 A_BOLD, /* searchbox_title_attr */
51 A_BOLD, /* searchbox_title_attr */ 50 A_NORMAL, /* searchbox_border_attr */
52 A_NORMAL, /* searchbox_border_attr */ 51 A_BOLD, /* position_indicator_attr */
53 A_BOLD, /* position_indicator_attr */ 52 A_NORMAL, /* menubox_attr */
54 A_NORMAL, /* menubox_attr */ 53 A_NORMAL, /* menubox_border_attr */
55 A_NORMAL, /* menubox_border_attr */ 54 A_NORMAL, /* item_attr */
56 A_NORMAL, /* item_attr */ 55 A_REVERSE, /* item_selected_attr */
57 A_REVERSE, /* item_selected_attr */ 56 A_BOLD, /* tag_attr */
58 A_BOLD, /* tag_attr */ 57 A_REVERSE, /* tag_selected_attr */
59 A_REVERSE, /* tag_selected_attr */ 58 A_BOLD, /* tag_key_attr */
60 A_BOLD, /* tag_key_attr */ 59 A_REVERSE, /* tag_key_selected_attr */
61 A_REVERSE, /* tag_key_selected_attr */ 60 A_BOLD, /* check_attr */
62 A_BOLD, /* check_attr */ 61 A_REVERSE, /* check_selected_attr */
63 A_REVERSE, /* check_selected_attr */ 62 A_BOLD, /* uarrow_attr */
64 A_BOLD, /* uarrow_attr */ 63 A_BOLD /* darrow_attr */
65 A_BOLD /* darrow_attr */
66}; 64};
67 65
68
69#include "colors.h" 66#include "colors.h"
70 67
71/* 68/*
72 * Table of color values 69 * Table of color values
73 */ 70 */
74int color_table[][3] = 71int color_table[][3] = {
75{ 72 {SCREEN_FG, SCREEN_BG, SCREEN_HL},
76 {SCREEN_FG, SCREEN_BG, SCREEN_HL}, 73 {SHADOW_FG, SHADOW_BG, SHADOW_HL},
77 {SHADOW_FG, SHADOW_BG, SHADOW_HL}, 74 {DIALOG_FG, DIALOG_BG, DIALOG_HL},
78 {DIALOG_FG, DIALOG_BG, DIALOG_HL}, 75 {TITLE_FG, TITLE_BG, TITLE_HL},
79 {TITLE_FG, TITLE_BG, TITLE_HL}, 76 {BORDER_FG, BORDER_BG, BORDER_HL},
80 {BORDER_FG, BORDER_BG, BORDER_HL}, 77 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL},
81 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, 78 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL},
82 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, 79 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL},
83 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, 80 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG,
84 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, BUTTON_KEY_INACTIVE_HL}, 81 BUTTON_KEY_INACTIVE_HL},
85 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, BUTTON_LABEL_ACTIVE_HL}, 82 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG,
86 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG, 83 BUTTON_LABEL_ACTIVE_HL},
87 BUTTON_LABEL_INACTIVE_HL}, 84 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
88 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL}, 85 BUTTON_LABEL_INACTIVE_HL},
89 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL}, 86 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
90 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL}, 87 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
91 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL}, 88 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
92 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL}, 89 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
93 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL}, 90 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
94 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL}, 91 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
95 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL}, 92 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
96 {ITEM_FG, ITEM_BG, ITEM_HL}, 93 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
97 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL}, 94 {ITEM_FG, ITEM_BG, ITEM_HL},
98 {TAG_FG, TAG_BG, TAG_HL}, 95 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
99 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL}, 96 {TAG_FG, TAG_BG, TAG_HL},
100 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL}, 97 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
101 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL}, 98 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
102 {CHECK_FG, CHECK_BG, CHECK_HL}, 99 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
103 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL}, 100 {CHECK_FG, CHECK_BG, CHECK_HL},
104 {UARROW_FG, UARROW_BG, UARROW_HL}, 101 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
105 {DARROW_FG, DARROW_BG, DARROW_HL}, 102 {UARROW_FG, UARROW_BG, UARROW_HL},
103 {DARROW_FG, DARROW_BG, DARROW_HL},
106}; /* color_table */ 104}; /* color_table */
107 105
108/* 106/*
109 * Set window to attribute 'attr' 107 * Set window to attribute 'attr'
110 */ 108 */
111void 109void attr_clear(WINDOW * win, int height, int width, chtype attr)
112attr_clear (WINDOW * win, int height, int width, chtype attr)
113{ 110{
114 int i, j; 111 int i, j;
115 112
116 wattrset (win, attr); 113 wattrset(win, attr);
117 for (i = 0; i < height; i++) { 114 for (i = 0; i < height; i++) {
118 wmove (win, i, 0); 115 wmove(win, i, 0);
119 for (j = 0; j < width; j++) 116 for (j = 0; j < width; j++)
120 waddch (win, ' '); 117 waddch(win, ' ');
121 } 118 }
122 touchwin (win); 119 touchwin(win);
123} 120}
124 121
125void dialog_clear (void) 122void dialog_clear(void)
126{ 123{
127 attr_clear (stdscr, LINES, COLS, screen_attr); 124 attr_clear(stdscr, LINES, COLS, screen_attr);
128 /* Display background title if it exists ... - SLH */ 125 /* Display background title if it exists ... - SLH */
129 if (backtitle != NULL) { 126 if (backtitle != NULL) {
130 int i; 127 int i;
131 128
132 wattrset (stdscr, screen_attr); 129 wattrset(stdscr, screen_attr);
133 mvwaddstr (stdscr, 0, 1, (char *)backtitle); 130 mvwaddstr(stdscr, 0, 1, (char *)backtitle);
134 wmove (stdscr, 1, 1); 131 wmove(stdscr, 1, 1);
135 for (i = 1; i < COLS - 1; i++) 132 for (i = 1; i < COLS - 1; i++)
136 waddch (stdscr, ACS_HLINE); 133 waddch(stdscr, ACS_HLINE);
137 } 134 }
138 wnoutrefresh (stdscr); 135 wnoutrefresh(stdscr);
139} 136}
140 137
141/* 138/*
142 * Do some initialization for dialog 139 * Do some initialization for dialog
143 */ 140 */
144void 141void init_dialog(void)
145init_dialog (void)
146{ 142{
147 initscr (); /* Init curses */ 143 initscr(); /* Init curses */
148 keypad (stdscr, TRUE); 144 keypad(stdscr, TRUE);
149 cbreak (); 145 cbreak();
150 noecho (); 146 noecho();
151 147
148 if (use_colors) /* Set up colors */
149 color_setup();
152 150
153 if (use_colors) /* Set up colors */ 151 dialog_clear();
154 color_setup ();
155
156
157 dialog_clear ();
158} 152}
159 153
160/* 154/*
161 * Setup for color display 155 * Setup for color display
162 */ 156 */
163void 157void color_setup(void)
164color_setup (void)
165{ 158{
166 int i; 159 int i;
167 160
168 if (has_colors ()) { /* Terminal supports color? */ 161 if (has_colors()) { /* Terminal supports color? */
169 start_color (); 162 start_color();
170 163
171 /* Initialize color pairs */ 164 /* Initialize color pairs */
172 for (i = 0; i < ATTRIBUTE_COUNT; i++) 165 for (i = 0; i < ATTRIBUTE_COUNT; i++)
173 init_pair (i + 1, color_table[i][0], color_table[i][1]); 166 init_pair(i + 1, color_table[i][0], color_table[i][1]);
174 167
175 /* Setup color attributes */ 168 /* Setup color attributes */
176 for (i = 0; i < ATTRIBUTE_COUNT; i++) 169 for (i = 0; i < ATTRIBUTE_COUNT; i++)
177 attributes[i] = C_ATTR (color_table[i][2], i + 1); 170 attributes[i] = C_ATTR(color_table[i][2], i + 1);
178 } 171 }
179} 172}
180 173
181/* 174/*
182 * End using dialog functions. 175 * End using dialog functions.
183 */ 176 */
184void 177void end_dialog(void)
185end_dialog (void)
186{ 178{
187 endwin (); 179 endwin();
188} 180}
189 181
190
191/* 182/*
192 * Print a string of text in a window, automatically wrap around to the 183 * Print a string of text in a window, automatically wrap around to the
193 * next line if the string is too long to fit on one line. Newline 184 * next line if the string is too long to fit on one line. Newline
194 * characters '\n' are replaced by spaces. We start on a new line 185 * characters '\n' are replaced by spaces. We start on a new line
195 * if there is no room for at least 4 nonblanks following a double-space. 186 * if there is no room for at least 4 nonblanks following a double-space.
196 */ 187 */
197void 188void print_autowrap(WINDOW * win, const char *prompt, int width, int y, int x)
198print_autowrap (WINDOW * win, const char *prompt, int width, int y, int x)
199{ 189{
200 int newl, cur_x, cur_y; 190 int newl, cur_x, cur_y;
201 int i, prompt_len, room, wlen; 191 int i, prompt_len, room, wlen;
202 char tempstr[MAX_LEN + 1], *word, *sp, *sp2; 192 char tempstr[MAX_LEN + 1], *word, *sp, *sp2;
203 193
204 strcpy (tempstr, prompt); 194 strcpy(tempstr, prompt);
205 195
206 prompt_len = strlen(tempstr); 196 prompt_len = strlen(tempstr);
207 197
208 /* 198 /*
209 * Remove newlines 199 * Remove newlines
210 */ 200 */
211 for(i=0; i<prompt_len; i++) { 201 for (i = 0; i < prompt_len; i++) {
212 if(tempstr[i] == '\n') tempstr[i] = ' '; 202 if (tempstr[i] == '\n')
213 } 203 tempstr[i] = ' ';
214 204 }
215 if (prompt_len <= width - x * 2) { /* If prompt is short */ 205
216 wmove (win, y, (width - prompt_len) / 2); 206 if (prompt_len <= width - x * 2) { /* If prompt is short */
217 waddstr (win, tempstr); 207 wmove(win, y, (width - prompt_len) / 2);
218 } else { 208 waddstr(win, tempstr);
219 cur_x = x; 209 } else {
220 cur_y = y;
221 newl = 1;
222 word = tempstr;
223 while (word && *word) {
224 sp = index(word, ' ');
225 if (sp)
226 *sp++ = 0;
227
228 /* Wrap to next line if either the word does not fit,
229 or it is the first word of a new sentence, and it is
230 short, and the next word does not fit. */
231 room = width - cur_x;
232 wlen = strlen(word);
233 if (wlen > room ||
234 (newl && wlen < 4 && sp && wlen+1+strlen(sp) > room
235 && (!(sp2 = index(sp, ' ')) || wlen+1+(sp2-sp) > room))) {
236 cur_y++;
237 cur_x = x; 210 cur_x = x;
238 } 211 cur_y = y;
239 wmove (win, cur_y, cur_x);
240 waddstr (win, word);
241 getyx (win, cur_y, cur_x);
242 cur_x++;
243 if (sp && *sp == ' ') {
244 cur_x++; /* double space */
245 while (*++sp == ' ');
246 newl = 1; 212 newl = 1;
247 } else 213 word = tempstr;
248 newl = 0; 214 while (word && *word) {
249 word = sp; 215 sp = index(word, ' ');
216 if (sp)
217 *sp++ = 0;
218
219 /* Wrap to next line if either the word does not fit,
220 or it is the first word of a new sentence, and it is
221 short, and the next word does not fit. */
222 room = width - cur_x;
223 wlen = strlen(word);
224 if (wlen > room ||
225 (newl && wlen < 4 && sp
226 && wlen + 1 + strlen(sp) > room
227 && (!(sp2 = index(sp, ' '))
228 || wlen + 1 + (sp2 - sp) > room))) {
229 cur_y++;
230 cur_x = x;
231 }
232 wmove(win, cur_y, cur_x);
233 waddstr(win, word);
234 getyx(win, cur_y, cur_x);
235 cur_x++;
236 if (sp && *sp == ' ') {
237 cur_x++; /* double space */
238 while (*++sp == ' ') ;
239 newl = 1;
240 } else
241 newl = 0;
242 word = sp;
243 }
250 } 244 }
251 }
252} 245}
253 246
254/* 247/*
255 * Print a button 248 * Print a button
256 */ 249 */
257void 250void print_button(WINDOW * win, const char *label, int y, int x, int selected)
258print_button (WINDOW * win, const char *label, int y, int x, int selected)
259{ 251{
260 int i, temp; 252 int i, temp;
261 253
262 wmove (win, y, x); 254 wmove(win, y, x);
263 wattrset (win, selected ? button_active_attr : button_inactive_attr); 255 wattrset(win, selected ? button_active_attr : button_inactive_attr);
264 waddstr (win, "<"); 256 waddstr(win, "<");
265 temp = strspn (label, " "); 257 temp = strspn(label, " ");
266 label += temp; 258 label += temp;
267 wattrset (win, selected ? button_label_active_attr 259 wattrset(win, selected ? button_label_active_attr
268 : button_label_inactive_attr); 260 : button_label_inactive_attr);
269 for (i = 0; i < temp; i++) 261 for (i = 0; i < temp; i++)
270 waddch (win, ' '); 262 waddch(win, ' ');
271 wattrset (win, selected ? button_key_active_attr 263 wattrset(win, selected ? button_key_active_attr
272 : button_key_inactive_attr); 264 : button_key_inactive_attr);
273 waddch (win, label[0]); 265 waddch(win, label[0]);
274 wattrset (win, selected ? button_label_active_attr 266 wattrset(win, selected ? button_label_active_attr
275 : button_label_inactive_attr); 267 : button_label_inactive_attr);
276 waddstr (win, (char *)label + 1); 268 waddstr(win, (char *)label + 1);
277 wattrset (win, selected ? button_active_attr : button_inactive_attr); 269 wattrset(win, selected ? button_active_attr : button_inactive_attr);
278 waddstr (win, ">"); 270 waddstr(win, ">");
279 wmove (win, y, x + temp + 1); 271 wmove(win, y, x + temp + 1);
280} 272}
281 273
282/* 274/*
283 * Draw a rectangular box with line drawing characters 275 * Draw a rectangular box with line drawing characters
284 */ 276 */
285void 277void
286draw_box (WINDOW * win, int y, int x, int height, int width, 278draw_box(WINDOW * win, int y, int x, int height, int width,
287 chtype box, chtype border) 279 chtype box, chtype border)
288{ 280{
289 int i, j; 281 int i, j;
290 282
291 wattrset (win, 0); 283 wattrset(win, 0);
292 for (i = 0; i < height; i++) { 284 for (i = 0; i < height; i++) {
293 wmove (win, y + i, x); 285 wmove(win, y + i, x);
294 for (j = 0; j < width; j++) 286 for (j = 0; j < width; j++)
295 if (!i && !j) 287 if (!i && !j)
296 waddch (win, border | ACS_ULCORNER); 288 waddch(win, border | ACS_ULCORNER);
297 else if (i == height - 1 && !j) 289 else if (i == height - 1 && !j)
298 waddch (win, border | ACS_LLCORNER); 290 waddch(win, border | ACS_LLCORNER);
299 else if (!i && j == width - 1) 291 else if (!i && j == width - 1)
300 waddch (win, box | ACS_URCORNER); 292 waddch(win, box | ACS_URCORNER);
301 else if (i == height - 1 && j == width - 1) 293 else if (i == height - 1 && j == width - 1)
302 waddch (win, box | ACS_LRCORNER); 294 waddch(win, box | ACS_LRCORNER);
303 else if (!i) 295 else if (!i)
304 waddch (win, border | ACS_HLINE); 296 waddch(win, border | ACS_HLINE);
305 else if (i == height - 1) 297 else if (i == height - 1)
306 waddch (win, box | ACS_HLINE); 298 waddch(win, box | ACS_HLINE);
307 else if (!j) 299 else if (!j)
308 waddch (win, border | ACS_VLINE); 300 waddch(win, border | ACS_VLINE);
309 else if (j == width - 1) 301 else if (j == width - 1)
310 waddch (win, box | ACS_VLINE); 302 waddch(win, box | ACS_VLINE);
311 else 303 else
312 waddch (win, box | ' '); 304 waddch(win, box | ' ');
313 } 305 }
314} 306}
315 307
316/* 308/*
317 * Draw shadows along the right and bottom edge to give a more 3D look 309 * Draw shadows along the right and bottom edge to give a more 3D look
318 * to the boxes 310 * to the boxes
319 */ 311 */
320void 312void draw_shadow(WINDOW * win, int y, int x, int height, int width)
321draw_shadow (WINDOW * win, int y, int x, int height, int width)
322{ 313{
323 int i; 314 int i;
324 315
325 if (has_colors ()) { /* Whether terminal supports color? */ 316 if (has_colors()) { /* Whether terminal supports color? */
326 wattrset (win, shadow_attr); 317 wattrset(win, shadow_attr);
327 wmove (win, y + height, x + 2); 318 wmove(win, y + height, x + 2);
328 for (i = 0; i < width; i++) 319 for (i = 0; i < width; i++)
329 waddch (win, winch (win) & A_CHARTEXT); 320 waddch(win, winch(win) & A_CHARTEXT);
330 for (i = y + 1; i < y + height + 1; i++) { 321 for (i = y + 1; i < y + height + 1; i++) {
331 wmove (win, i, x + width); 322 wmove(win, i, x + width);
332 waddch (win, winch (win) & A_CHARTEXT); 323 waddch(win, winch(win) & A_CHARTEXT);
333 waddch (win, winch (win) & A_CHARTEXT); 324 waddch(win, winch(win) & A_CHARTEXT);
325 }
326 wnoutrefresh(win);
334 } 327 }
335 wnoutrefresh (win);
336 }
337} 328}
338 329
339/* 330/*
340 * Return the position of the first alphabetic character in a string. 331 * Return the position of the first alphabetic character in a string.
341 */ 332 */
342int 333int first_alpha(const char *string, const char *exempt)
343first_alpha(const char *string, const char *exempt)
344{ 334{
345 int i, in_paren=0, c; 335 int i, in_paren = 0, c;
346 336
347 for (i = 0; i < strlen(string); i++) { 337 for (i = 0; i < strlen(string); i++) {
348 c = tolower(string[i]); 338 c = tolower(string[i]);
349 339
350 if (strchr("<[(", c)) ++in_paren; 340 if (strchr("<[(", c))
351 if (strchr(">])", c) && in_paren > 0) --in_paren; 341 ++in_paren;
342 if (strchr(">])", c) && in_paren > 0)
343 --in_paren;
352 344
353 if ((! in_paren) && isalpha(c) && 345 if ((!in_paren) && isalpha(c) && strchr(exempt, c) == 0)
354 strchr(exempt, c) == 0)
355 return i; 346 return i;
356 } 347 }
357 348
diff --git a/scripts/lxdialog/yesno.c b/scripts/lxdialog/yesno.c
index 11fcc25f5159..dffd5af36713 100644
--- a/scripts/lxdialog/yesno.c
+++ b/scripts/lxdialog/yesno.c
@@ -24,95 +24,93 @@
24/* 24/*
25 * Display termination buttons 25 * Display termination buttons
26 */ 26 */
27static void 27static void print_buttons(WINDOW * dialog, int height, int width, int selected)
28print_buttons(WINDOW *dialog, int height, int width, int selected)
29{ 28{
30 int x = width / 2 - 10; 29 int x = width / 2 - 10;
31 int y = height - 2; 30 int y = height - 2;
32 31
33 print_button (dialog, " Yes ", y, x, selected == 0); 32 print_button(dialog, " Yes ", y, x, selected == 0);
34 print_button (dialog, " No ", y, x + 13, selected == 1); 33 print_button(dialog, " No ", y, x + 13, selected == 1);
35 34
36 wmove(dialog, y, x+1 + 13*selected ); 35 wmove(dialog, y, x + 1 + 13 * selected);
37 wrefresh (dialog); 36 wrefresh(dialog);
38} 37}
39 38
40/* 39/*
41 * Display a dialog box with two buttons - Yes and No 40 * Display a dialog box with two buttons - Yes and No
42 */ 41 */
43int 42int dialog_yesno(const char *title, const char *prompt, int height, int width)
44dialog_yesno (const char *title, const char *prompt, int height, int width)
45{ 43{
46 int i, x, y, key = 0, button = 0; 44 int i, x, y, key = 0, button = 0;
47 WINDOW *dialog; 45 WINDOW *dialog;
48 46
49 /* center dialog box on screen */ 47 /* center dialog box on screen */
50 x = (COLS - width) / 2; 48 x = (COLS - width) / 2;
51 y = (LINES - height) / 2; 49 y = (LINES - height) / 2;
52 50
53 draw_shadow (stdscr, y, x, height, width); 51 draw_shadow(stdscr, y, x, height, width);
54 52
55 dialog = newwin (height, width, y, x); 53 dialog = newwin(height, width, y, x);
56 keypad (dialog, TRUE); 54 keypad(dialog, TRUE);
57 55
58 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr); 56 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
59 wattrset (dialog, border_attr); 57 wattrset(dialog, border_attr);
60 mvwaddch (dialog, height-3, 0, ACS_LTEE); 58 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
61 for (i = 0; i < width - 2; i++) 59 for (i = 0; i < width - 2; i++)
62 waddch (dialog, ACS_HLINE); 60 waddch(dialog, ACS_HLINE);
63 wattrset (dialog, dialog_attr); 61 wattrset(dialog, dialog_attr);
64 waddch (dialog, ACS_RTEE); 62 waddch(dialog, ACS_RTEE);
65 63
66 if (title != NULL && strlen(title) >= width-2 ) { 64 if (title != NULL && strlen(title) >= width - 2) {
67 /* truncate long title -- mec */ 65 /* truncate long title -- mec */
68 char * title2 = malloc(width-2+1); 66 char *title2 = malloc(width - 2 + 1);
69 memcpy( title2, title, width-2 ); 67 memcpy(title2, title, width - 2);
70 title2[width-2] = '\0'; 68 title2[width - 2] = '\0';
71 title = title2; 69 title = title2;
72 }
73
74 if (title != NULL) {
75 wattrset (dialog, title_attr);
76 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
77 waddstr (dialog, (char *)title);
78 waddch (dialog, ' ');
79 }
80
81 wattrset (dialog, dialog_attr);
82 print_autowrap (dialog, prompt, width - 2, 1, 3);
83
84 print_buttons(dialog, height, width, 0);
85
86 while (key != ESC) {
87 key = wgetch (dialog);
88 switch (key) {
89 case 'Y':
90 case 'y':
91 delwin (dialog);
92 return 0;
93 case 'N':
94 case 'n':
95 delwin (dialog);
96 return 1;
97
98 case TAB:
99 case KEY_LEFT:
100 case KEY_RIGHT:
101 button = ((key == KEY_LEFT ? --button : ++button) < 0)
102 ? 1 : (button > 1 ? 0 : button);
103
104 print_buttons(dialog, height, width, button);
105 wrefresh (dialog);
106 break;
107 case ' ':
108 case '\n':
109 delwin (dialog);
110 return button;
111 case ESC:
112 break;
113 } 70 }
114 }
115 71
116 delwin (dialog); 72 if (title != NULL) {
117 return -1; /* ESC pressed */ 73 wattrset(dialog, title_attr);
74 mvwaddch(dialog, 0, (width - strlen(title)) / 2 - 1, ' ');
75 waddstr(dialog, (char *)title);
76 waddch(dialog, ' ');
77 }
78
79 wattrset(dialog, dialog_attr);
80 print_autowrap(dialog, prompt, width - 2, 1, 3);
81
82 print_buttons(dialog, height, width, 0);
83
84 while (key != ESC) {
85 key = wgetch(dialog);
86 switch (key) {
87 case 'Y':
88 case 'y':
89 delwin(dialog);
90 return 0;
91 case 'N':
92 case 'n':
93 delwin(dialog);
94 return 1;
95
96 case TAB:
97 case KEY_LEFT:
98 case KEY_RIGHT:
99 button = ((key == KEY_LEFT ? --button : ++button) < 0)
100 ? 1 : (button > 1 ? 0 : button);
101
102 print_buttons(dialog, height, width, button);
103 wrefresh(dialog);
104 break;
105 case ' ':
106 case '\n':
107 delwin(dialog);
108 return button;
109 case ESC:
110 break;
111 }
112 }
113
114 delwin(dialog);
115 return -1; /* ESC pressed */
118} 116}