cctools
progress_bar.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2025 The University of Notre Dame
3 This software is distributed under the GNU General Public License.
4 See 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 
27 struct ProgressBar {
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 
45 struct ProgressBar *progress_bar_init(const char *label);
46 
51 void progress_bar_set_update_interval(struct ProgressBar *bar, double update_interval_sec);
52 
58 struct ProgressBarPart *progress_bar_create_part(const char *label, uint64_t total);
59 
64 void progress_bar_bind_part(struct ProgressBar *bar, struct ProgressBarPart *part);
65 
71 void progress_bar_set_part_total(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t new_total);
72 
78 void progress_bar_update_part(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t increment);
79 
84 void progress_bar_set_start_time(struct ProgressBar *bar, timestamp_t start_time);
85 
89 void progress_bar_finish(struct ProgressBar *bar);
90 
94 void progress_bar_delete(struct ProgressBar *bar);
95 
96 #endif
progress_bar_set_part_total
void progress_bar_set_part_total(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t new_total)
Set the total for a part.
ProgressBar
Progress bar object.
Definition: progress_bar.h:27
progress_bar_bind_part
void progress_bar_bind_part(struct ProgressBar *bar, struct ProgressBarPart *part)
Bind a part to the progress bar.
progress_bar_set_start_time
void progress_bar_set_start_time(struct ProgressBar *bar, timestamp_t start_time)
Set the start time for the progress bar.
progress_bar_delete
void progress_bar_delete(struct ProgressBar *bar)
Delete the progress bar and free all parts.
progress_bar_create_part
struct ProgressBarPart * progress_bar_create_part(const char *label, uint64_t total)
Create a new part.
timestamp_t
UINT64_T timestamp_t
A type to hold the current time, in microseconds since January 1st, 1970.
Definition: timestamp.h:20
progress_bar_update_part
void progress_bar_update_part(struct ProgressBar *bar, struct ProgressBarPart *part, uint64_t increment)
Update the current value for a part, redraw if needed.
progress_bar_finish
void progress_bar_finish(struct ProgressBar *bar)
Finish the progress bar: draw once and print a newline.
ProgressBarPart
A part of a progress bar.
Definition: progress_bar.h:20
list.h
progress_bar_init
struct ProgressBar * progress_bar_init(const char *label)
Create a progress bar.
timestamp.h
progress_bar_set_update_interval
void progress_bar_set_update_interval(struct ProgressBar *bar, double update_interval_sec)
Set the update interval for the progress bar.