xref: /freebsd/contrib/bsddialog/examples_library/mixedgauge.c (revision d316de24faa7453118a90fb0e9839e8026e36a4e)
1 /*-
2  * SPDX-License-Identifier: CC0-1.0
3  *
4  * Written in 2023 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 <stdlib.h>
13 #include <stdio.h>
14 #include <unistd.h>
15 
16 #define NMINIBAR    13
17 
18 static const char *minilabels[NMINIBAR] = {
19 	"Label   1",
20 	"Label   2",
21 	"Label   3",
22 	"Label   4",
23 	"Label   5",
24 	"Label   6",
25 	"Label   7",
26 	"Label   8",
27 	"Label   9",
28 	"Label  10",
29 	"Label  11",
30 	"Label   X",
31 	"Label   Y",
32 };
33 
34 static int minipercs[NMINIBAR] = {
35 	BSDDIALOG_MG_SUCCEEDED,
36 	BSDDIALOG_MG_FAILED,
37 	BSDDIALOG_MG_PASSED,
38 	BSDDIALOG_MG_COMPLETED,
39 	BSDDIALOG_MG_CHECKED,
40 	BSDDIALOG_MG_DONE,
41 	BSDDIALOG_MG_SKIPPED,
42 	BSDDIALOG_MG_INPROGRESS,
43 	BSDDIALOG_MG_BLANK,
44 	BSDDIALOG_MG_NA,
45 	BSDDIALOG_MG_PENDING,
46 	67,
47 	0,
48 };
49 
50 static void exit_error()
51 {
52 	if (bsddialog_inmode())
53 		bsddialog_end();
54 	printf("Error: %s\n", bsddialog_geterror());
55 	exit (1);
56 }
57 
58 int main()
59 {
60 	int retval, i;
61 	struct bsddialog_conf conf;
62 
63 	if (bsddialog_init() == BSDDIALOG_ERROR)
64 		exit_error();
65 	bsddialog_initconf(&conf);
66 	conf.title = "mixedgauge";
67 	for (i = 0; i <= 10; i++) {
68 		minipercs[11] += 3;
69 		minipercs[12] = i * 10;
70 		retval= bsddialog_mixedgauge(&conf, "Example", 20, 40,
71 		    50 + i * 5, NMINIBAR, minilabels, minipercs);
72 		if (retval == BSDDIALOG_ERROR)
73 			exit_error();
74 		sleep(1);
75 	}
76 	bsddialog_end();
77 
78 	return (0);
79 }