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 output;
19 	unsigned int i, j;
20 	struct bsddialog_conf conf;
21 	struct bsddialog_menuitem item;
22 	struct bsddialog_menuitem check[5] = {
23 	    { "+", true,  0, "Name 1", "Desc 1", "Bottom Desc 1" },
24 	    { "" , false, 0, "Name 2", "Desc 2", "Bottom Desc 2" },
25 	    { "+", true,  0, "Name 3", "Desc 3", "Bottom Desc 3" },
26 	    { "" , false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },
27 	    { "+", true,  0, "Name 5", "Desc 5", "Bottom Desc 5" }
28 	};
29 	struct bsddialog_menuitem sep[1] = {
30 	    { "", true, 0, "Radiolist", "(desc)", "" }
31 	};
32 	struct bsddialog_menuitem radio[5] = {
33 	    { "",  true,  0, "Name 1", "Desc 1", "Bottom Desc 1" },
34 	    { "+", false, 0, "Name 2", "Desc 2", "Bottom Desc 2" },
35 	    { "",  false, 0, "Name 3", "Desc 3", "Bottom Desc 3" },
36 	    { "+", false, 0, "Name 4", "Desc 4", "Bottom Desc 4" },
37 	    { "",  false, 0, "Name 5", "Desc 5", "Bottom Desc 5" }
38 	};
39 	struct bsddialog_menugroup group[3] = {
40 	    { BSDDIALOG_CHECKLIST, 5, check },
41 	    { BSDDIALOG_SEPARATOR, 1, sep   },
42 	    { BSDDIALOG_RADIOLIST, 5, radio }
43 	};
44 
45 	if (bsddialog_init() == BSDDIALOG_ERROR) {
46 		printf("Error: %s\n", bsddialog_geterror());
47 		return (1);
48 	}
49 
50 	bsddialog_initconf(&conf);
51 	conf.title = "mixedlist";
52 	output = bsddialog_mixedlist(&conf, "Example", 20, 30, 11, 3, group,
53 	    NULL, NULL);
54 
55 	bsddialog_end();
56 
57 	if (output == BSDDIALOG_ERROR) {
58 		printf("Error: %s\n", bsddialog_geterror());
59 		return (1);
60 	}
61 
62 	if (output == BSDDIALOG_CANCEL) {
63 		printf("Cancel\n");
64 		return (0);
65 	}
66 
67 	printf("Mixedlist:\n");
68 	for (i = 0; i < 3; i++) {
69 		for (j = 0; j < group[i].nitems; j++) {
70 			item = group[i].items[j];
71 			if (group[i].type == BSDDIALOG_SEPARATOR)
72 				printf("----- %s -----\n", item.name);
73 			else if (group[i].type == BSDDIALOG_RADIOLIST)
74 				printf(" (%c) %s\n",
75 				    item.on ? '*' : ' ', item.name);
76 			else /* BSDDIALOG_CHECKLIST */
77 				printf(" [%c] %s\n",
78 				    item.on ? 'X' : ' ', item.name);
79 		}
80 	}
81 
82 	return (output);
83 }