xref: /freebsd/contrib/bsddialog/examples_library/checklist.c (revision 61ba55bcf70f2340f9c943c9571113b3fd8eda69)
1f499134dSBaptiste Daroussin /*-
2f499134dSBaptiste Daroussin  * SPDX-License-Identifier: CC0-1.0
3f499134dSBaptiste Daroussin  *
4f499134dSBaptiste Daroussin  * Written in 2021 by Alfonso Sabato Siciliano.
5f499134dSBaptiste Daroussin  * To the extent possible under law, the author has dedicated all copyright
6f499134dSBaptiste Daroussin  * and related and neighboring rights to this software to the public domain
7f499134dSBaptiste Daroussin  * worldwide. This software is distributed without any warranty, see:
8f499134dSBaptiste Daroussin  *   <http://creativecommons.org/publicdomain/zero/1.0/>.
9f499134dSBaptiste Daroussin  */
10f499134dSBaptiste Daroussin 
11bce40c02SAlfonso S. Siciliano #include <bsddialog.h>
12f499134dSBaptiste Daroussin #include <stdio.h>
13f499134dSBaptiste Daroussin 
main()14f499134dSBaptiste Daroussin int main()
15f499134dSBaptiste Daroussin {
16f499134dSBaptiste Daroussin 	int i, output;
17f499134dSBaptiste Daroussin 	struct bsddialog_conf conf;
18f499134dSBaptiste Daroussin 	struct bsddialog_menuitem items[5] = {
19263660c0SAlfonso Siciliano 	    {"i",   true,  0, "Name 1", "Desc 1", "Bottom Desc 1"},
20263660c0SAlfonso Siciliano 	    {"ii",  false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
21263660c0SAlfonso Siciliano 	    {"iii", true,  0, "Name 3", "Desc 3", "Bottom Desc 3"},
22263660c0SAlfonso Siciliano 	    {"iv",  false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
23263660c0SAlfonso Siciliano 	    {"v",   true,  0, "Name 5", "Desc 5", "Bottom Desc 5"}
24f499134dSBaptiste Daroussin 	};
25f499134dSBaptiste Daroussin 
26263660c0SAlfonso Siciliano 	if (bsddialog_init() == BSDDIALOG_ERROR) {
27263660c0SAlfonso Siciliano 		printf("Error: %s\n", bsddialog_geterror());
28263660c0SAlfonso Siciliano 		return (1);
29263660c0SAlfonso Siciliano 	}
30f499134dSBaptiste Daroussin 	bsddialog_initconf(&conf);
31f499134dSBaptiste Daroussin 	conf.title = "checklist";
32263660c0SAlfonso Siciliano 	output = bsddialog_checklist(&conf, "Example", 15, 30, 5, 5, items,
33263660c0SAlfonso Siciliano 	    NULL);
34f499134dSBaptiste Daroussin 	bsddialog_end();
35263660c0SAlfonso Siciliano 	if (output == BSDDIALOG_ERROR) {
36263660c0SAlfonso Siciliano 		printf("Error: %s\n", bsddialog_geterror());
37263660c0SAlfonso Siciliano 		return (1);
38263660c0SAlfonso Siciliano 	}
39263660c0SAlfonso Siciliano 
40f499134dSBaptiste Daroussin 	printf("Checklist:\n");
41f499134dSBaptiste Daroussin 	for (i = 0; i < 5; i++)
42f499134dSBaptiste Daroussin 		printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
43f499134dSBaptiste Daroussin 
44*61ba55bcSBaptiste Daroussin 	return (0);
45f499134dSBaptiste Daroussin }