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