-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest.c
109 lines (85 loc) · 2.45 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <progress.h>
#include <assert.h>
void
on_progress_start (progress_data_t *data);
void
on_progress (progress_data_t *data);
void
on_progress_end (progress_data_t *data);
int
main (void) {
// init with
progress_t *progress = progress_new(100, 60);
progress->fmt = " progress (:percent) => {:bar} [:elapsed]";
progress->bg_bar_char = " ";
progress->bar_char = ".";
// set events
progress_on(progress, PROGRESS_EVENT_START, on_progress_start);
progress_on(progress, PROGRESS_EVENT_PROGRESS, on_progress);
progress_on(progress, PROGRESS_EVENT_END, on_progress_end);
// tick progress
progress_tick(progress, 10);
sleep(1);
progress_tick(progress, 30);
progress_tick(progress, 5);
progress_tick(progress, 10);
progress_tick(progress, 20);
sleep(1);
progress_tick(progress, 10);
progress_tick(progress, 5);
progress_tick(progress, 10);
// inspect
progress_inspect(progress);
progress_free(progress);
progress = progress_new(100, 60);
progress->fmt = " progress (:percent) => {:bar} [:elapsed]";
progress->bg_bar_char = " ";
progress->bar_char = ".";
// set events
progress_on(progress, PROGRESS_EVENT_START, on_progress_start);
progress_on(progress, PROGRESS_EVENT_PROGRESS, on_progress);
progress_on(progress, PROGRESS_EVENT_END, on_progress_end);
// tick progress
progress_value(progress, 2);
sleep(1);
progress_value(progress, 5);
progress_value(progress, 10);
sleep(1);
progress_value(progress, 15);
progress_value(progress, 20);
sleep(1);
progress_value(progress, 30);
sleep(1);
progress_value(progress, 40);
sleep(1);
progress_value(progress, 100);
// inspect
progress_inspect(progress);
progress_free(progress);
progress = progress_new(100, 60);
progress->fmt = " progress (:percent) => {:bar} [:elapsed]";
progress->bg_bar_char = " ";
progress->bar_char = ".";
// set events
progress_on(progress, PROGRESS_EVENT_START, on_progress_start);
progress_on(progress, PROGRESS_EVENT_PROGRESS, on_progress);
progress_on(progress, PROGRESS_EVENT_END, on_progress_end);
for (long i = 0; i < 10000; ++i) {
progress_value(progress, i / 100);
}
progress_free(progress);
}
void
on_progress_start (progress_data_t *data) {
assert(data);
puts("\nprogress start");
progress_write(data->holder);
}
void
on_progress (progress_data_t *data) {
progress_write(data->holder);
}
void
on_progress_end (progress_data_t *data) {
puts("\nprogress end");
}