xref: /freebsd/contrib/bsddialog/examples_library/msgbox.c (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1 /*-
2  * SPDX-License-Identifier: CC0-1.0
3  *
4  * Written in 2021 by Alfonso Sabato Siciliano.
5  * To the extent possible under law, the author has dedicated all copyright
6  * and related and neighboring rights to this software to the public domain
7  * worldwide. This software is distributed without any warranty, see:
8  *   <http://creativecommons.org/publicdomain/zero/1.0/>.
9  */
10 
11 #include <stdio.h>
12 #include <string.h>
13 
14 #include <bsddialog.h>
15 
16 int main()
17 {
18 	int input;
19 	struct bsddialog_conf conf;
20 
21 	/* Configuration */
22 	bsddialog_initconf(&conf);
23 	conf.title = "msgbox";
24 
25 	/* Run BSDDialog */
26 	if (bsddialog_init() == BSDDIALOG_ERROR) {
27 		printf("Error: %s\n", bsddialog_geterror());
28 		return -1;
29 	}
30 	input = bsddialog_msgbox(&conf, "Example", 7, 20);
31 	bsddialog_end();
32 
33 	/* User Input */
34 	printf("User input: ");
35 	switch (input) {
36 	case BSDDIALOG_ERROR: printf("Error %s\n", bsddialog_geterror()); break;
37 	case BSDDIALOG_OK: printf("OK\n");  break;
38 	case BSDDIALOG_ESC:   printf("ESC\n"); break;
39 	}
40 
41 	return input;
42 }
43