Codebase list golang-github-vbauerster-mpb / 208a51c
spinTipBar example Vladimir Bauer 5 years ago
2 changed file(s) with 35 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 module github.com/vbauerster/mpb/_examples/spinTipBar
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 := "Single Bar:"
16 bar := p.Add(int64(total),
17 mpb.NewBarFiller(mpb.BarStyle().Tip(`-`, `\`, `|`, `/`)),
18 mpb.PrependDecorators(decor.Name(name)),
19 mpb.AppendDecorators(decor.Percentage()),
20 )
21 // simulating some work
22 max := 100 * time.Millisecond
23 for i := 0; i < total; i++ {
24 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
25 bar.Increment()
26 }
27 // wait for our bar to complete and flush
28 p.Wait()
29 }