Chameleon

Chameleon Svn Source Tree

Root/tags/2.0/i386/config/yesno.c

Source at commit 1808 created 12 years 3 months ago.
By blackosx, Revise layout of package installer 'Welcome' file so it looks cleaner. Change the copyright notice to begin from 2009 as seen in the Chameleon 2.0 r431 installer. Should this date be set earlier?
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 */
27static void print_buttons(WINDOW * dialog, int height, int width, int selected)
28{
29int x = width / 2 - 10;
30int y = height - 2;
31
32print_button(dialog, gettext(" Yes "), y, x, selected == 0);
33print_button(dialog, gettext(" No "), y, x + 13, selected == 1);
34
35wmove(dialog, y, x + 1 + 13 * selected);
36wrefresh(dialog);
37}
38
39/*
40 * Display a dialog box with two buttons - Yes and No
41 */
42int dialog_yesno(const char *title, const char *prompt, int height, int width)
43{
44int i, x, y, key = 0, button = 0;
45WINDOW *dialog;
46
47do_resize:
48if (getmaxy(stdscr) < (height + 4))
49return -ERRDISPLAYTOOSMALL;
50if (getmaxx(stdscr) < (width + 4))
51return -ERRDISPLAYTOOSMALL;
52
53/* center dialog box on screen */
54x = (COLS - width) / 2;
55y = (LINES - height) / 2;
56
57draw_shadow(stdscr, y, x, height, width);
58
59dialog = newwin(height, width, y, x);
60keypad(dialog, TRUE);
61
62draw_box(dialog, 0, 0, height, width,
63 dlg.dialog.atr, dlg.border.atr);
64wattrset(dialog, dlg.border.atr);
65mvwaddch(dialog, height - 3, 0, ACS_LTEE);
66for (i = 0; i < width - 2; i++)
67waddch(dialog, ACS_HLINE);
68wattrset(dialog, dlg.dialog.atr);
69waddch(dialog, ACS_RTEE);
70
71print_title(dialog, title, width);
72
73wattrset(dialog, dlg.dialog.atr);
74print_autowrap(dialog, prompt, width - 2, 1, 3);
75
76print_buttons(dialog, height, width, 0);
77
78while (key != KEY_ESC) {
79key = wgetch(dialog);
80switch (key) {
81case 'Y':
82case 'y':
83delwin(dialog);
84return 0;
85case 'N':
86case 'n':
87delwin(dialog);
88return 1;
89
90case TAB:
91case KEY_LEFT:
92case KEY_RIGHT:
93button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
94
95print_buttons(dialog, height, width, button);
96wrefresh(dialog);
97break;
98case ' ':
99case '\n':
100delwin(dialog);
101return button;
102case KEY_ESC:
103key = on_key_esc(dialog);
104break;
105case KEY_RESIZE:
106delwin(dialog);
107on_key_resize();
108goto do_resize;
109}
110}
111
112delwin(dialog);
113return key;/* ESC pressed */
114}
115

Archive Download this file

Revision: 1808