1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-04 12:52:15 +00:00

Add a new function, dialog_noyes(), for sysinstall to be able to

present questinos with a different default answer.  Somebody submitted
a patch to me once which did something this but I lost it (my bad) so
I'm just going to re-implement it with thanks to whomever it was who
gave me the idea.
This commit is contained in:
Jordan K. Hubbard 2000-12-14 02:35:22 +00:00
parent 58ef75f022
commit e6657d443e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=70004
3 changed files with 45 additions and 13 deletions

View File

@ -27,15 +27,18 @@
int
main(int argc, char **argv)
{
int retval;
int rval1, rval2;
init_dialog();
retval = dialog_yesno("This is dialog_yesno() in action",
"Have you stopped deliberately putting bugs into your code?", -1, -1);
rval1 = dialog_yesno("This is dialog_yesno() in action",
"Have you stopped deliberately putting bugs into your code?", -1, -1);
dialog_clear();
rval2 = dialog_noyes("This is dialog_noyes() in action",
"Have you stopped beating your wife?", -1, -1);
dialog_clear();
fprintf(stderr, "returned value for dialog_yesno was %d\n", retval);
end_dialog();
fprintf(stderr, "returned value for dialog_yesno was %d\n", rval1);
fprintf(stderr, "returned value for dialog_noyes was %d\n", rval2);
return 0;
}

View File

@ -21,6 +21,9 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $FreeBSD$
*
*/
#define HAVE_NCURSES
@ -131,6 +134,7 @@ int strwidth(const char *p);
void dialog_create_rc(unsigned char *filename);
int dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width);
int dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width);
int dialog_prgbox(unsigned char *title, const unsigned char *line, int height, int width, int pause, int use_shell);
int dialog_msgbox(unsigned char *title, unsigned char *prompt, int height, int width, int pause);
int dialog_textbox(unsigned char *title, unsigned char *file, int height, int width);

View File

@ -18,15 +18,37 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef lint
static const char rcsid[] = "$FreeBSD$";
#endif
#include <dialog.h>
#include "dialog.priv.h"
/* Actual work function */
static int dialog_yesno_proc(unsigned char *title, unsigned char *prompt,
int height, int width, int yesdefault);
/*
* Display a dialog box with two buttons - Yes and No
*/
int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int width)
int
dialog_yesno(unsigned char *title, unsigned char *prompt, int height, int width)
{
return dialog_yesno_proc(title, prompt, height, width, TRUE);
}
/*
* Display a dialog box with two buttons - No and Yes
*/
int
dialog_noyes(unsigned char *title, unsigned char *prompt, int height, int width)
{
return dialog_yesno_proc(title, prompt, height, width, FALSE);
}
static int
dialog_yesno_proc(unsigned char *title, unsigned char *prompt, int height, int width, int yesdefault)
{
int i, j, x, y, key = 0, button = 0;
WINDOW *dialog;
@ -92,8 +114,8 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
x = width/2-10;
y = height-2;
print_button(dialog, " No ", y, x+13, FALSE);
print_button(dialog, " Yes ", y, x, TRUE);
print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, FALSE);
print_button(dialog, yesdefault ? " Yes " : " No ", y, x, TRUE);
wrefresh(dialog);
while (key != ESC) {
@ -117,13 +139,13 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
case KEY_RIGHT:
if (!button) {
button = 1; /* Indicates "No" button is selected */
print_button(dialog, " Yes ", y, x, FALSE);
print_button(dialog, " No ", y, x+13, TRUE);
print_button(dialog, yesdefault ? " Yes " : " No ", y, x, FALSE);
print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, TRUE);
}
else {
button = 0; /* Indicates "Yes" button is selected */
print_button(dialog, " No ", y, x+13, FALSE);
print_button(dialog, " Yes ", y, x, TRUE);
print_button(dialog, yesdefault ? " No " : " Yes ", y, x+13, FALSE);
print_button(dialog, yesdefault ? " Yes " : " No ", y, x, TRUE);
}
wrefresh(dialog);
break;
@ -132,7 +154,10 @@ int dialog_yesno(unsigned char *title, unsigned char * prompt, int height, int w
case '\n':
delwin(dialog);
restore_helpline(tmphlp);
return button;
if (yesdefault)
return button;
else
return !button;
case ESC:
break;
case KEY_F(1):