xref: /freebsd/contrib/bsddialog/examples_library/theme.c (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
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 #include <bsddialog_theme.h>
16 
17 int main()
18 {
19 	int output, focusitem;
20 	struct bsddialog_conf conf;
21 	enum bsddialog_default_theme theme;
22 	struct bsddialog_menuitem items[5] = {
23 		{"", false, 0, "Default", "dialog-like",
24 		    "BSDDIALOG_THEME_DEFAULT" },
25 		{"", false, 0, "Dialog", "dialog clone",
26 		    "BSDDIALOG_THEME_DIALOG" },
27 		{"", false, 0, "BSDDialog", "new theme",
28 		    "BSDDIALOG_THEME_BSDDIALOG" },
29 		{"", false, 0, "BlackWhite","black and white",
30 		    "BSDDIALOG_THEME_BLACKWHITE" },
31 		{"", false, 0, "Quit", "Exit", "Quit or Cancel to exit" }
32 	};
33 
34 	if (bsddialog_init() == BSDDIALOG_ERROR) {
35 		printf("Error: %s\n", bsddialog_geterror());
36 		return (1);
37 	}
38 
39 	bsddialog_initconf(&conf);
40 
41 	bsddialog_backtitle(&conf, "Theme Example");
42 
43 	conf.title = " Theme ";
44 	focusitem = -1;
45 	while (true) {
46 		output = bsddialog_menu(&conf, "Choose theme", 15, 40, 5, 5,
47 		    items, &focusitem);
48 
49 		if (output != BSDDIALOG_OK || items[4].on)
50 			break;
51 
52 		if (items[0].on) {
53 			theme = BSDDIALOG_THEME_DEFAULT;
54 			focusitem = 0;
55 		}
56 		else if (items[1].on) {
57 			theme = BSDDIALOG_THEME_DIALOG;
58 			focusitem = 1;
59 		}
60 		else if (items[2].on) {
61 			theme = BSDDIALOG_THEME_BSDDIALOG;
62 			focusitem = 2;
63 		}
64 		else if (items[3].on) {
65 			theme = BSDDIALOG_THEME_BLACKWHITE;
66 			focusitem = 3;
67 		}
68 
69 		bsddialog_set_default_theme(theme);
70 	}
71 
72 	bsddialog_end();
73 
74 	return (output);
75 }