mexicanBar example
Vladimir Bauer
5 years ago
|
0 |
module github.com/vbauerster/mpb/_examples/mexicanBar
|
|
1 |
|
|
2 |
go 1.14
|
|
3 |
|
|
4 |
require github.com/vbauerster/mpb/v7 v7.0.0
|
|
0 |
package main
|
|
1 |
|
|
2 |
import (
|
|
3 |
"math/rand"
|
|
4 |
"time"
|
|
5 |
|
|
6 |
"github.com/vbauerster/mpb/v6"
|
|
7 |
"github.com/vbauerster/mpb/v6/decor"
|
|
8 |
)
|
|
9 |
|
|
10 |
func main() {
|
|
11 |
// initialize progress container, with custom width
|
|
12 |
p := mpb.New(mpb.WithWidth(80))
|
|
13 |
|
|
14 |
total := 100
|
|
15 |
name := "Complex Filler:"
|
|
16 |
bs := mpb.BarStyle()
|
|
17 |
bs.Lbound("[\u001b[36;1m")
|
|
18 |
bs.Filler("_")
|
|
19 |
bs.Tip("\u001b[0m⛵\u001b[36;1m")
|
|
20 |
bs.Padding("_")
|
|
21 |
bs.Rbound("\u001b[0m]")
|
|
22 |
bar := p.Add(int64(total),
|
|
23 |
mpb.NewBarFiller(bs),
|
|
24 |
mpb.PrependDecorators(decor.Name(name)),
|
|
25 |
mpb.AppendDecorators(decor.Percentage()),
|
|
26 |
)
|
|
27 |
// simulating some work
|
|
28 |
max := 100 * time.Millisecond
|
|
29 |
for i := 0; i < total; i++ {
|
|
30 |
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
|
|
31 |
bar.Increment()
|
|
32 |
}
|
|
33 |
// wait for our bar to complete
|
|
34 |
p.Wait()
|
|
35 |
}
|