forked from vbauerster/mpb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
57 lines (49 loc) · 1.29 KB
/
example_test.go
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
package mpb_test
import (
"math/rand"
"time"
"github.com/vbauerster/mpb"
"github.com/vbauerster/mpb/decor"
)
func Example() {
p := mpb.New(
// override default (80) width
mpb.WithWidth(100),
// override default "[=>-]" format
mpb.WithFormat("╢▌▌░╟"),
// override default 100ms refresh rate
mpb.WithRefreshRate(120*time.Millisecond),
)
total := 100
name := "Single Bar:"
// Add a bar
// You're not limited to just a single bar, add as many as you need
bar := p.AddBar(int64(total),
// Prepending decorators
mpb.PrependDecorators(
// StaticName decorator with minWidth and no extra config
// If you need to change name while rendering, use DynamicName
decor.StaticName(name, len(name), 0),
// ETA decorator with minWidth and no extra config
decor.ETA(4, 0),
),
// Appending decorators
mpb.AppendDecorators(
// Percentage decorator with minWidth and no extra config
decor.Percentage(5, 0),
),
)
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
bar.Increment()
}
p.Stop()
}
func ExampleBar_InProgress() {
p := mpb.New()
bar := p.AddBar(100, mpb.AppendDecorators(decor.Percentage(5, 0)))
for bar.InProgress() {
time.Sleep(time.Duration(rand.Intn(10)+1) * time.Second / 100)
bar.Increment()
}
}