diff --git a/example/simple/simple.go b/example/simple/simple.go index f4c39fd..00a58f2 100644 --- a/example/simple/simple.go +++ b/example/simple/simple.go @@ -3,29 +3,30 @@ import ( "fmt" "math/rand" - "runtime" "time" - "github.com/vbauerster/uiprogress" + "github.com/vbauerster/mpb" ) const ( totalItem = 100 - maxBlockSize = 12 + maxBlockSize = 10 ) func main() { - runtime.GOMAXPROCS(runtime.NumCPU()) - decor := func(s *uiprogress.Statistics) string { - str := fmt.Sprintf("%d/%d", s.Completed, s.Total) + decor := func(s *mpb.Statistics) string { + str := fmt.Sprintf("%d/%d", s.Current, s.Total) return fmt.Sprintf("%-7s", str) } - p := uiprogress.New() + p := mpb.New() bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor) + // if you omit the following line, bar rendering goroutine may not have a + // chance to coplete, thus better always use. + p.Wg.Add(1) blockSize := rand.Intn(maxBlockSize) + 1 - for i := 0; i < 100; i += 1 { + for i := 0; i < 100; i++ { time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond))))) bar.Incr(1) blockSize = rand.Intn(maxBlockSize) + 1