brcm-2.4: rip out all /dev/nvram and nvram setting/committing code from the kernel
[openwrt.git] / scripts / config / lxdialog / yesno.c
1 /*
2 * yesno.c -- implements the yes/no box
3 *
4 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "dialog.h"
23
24 /*
25 * Display termination buttons
26 */
27 static void print_buttons(WINDOW * dialog, int height, int width, int selected)
28 {
29 int x = width / 2 - 10;
30 int y = height - 2;
31
32 print_button(dialog, " Yes ", y, x, selected == 0);
33 print_button(dialog, " No ", y, x + 13, selected == 1);
34
35 wmove(dialog, y, x + 1 + 13 * selected);
36 wrefresh(dialog);
37 }
38
39 /*
40 * Display a dialog box with two buttons - Yes and No
41 */
42 int dialog_yesno(const char *title, const char *prompt, int height, int width)
43 {
44 int i, x, y, key = 0, button = 0;
45 WINDOW *dialog;
46
47 /* center dialog box on screen */
48 x = (COLS - width) / 2;
49 y = (LINES - height) / 2;
50
51 draw_shadow(stdscr, y, x, height, width);
52
53 dialog = newwin(height, width, y, x);
54 keypad(dialog, TRUE);
55
56 draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
57 wattrset(dialog, border_attr);
58 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
59 for (i = 0; i < width - 2; i++)
60 waddch(dialog, ACS_HLINE);
61 wattrset(dialog, dialog_attr);
62 waddch(dialog, ACS_RTEE);
63
64 print_title(dialog, title, width);
65
66 wattrset(dialog, dialog_attr);
67 print_autowrap(dialog, prompt, width - 2, 1, 3);
68
69 print_buttons(dialog, height, width, 0);
70
71 while (key != ESC) {
72 key = wgetch(dialog);
73 switch (key) {
74 case 'Y':
75 case 'y':
76 delwin(dialog);
77 return 0;
78 case 'N':
79 case 'n':
80 delwin(dialog);
81 return 1;
82
83 case TAB:
84 case KEY_LEFT:
85 case KEY_RIGHT:
86 button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
87
88 print_buttons(dialog, height, width, button);
89 wrefresh(dialog);
90 break;
91 case ' ':
92 case '\n':
93 delwin(dialog);
94 return button;
95 case ESC:
96 break;
97 }
98 }
99
100 delwin(dialog);
101 return -1; /* ESC pressed */
102 }
This page took 0.055389 seconds and 5 git commands to generate.