aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lxdialog/yesno.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lxdialog/yesno.c')
-rw-r--r--scripts/lxdialog/yesno.c158
1 files changed, 78 insertions, 80 deletions
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}