~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/kconfig/lxdialog/yesno.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0+
  2 /*
  3  *  yesno.c -- implements the yes/no box
  4  *
  5  *  ORIGINAL AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
  6  *  MODIFIED FOR LINUX KERNEL CONFIG BY: William Roadcap (roadcap@cfw.com)
  7  */
  8 
  9 #include "dialog.h"
 10 
 11 /*
 12  * Display termination buttons
 13  */
 14 static void print_buttons(WINDOW * dialog, int height, int width, int selected)
 15 {
 16         int x = width / 2 - 10;
 17         int y = height - 2;
 18 
 19         print_button(dialog, " Yes ", y, x, selected == 0);
 20         print_button(dialog, "  No  ", y, x + 13, selected == 1);
 21 
 22         wmove(dialog, y, x + 1 + 13 * selected);
 23         wrefresh(dialog);
 24 }
 25 
 26 /*
 27  * Display a dialog box with two buttons - Yes and No
 28  */
 29 int dialog_yesno(const char *title, const char *prompt, int height, int width)
 30 {
 31         int i, x, y, key = 0, button = 0;
 32         WINDOW *dialog;
 33 
 34 do_resize:
 35         if (getmaxy(stdscr) < (height + YESNO_HEIGHT_MIN))
 36                 return -ERRDISPLAYTOOSMALL;
 37         if (getmaxx(stdscr) < (width + YESNO_WIDTH_MIN))
 38                 return -ERRDISPLAYTOOSMALL;
 39 
 40         /* center dialog box on screen */
 41         x = (getmaxx(stdscr) - width) / 2;
 42         y = (getmaxy(stdscr) - height) / 2;
 43 
 44         draw_shadow(stdscr, y, x, height, width);
 45 
 46         dialog = newwin(height, width, y, x);
 47         keypad(dialog, TRUE);
 48 
 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);
 57 
 58         print_title(dialog, title, width);
 59 
 60         wattrset(dialog, dlg.dialog.atr);
 61         print_autowrap(dialog, prompt, width - 2, 1, 3);
 62 
 63         print_buttons(dialog, height, width, 0);
 64 
 65         while (key != KEY_ESC) {
 66                 key = wgetch(dialog);
 67                 switch (key) {
 68                 case 'Y':
 69                 case 'y':
 70                         delwin(dialog);
 71                         return 0;
 72                 case 'N':
 73                 case 'n':
 74                         delwin(dialog);
 75                         return 1;
 76 
 77                 case TAB:
 78                 case KEY_LEFT:
 79                 case KEY_RIGHT:
 80                         button = ((key == KEY_LEFT ? --button : ++button) < 0) ? 1 : (button > 1 ? 0 : button);
 81 
 82                         print_buttons(dialog, height, width, button);
 83                         wrefresh(dialog);
 84                         break;
 85                 case ' ':
 86                 case '\n':
 87                         delwin(dialog);
 88                         return button;
 89                 case KEY_ESC:
 90                         key = on_key_esc(dialog);
 91                         break;
 92                 case KEY_RESIZE:
 93                         delwin(dialog);
 94                         on_key_resize();
 95                         goto do_resize;
 96                 }
 97         }
 98 
 99         delwin(dialog);
100         return key;             /* ESC pressed */
101 }
102 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php