1 // SPDX-License-Identifier: GPL-2.0+
3 * yesno.c -- implements the yes/no box
5 * ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
6 * MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
12 * Display termination buttons
14 static void print_buttons(WINDOW * dialog, int height, int width, int selected)
16 int x = width / 2 - 10;
19 print_button(dialog, gettext(" Yes "), y, x, selected == 0);
20 print_button(dialog, gettext(" No "), y, x + 13, selected == 1);
22 wmove(dialog, y, x + 1 + 13 * selected);
27 * Display a dialog box with two buttons - Yes and No
29 int dialog_yesno(const char *title, const char *prompt, int height, int width)
31 int i, x, y, key = 0, button = 0;
35 if (getmaxy(stdscr) < (height + YESNO_HEIGTH_MIN))
36 return -ERRDISPLAYTOOSMALL;
37 if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
38 return -ERRDISPLAYTOOSMALL;
40 /* center dialog box on screen */
41 x = (getmaxx(stdscr) - width) / 2;
42 y = (getmaxy(stdscr) - height) / 2;
44 draw_shadow(stdscr, y, x, height, width);
46 dialog = newwin(height, width, y, x);
49 draw_box(dialog, 0, 0, height, width,
50 dlg.dialog.atr, dlg.border.atr);
51 wattrset(dialog, dlg.border.atr);
52 mvwaddch(dialog, height - 3, 0, ACS_LTEE);
53 for (i = 0; i < width - 2; i++)
54 waddch(dialog, ACS_HLINE);
55 wattrset(dialog, dlg.dialog.atr);
56 waddch(dialog, ACS_RTEE);
58 print_title(dialog, title, width);
60 wattrset(dialog, dlg.dialog.atr);
61 print_autowrap(dialog, prompt, width - 2, 1, 3);
63 print_buttons(dialog, height, width, 0);
65 while (key != KEY_ESC) {
80 button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
82 print_buttons(dialog, height, width, button);
90 key = on_key_esc(dialog);
100 return key; /* ESC pressed */