xref: /freebsd/contrib/bsddialog/examples_library/theme.c (revision f499134dd403eeeba8283e2640e2654c8da62430)
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;
20 	struct bsddialog_conf conf;
21 	enum bsddialog_default_theme theme;
22 	struct bsddialog_menuitem items[5] = {
23 	    {"", false, 0, "Dialog",    "Current dialog theme",  "BSDDIALOG_THEME_DIALOG" },
24 	    {"", false, 0, "BSDDialog", "Future default theme",  "BSDDIALOG_THEME_DEFAULT"},
25 	    {"", false, 0, "BlackWhite","Black and White theme", "BSDDIALOG_THEME_BLACKWHITE"},
26 	    {"", false, 0, "Magenta",   "Testing",               "BSDDIALOG_THEME_MAGENTA"},
27 	    {"", false, 0, "Quit",      "Exit",                  "Quit or Cancel to exit" }
28 	};
29 
30 	bsddialog_initconf(&conf);
31 	conf.title = " Theme ";
32 
33 	if (bsddialog_init() == BSDDIALOG_ERROR)
34 		return BSDDIALOG_ERROR;
35 
36 	while (true) {
37 		bsddialog_backtitle(&conf, "Theme Example");
38 
39 		output = bsddialog_menu(&conf, "Choose theme", 15, 40, 5, 5, items, NULL);
40 
41 		if (output != BSDDIALOG_YESOK || items[4].on)
42 			break;
43 
44 		if (items[0].on) {
45 			theme = BSDDIALOG_THEME_DIALOG;
46 			conf.menu.default_item = items[0].name;
47 		}
48 		else if (items[1].on) {
49 			theme = BSDDIALOG_THEME_BSDDIALOG;
50 			conf.menu.default_item = items[1].name;
51 		}
52 		else if (items[2].on) {
53 			theme = BSDDIALOG_THEME_BLACKWHITE;
54 			conf.menu.default_item = items[2].name;
55 		}
56 		else if (items[3].on) {
57 			theme = BSDDIALOG_THEME_MAGENTA;
58 			conf.menu.default_item = items[3].name;
59 		}
60 
61 		bsddialog_set_default_theme(theme);
62 	}
63 
64 	bsddialog_end();
65 
66 	return output;
67 }
68