xref: /freebsd/contrib/bsddialog/examples_library/timebox.c (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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 <time.h>
14 
15 int main()
16 {
17 	int output;
18 	unsigned int hh, mm, ss;
19 	struct bsddialog_conf conf;
20 	time_t clock;
21 	struct tm *localtm;
22 
23 	time(&clock);
24 	localtm = localtime(&clock);
25 	hh = localtm->tm_hour;
26 	mm = localtm->tm_min;
27 	ss = localtm->tm_sec;
28 
29 	if (bsddialog_init() == BSDDIALOG_ERROR) {
30 		printf("Error: %s\n", bsddialog_geterror());
31 		return (1);
32 	}
33 	bsddialog_initconf(&conf);
34 	conf.title = "timebox";
35 	output = bsddialog_timebox(&conf, "Example", 9, 35, &hh, &mm, &ss);
36 	bsddialog_end();
37 	if (output == BSDDIALOG_ERROR) {
38 		printf("Error: %s\n", bsddialog_geterror());
39 		return (1);
40 	}
41 	printf("Time: %u:%u:%u\n", hh, mm, ss);
42 
43 	return (0);
44 }