package ProgressBar
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/vbauerster/mpb"
|
|
"github.com/vbauerster/mpb/decor"
|
|
)
|
|
|
|
var (
|
|
BarWG sync.WaitGroup
|
|
P = mpb.New(mpb.WithWaitGroup(&BarWG))
|
|
)
|
|
|
|
func InitBar(name string, total int) *mpb.Bar {
|
|
var (
|
|
bar *mpb.Bar
|
|
)
|
|
|
|
BarWG.Add(1)
|
|
|
|
bar = P.AddBar(int64(total),
|
|
mpb.PrependDecorators(
|
|
decor.Name(name),
|
|
decor.Percentage(decor.WCSyncSpace),
|
|
),
|
|
mpb.AppendDecorators(
|
|
// replace ETA decorator with "done" message, OnComplete event
|
|
decor.OnComplete(
|
|
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
|
|
),
|
|
),
|
|
)
|
|
|
|
return bar
|
|
}
|
|
|
|
func CloseBar(bar *mpb.Bar) {
|
|
bar.Abort(false)
|
|
BarWG.Done()
|
|
}
|