This source file includes following definitions.
- print_buttons
- dialog_yesno
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 #include "dialog.h"
23
24
25
26
27 static void
28 print_buttons(WINDOW *dialog, int height, int width, int selected)
29 {
30 int x = width / 2 - 10;
31 int y = height - 2;
32
33 print_button (dialog, " Yes ", y, x, selected == 0);
34 print_button (dialog, " No ", y, x + 13, selected == 1);
35
36 wmove(dialog, y, x+1 + 13*selected );
37 wrefresh (dialog);
38 }
39
40
41
42
43 int
44 dialog_yesno (const char *title, const char *prompt, int height, int width)
45 {
46 int i, x, y, key = 0, button = 0;
47 WINDOW *dialog;
48
49
50 x = (COLS - width) / 2;
51 y = (LINES - height) / 2;
52
53 draw_shadow (stdscr, y, x, height, width);
54
55 dialog = newwin (height, width, y, x);
56 keypad (dialog, TRUE);
57
58 draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
59 wattrset (dialog, border_attr);
60 mvwaddch (dialog, height-3, 0, ACS_LTEE);
61 for (i = 0; i < width - 2; i++)
62 waddch (dialog, ACS_HLINE);
63 wattrset (dialog, dialog_attr);
64 waddch (dialog, ACS_RTEE);
65
66 if (title != NULL) {
67 wattrset (dialog, title_attr);
68 mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
69 waddstr (dialog, (char *)title);
70 waddch (dialog, ' ');
71 }
72
73 wattrset (dialog, dialog_attr);
74 print_autowrap (dialog, prompt, width - 2, 1, 3);
75
76 print_buttons(dialog, height, width, 0);
77
78 while (key != ESC) {
79 key = wgetch (dialog);
80 switch (key) {
81 case 'Y':
82 case 'y':
83 delwin (dialog);
84 return 0;
85 case 'N':
86 case 'n':
87 delwin (dialog);
88 return 1;
89
90 case TAB:
91 case KEY_LEFT:
92 case KEY_RIGHT:
93 button = ((key == KEY_LEFT ? --button : ++button) < 0)
94 ? 1 : (button > 1 ? 0 : button);
95
96 print_buttons(dialog, height, width, button);
97 wrefresh (dialog);
98 break;
99 case ' ':
100 case '\n':
101 delwin (dialog);
102 return button;
103 case ESC:
104 break;
105 }
106 }
107
108 delwin (dialog);
109 return -1;
110 }