xref: /freebsd/contrib/bsddialog/examples_library/menu.c (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
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 #include <string.h>
14 
15 int main()
16 {
17 	int i, output;
18 	struct bsddialog_conf conf;
19 	struct bsddialog_menuitem items[5] = {
20 	    {"I",   true,  0, "Name 1", "Desc 1", "Bottom Desc 1"},
21 	    {"II",  false, 0, "Name 2", "Desc 2", "Bottom Desc 2"},
22 	    {"III", true,  0, "Name 3", "Desc 3", "Bottom Desc 3"},
23 	    {"IV",  false, 0, "Name 4", "Desc 4", "Bottom Desc 4"},
24 	    {"V",   true,  0, "Name 5", "Desc 5", "Bottom Desc 5"}
25 	};
26 
27 	if (bsddialog_init() == BSDDIALOG_ERROR) {
28 		printf("Error: %s\n", bsddialog_geterror());
29 		return (1);
30 	}
31 
32 	bsddialog_initconf(&conf);
33 	conf.title = "menu";
34 	output = bsddialog_menu(&conf, "Example", 15, 30, 5, 5, items, NULL);
35 
36 	bsddialog_end();
37 
38 	if (output == BSDDIALOG_ERROR) {
39 		printf("Error: %s\n", bsddialog_geterror());
40 		return (1);
41 	}
42 
43 	if (output == BSDDIALOG_CANCEL) {
44 		printf("Cancel\n");
45 		return (0);
46 	}
47 
48 	printf("Menu:\n");
49 	for (i = 0; i < 5; i++)
50 		printf(" [%c] %s\n", items[i].on ? 'X' : ' ', items[i].name);
51 
52 	return (output);
53 }