package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb"
"github.com/vbauerster/mpb/decor"
)
func main() {
p := mpb.New()
total := 100
numBars := 3
var wg sync.WaitGroup
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
// Name decorator with minWidth and no width sync options
decor.Name(name, len(name), 0),
// Percentage decorator with minWidth and width sync options DwidthSync|DextraSpace
decor.Percentage(3, decor.DSyncSpace),
),
mpb.AppendDecorators(
// ETA decorator, with no width sync
decor.ETA(2, 0),
),
)
go func() {
defer wg.Done()
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(100)) * time.Millisecond)
bar.Incr(1)
}
}()
}
wg.Wait() // Wait for goroutines to finish
p.Stop() // Stop mpb's rendering goroutine
}