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