Codebase list golang-github-vbauerster-mpb / 1b1be6a
simple example update Vladimir Bauer 9 years ago
1 changed file(s) with 9 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "fmt"
44 "math/rand"
5 "runtime"
65 "time"
76
8 "github.com/vbauerster/uiprogress"
7 "github.com/vbauerster/mpb"
98 )
109
1110 const (
1211 totalItem = 100
13 maxBlockSize = 12
12 maxBlockSize = 10
1413 )
1514
1615 func main() {
17 runtime.GOMAXPROCS(runtime.NumCPU())
18 decor := func(s *uiprogress.Statistics) string {
19 str := fmt.Sprintf("%d/%d", s.Completed, s.Total)
16 decor := func(s *mpb.Statistics) string {
17 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
2018 return fmt.Sprintf("%-7s", str)
2119 }
2220
23 p := uiprogress.New()
21 p := mpb.New()
2422 bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor)
23 // if you omit the following line, bar rendering goroutine may not have a
24 // chance to coplete, thus better always use.
25 p.Wg.Add(1)
2526
2627 blockSize := rand.Intn(maxBlockSize) + 1
27 for i := 0; i < 100; i += 1 {
28 for i := 0; i < 100; i++ {
2829 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
2930 bar.Incr(1)
3031 blockSize = rand.Intn(maxBlockSize) + 1