Path: blob/main/contrib/bsddialog/examples_library/gauge.c
39530 views
/*-1* SPDX-License-Identifier: CC0-1.02*3* Written in 2023 by Alfonso Sabato Siciliano.4* To the extent possible under law, the author has dedicated all copyright5* and related and neighboring rights to this software to the public domain6* worldwide. This software is distributed without any warranty, see:7* <http://creativecommons.org/publicdomain/zero/1.0/>.8*/910#include <bsddialog.h>11#include <stdio.h>12#include <stdlib.h>13#include <unistd.h>1415static void sender(int fd)16{17int i;1819for (i = 1; i <= 10; i++) {20sleep(1);21dprintf(fd, "SEP\n");22dprintf(fd, "%d\n", i * 10);23dprintf(fd, "In Progress... [%d / 10]\n", i);24dprintf(fd, "SEP\n");25}26sleep(1);27dprintf(fd, "EOF\n");28}2930int main()31{32int rv, fd[2];33struct bsddialog_conf conf;3435/* add checks and sync */36pipe(fd);37if (fork() == 0) {38close(fd[0]);39sender(fd[1]);40exit (0);41}42close(fd[1]);4344if (bsddialog_init() == BSDDIALOG_ERROR) {45printf("Error: %s\n", bsddialog_geterror());46return (1);47}48bsddialog_initconf(&conf);49conf.title = "gauge";50rv = bsddialog_gauge(&conf, "Example", 7, 30, 0, fd[0], "SEP", "EOF");51bsddialog_end();52if (rv == BSDDIALOG_ERROR)53printf("Error: %s\n", bsddialog_geterror());5455return (0);56}5758