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 <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15
sender(int fd)16 static void sender(int fd)
17 {
18 int i;
19
20 for (i = 1; i <= 10; i++) {
21 sleep(1);
22 dprintf(fd, "SEP\n");
23 dprintf(fd, "%d\n", i * 10);
24 dprintf(fd, "In Progress... [%d / 10]\n", i);
25 dprintf(fd, "SEP\n");
26 }
27 sleep(1);
28 dprintf(fd, "EOF\n");
29 }
30
main()31 int main()
32 {
33 int rv, fd[2];
34 struct bsddialog_conf conf;
35
36 /* add checks and sync */
37 pipe(fd);
38 if (fork() == 0) {
39 close(fd[0]);
40 sender(fd[1]);
41 exit (0);
42 }
43 close(fd[1]);
44
45 if (bsddialog_init() == BSDDIALOG_ERROR) {
46 printf("Error: %s\n", bsddialog_geterror());
47 return (1);
48 }
49 bsddialog_initconf(&conf);
50 conf.title = "gauge";
51 rv = bsddialog_gauge(&conf, "Example", 7, 30, 0, fd[0], "SEP", "EOF");
52 bsddialog_end();
53 if (rv == BSDDIALOG_ERROR)
54 printf("Error: %s\n", bsddialog_geterror());
55
56 return (0);
57 }