cctools
progress_bar.h
Go to the documentation of this file.
1/*
2Copyright (C) 2025 The University of Notre Dame
3This software is distributed under the GNU General Public License.
4See the file COPYING for details.
5*/
6
11#ifndef PROGRESS_BAR_H
12#define PROGRESS_BAR_H
13
14#include "list.h"
15#include "timestamp.h"
16#include <time.h>
17#include <stdint.h>
18
21 char *label;
22 uint64_t total;
23 uint64_t current;
24};
25
28 /* User-facing interval in seconds; internal comparisons use *_us. */
29 double update_interval_sec;
30 char *label;
31 struct list *parts;
32 /* Timestamps in microseconds. */
33 timestamp_t start_time_us;
34 timestamp_t last_draw_time_us;
35 timestamp_t update_interval_us;
36 int has_drawn_once;
37};
38
39/* Progress Bar Part API */
40
45struct ProgressBar *progress_bar_init(const char *label);
46
51void progress_bar_set_update_interval(struct ProgressBar *bar, double update_interval_sec);
52
58struct ProgressBarPart *progress_bar_create_part(const char *label, uint64_t total);
59
64void progress_bar_bind_part(struct ProgressBar *bar, struct ProgressBarPart *part);
65
71void progress_bar_set_part_total(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t new_total);
72
78void progress_bar_update_part(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t increment);
79
85
90
95
96#endif
Robust, reentrant linked list structure.
void progress_bar_set_update_interval(struct ProgressBar *bar, double update_interval_sec)
Set the update interval for the progress bar.
void progress_bar_update_part(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t increment)
Update the current value for a part, redraw if needed.
struct ProgressBar * progress_bar_init(const char *label)
Create a progress bar.
void progress_bar_bind_part(struct ProgressBar *bar, struct ProgressBarPart *part)
Bind a part to the progress bar.
void progress_bar_finish(struct ProgressBar *bar)
Finish the progress bar: draw once and print a newline.
void progress_bar_set_part_total(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t new_total)
Set the total for a part.
void progress_bar_set_start_time(struct ProgressBar *bar, timestamp_t start_time)
Set the start time for the progress bar.
void progress_bar_delete(struct ProgressBar *bar)
Delete the progress bar and free all parts.
struct ProgressBarPart * progress_bar_create_part(const char *label, uint64_t total)
Create a new part.
A part of a progress bar.
Definition progress_bar.h:20
Progress bar object.
Definition progress_bar.h:27
Portable routines for high resolution timing.
UINT64_T timestamp_t
A type to hold the current time, in microseconds since January 1st, 1970.
Definition timestamp.h:20