mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.1 KiB

  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. * MODIFIED FOR ROCK LINUX CONFIG BY: Clifford Wolf (clifford@clifford.at)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include "dialog.h"
  23. /*
  24. * Display termination buttons
  25. */
  26. static void
  27. print_buttons(WINDOW *dialog, int height, int width, int selected)
  28. {
  29. int x = width / 2 - 10;
  30. int y = height - 2;
  31. print_button (dialog, " Yes ", y, x, selected == 0);
  32. print_button (dialog, " No ", y, x + 13, selected == 1);
  33. wmove(dialog, y, x+1 + 13*selected );
  34. wrefresh (dialog);
  35. }
  36. /*
  37. * Display a dialog box with two buttons - Yes and No
  38. */
  39. int
  40. dialog_yesno (const char *title, const char *prompt, int height, int width)
  41. {
  42. int i, x, y, key = 0, button = 0;
  43. WINDOW *dialog;
  44. /* center dialog box on screen */
  45. x = (COLS - width) / 2;
  46. y = (LINES - height) / 2;
  47. draw_shadow (stdscr, y, x, height, width);
  48. dialog = newwin (height, width, y, x);
  49. keypad (dialog, TRUE);
  50. draw_box (dialog, 0, 0, height, width, dialog_attr, border_attr);
  51. wattrset (dialog, border_attr);
  52. mvwaddch (dialog, height-3, 0, ACS_LTEE);
  53. for (i = 0; i < width - 2; i++)
  54. waddch (dialog, ACS_HLINE);
  55. wattrset (dialog, dialog_attr);
  56. waddch (dialog, ACS_RTEE);
  57. if (title != NULL && strlen(title) >= width-2 ) {
  58. /* truncate long title -- mec */
  59. char * title2 = malloc(width-2+1);
  60. memcpy( title2, title, width-2 );
  61. title2[width-2] = '\0';
  62. title = title2;
  63. }
  64. if (title != NULL) {
  65. wattrset (dialog, title_attr);
  66. mvwaddch (dialog, 0, (width - strlen(title))/2 - 1, ' ');
  67. waddstr (dialog, (char *)title);
  68. waddch (dialog, ' ');
  69. }
  70. wattrset (dialog, dialog_attr);
  71. print_autowrap (dialog, prompt, width - 2, 1, 3);
  72. print_buttons(dialog, height, width, 0);
  73. while (key != ESC) {
  74. key = wgetch (dialog);
  75. switch (key) {
  76. case 'Y':
  77. case 'y':
  78. delwin (dialog);
  79. return 0;
  80. case 'N':
  81. case 'n':
  82. delwin (dialog);
  83. return 1;
  84. case TAB:
  85. case KEY_LEFT:
  86. case KEY_RIGHT:
  87. button = ((key == KEY_LEFT ? --button : ++button) < 0)
  88. ? 1 : (button > 1 ? 0 : button);
  89. print_buttons(dialog, height, width, button);
  90. wrefresh (dialog);
  91. break;
  92. case ' ':
  93. case '\n':
  94. delwin (dialog);
  95. return button;
  96. case ESC:
  97. break;
  98. }
  99. }
  100. delwin (dialog);
  101. return -1; /* ESC pressed */
  102. }