xref: /freebsd/contrib/bsddialog/examples_library/checklist.c (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
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 i, output;
17 	struct bsddialog_conf conf;
18 	struct bsddialog_menuitem items[5] = {
19 	    {"i",   true,  0, "Name 1", "Desc 1", "Bottom Desc 1"},
20 	    {"ii",  false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
21 	    {"iii", true,  0, "Name 3", "Desc 3", "Bottom Desc 3"},
22 	    {"iv",  false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
23 	    {"v",   true,  0, "Name 5", "Desc 5", "Bottom Desc 5"}
24 	};
25 
26 	if (bsddialog_init() == BSDDIALOG_ERROR) {
27 		printf("Error: %s\n", bsddialog_geterror());
28 		return (1);
29 	}
30 	bsddialog_initconf(&conf);
31 	conf.title = "checklist";
32 	output = bsddialog_checklist(&conf, "Example", 15, 30, 5, 5, items,
33 	    NULL);
34 	bsddialog_end();
35 	if (output == BSDDIALOG_ERROR) {
36 		printf("Error: %s\n", bsddialog_geterror());
37 		return (1);
38 	}
39 
40 	printf("Checklist:\n");
41 	for (i = 0; i < 5; i++)
42 		printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
43 
44 	return (0);
45 }