aboutsummaryrefslogtreecommitdiff
path: root/contrib/bsddialog/examples_library/mixedgauge.c
blob: e74bb3512a9a18f19896915f02ff3d364f04a730 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*-
 * SPDX-License-Identifier: CC0-1.0
 *
 * Written in 2023 by Alfonso Sabato Siciliano.
 * To the extent possible under law, the author has dedicated all copyright
 * and related and neighboring rights to this software to the public domain
 * worldwide. This software is distributed without any warranty, see:
 *   <http://creativecommons.org/publicdomain/zero/1.0/>.
 */

#include <bsddialog.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#define NMINIBAR    13

static const char *minilabels[NMINIBAR] = {
	"Label   1",
	"Label   2",
	"Label   3",
	"Label   4",
	"Label   5",
	"Label   6",
	"Label   7",
	"Label   8",
	"Label   9",
	"Label  10",
	"Label  11",
	"Label   X",
	"Label   Y",
};

static int minipercs[NMINIBAR] = {
	BSDDIALOG_MG_SUCCEEDED,
	BSDDIALOG_MG_FAILED,
	BSDDIALOG_MG_PASSED,
	BSDDIALOG_MG_COMPLETED,
	BSDDIALOG_MG_CHECKED,
	BSDDIALOG_MG_DONE,
	BSDDIALOG_MG_SKIPPED,
	BSDDIALOG_MG_INPROGRESS,
	BSDDIALOG_MG_BLANK,
	BSDDIALOG_MG_NA,
	BSDDIALOG_MG_PENDING,
	67,
	0,
};

static void exit_error()
{
	if (bsddialog_inmode())
		bsddialog_end();
	printf("Error: %s\n", bsddialog_geterror());
	exit (1);
}

int main()
{
	int retval, i;
	struct bsddialog_conf conf;

	if (bsddialog_init() == BSDDIALOG_ERROR)
		exit_error();
	bsddialog_initconf(&conf);
	conf.title = "mixedgauge";
	for (i = 0; i <= 10; i++) {
		minipercs[11] += 3;
		minipercs[12] = i * 10;
		retval= bsddialog_mixedgauge(&conf, "Example", 20, 40,
		    50 + i * 5, NMINIBAR, minilabels, minipercs);
		if (retval == BSDDIALOG_ERROR)
			exit_error();
		sleep(1);
	}
	bsddialog_end();

	return (0);
}