Codebase list golang-github-vbauerster-mpb / 8bdb62a
examples update Vladimir Bauer 9 years ago
7 changed file(s) with 46 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
4747 leftEnd: '[',
4848 rightEnd: ']',
4949 alpha: 0.25,
50 // total: total,
51 width: width,
50 width: width,
51
5252 incrCh: make(chan int),
5353 redrawReqCh: make(chan chan []byte),
5454 currentReqCh: make(chan chan int),
1919 }
2020
2121 p := mpb.New()
22 p.Wg.Add(1)
2322 bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor)
2423
2524 blockSize := rand.Intn(maxBlockSize) + 1
3231 blockSize = rand.Intn(maxBlockSize) + 1
3332 }
3433
35 p.WaitAndStop()
34 p.Stop()
3635 fmt.Println("stop")
3736 }
2020
2121 p := mpb.New()
2222 bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor)
23 p.Wg.Add(1)
2423
2524 blockSize := rand.Intn(maxBlockSize) + 1
2625 for i := 0; bar.InProgress(); i++ {
3231 blockSize = rand.Intn(maxBlockSize) + 1
3332 }
3433
35 p.WaitAndStop()
34 p.Stop()
3635 fmt.Println("stop")
3736 }
22 import (
33 "fmt"
44 "math/rand"
5 "sync"
56 "time"
67
78 "github.com/vbauerster/mpb"
1314
1415 func main() {
1516
17 var wg sync.WaitGroup
1618 p := mpb.New().SetWidth(64)
1719 // p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
1820
1921 name1 := "Bar#1:"
2022 bar1 := p.AddBar(50).AppendPercentage().PrependETA(4).PrependName(name1, len(name1))
21 p.Wg.Add(1)
23 wg.Add(1)
2224 go func() {
25 defer wg.Done()
2326 blockSize := rand.Intn(maxBlockSize) + 1
2427 for i := 0; i < 50; i++ {
2528 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
2932 }()
3033
3134 bar2 := p.AddBar(100).AppendPercentage().PrependETA(4).PrependName("", 0-len(name1))
32 p.Wg.Add(1)
35 wg.Add(1)
3336 go func() {
37 defer wg.Done()
3438 blockSize := rand.Intn(maxBlockSize) + 1
3539 for i := 0; i < 100; i++ {
3640 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
4044 }()
4145
4246 bar3 := p.AddBar(80).AppendPercentage().PrependETA(4).PrependName("Bar#3:", 0)
43 p.Wg.Add(1)
47 wg.Add(1)
4448 go func() {
49 defer wg.Done()
4550 blockSize := rand.Intn(maxBlockSize) + 1
4651 for i := 0; i < 80; i++ {
4752 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
5055 }
5156 }()
5257
53 // time.Sleep(time.Second)
54 // p.RemoveBar(bar2)
55
56 p.WaitAndStop()
58 wg.Wait()
59 p.Stop()
5760 fmt.Println("stop")
5861 // p.AddBar(1) // panic: send on closed channnel
5962 }
22 import (
33 "fmt"
44 "math/rand"
5 "sync"
56 "time"
67
78 "github.com/vbauerster/mpb"
1314
1415 func main() {
1516
17 var wg sync.WaitGroup
1618 p := mpb.New().SetWidth(64)
1719 // p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
1820
1921 name1 := "Bar#1:"
2022 bar1 := p.AddBar(50).AppendPercentage().PrependElapsed(3).PrependName(name1, len(name1))
21 p.Wg.Add(1)
23 wg.Add(1)
2224 go func() {
25 defer wg.Done()
2326 blockSize := rand.Intn(maxBlockSize) + 1
2427 for i := 0; i < 50; i++ {
2528 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
2932 }()
3033
3134 bar2 := p.AddBar(100).AppendPercentage().PrependElapsed(3).PrependName("", 0-len(name1))
32 p.Wg.Add(1)
35 wg.Add(1)
3336 go func() {
37 defer wg.Done()
3438 blockSize := rand.Intn(maxBlockSize) + 1
3539 for i := 0; i < 100; i++ {
3640 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
4044 }()
4145
4246 bar3 := p.AddBar(80).AppendPercentage().PrependElapsed(3).PrependName("Bar#3:", 0)
43 p.Wg.Add(1)
47 wg.Add(1)
4448 go func() {
49 defer wg.Done()
4550 blockSize := rand.Intn(maxBlockSize) + 1
4651 for i := 0; i < 80; i++ {
4752 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
5055 }
5156 }()
5257
53 // time.Sleep(time.Second)
54 // p.RemoveBar(bar2)
55
56 p.WaitAndStop()
58 wg.Wait()
59 p.Stop()
5760 fmt.Println("stop")
5861 // p.AddBar(1) // panic: send on closed channnel
5962 }
22 import (
33 "fmt"
44 "math/rand"
5 "sync"
56 "time"
67
78 "github.com/vbauerster/mpb"
1314
1415 func main() {
1516
17 var wg sync.WaitGroup
1618 p := mpb.New().SetWidth(64)
1719 // p := mpb.New().RefreshRate(100 * time.Millisecond).SetWidth(64)
1820
1921 name1 := "Bar#1:"
2022 bar1 := p.AddBar(50).AppendETA().PrependPercentage(3).PrependName(name1, len(name1))
21 p.Wg.Add(1)
23 wg.Add(1)
2224 go func() {
25 defer wg.Done()
2326 blockSize := rand.Intn(maxBlockSize) + 1
2427 for i := 0; i < 50; i++ {
2528 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
2932 }()
3033
3134 bar2 := p.AddBar(100).AppendETA().PrependPercentage(3).PrependName("", 0-len(name1))
32 p.Wg.Add(1)
35 wg.Add(1)
3336 go func() {
37 defer wg.Done()
3438 blockSize := rand.Intn(maxBlockSize) + 1
3539 for i := 0; i < 100; i++ {
3640 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
4044 }()
4145
4246 bar3 := p.AddBar(80).AppendETA().PrependPercentage(3).PrependName("Bar#3:", 0)
43 p.Wg.Add(1)
47 wg.Add(1)
4448 go func() {
49 defer wg.Done()
4550 blockSize := rand.Intn(maxBlockSize) + 1
4651 for i := 0; i < 80; i++ {
4752 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
5156 }()
5257
5358 time.Sleep(3 * time.Second)
59 // After removing the bar, it is good practice to ask underlying goroutine
60 // (2nd one in our example) to stop, so its wg.Done() will execute in time
5461 p.RemoveBar(bar2)
5562
56 p.WaitAndStop()
63 wg.Wait()
64 p.Stop()
5765 fmt.Println("stop")
5866 // p.AddBar(1) // panic: send on closed channnel
5967 }
22 import (
33 "fmt"
44 "math/rand"
5 "sync"
56 "time"
67
78 "github.com/vbauerster/mpb"
1314
1415 func main() {
1516
17 var wg sync.WaitGroup
1618 p := mpb.New().WithSort(mpb.SortTop).SetWidth(60)
1719
1820 name1 := "Bar#1:"
1921 bar1 := p.AddBar(100).AppendETA().PrependFunc(getDecor()).PrependName(name1, len(name1))
20 p.Wg.Add(1)
22 wg.Add(1)
2123 go func() {
24 defer wg.Done()
2225 blockSize := rand.Intn(maxBlockSize) + 1
2326 for i := 0; i < 100; i++ {
2427 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
2831 }()
2932
3033 bar2 := p.AddBar(60).AppendETA().PrependFunc(getDecor()).PrependName("", 0-len(name1))
31 p.Wg.Add(1)
34 wg.Add(1)
3235 go func() {
36 defer wg.Done()
3337 blockSize := rand.Intn(maxBlockSize) + 1
3438 for i := 0; i < 60; i++ {
3539 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
3943 }()
4044
4145 bar3 := p.AddBar(80).AppendETA().PrependFunc(getDecor()).PrependName("Bar#3:", 0)
42 p.Wg.Add(1)
46 wg.Add(1)
4347 go func() {
48 defer wg.Done()
4449 blockSize := rand.Intn(maxBlockSize) + 1
4550 for i := 0; i < 80; i++ {
4651 time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
4954 }
5055 }()
5156
52 // time.Sleep(time.Second)
53 // p.RemoveBar(bar2)
54
55 p.WaitAndStop()
57 wg.Wait()
58 p.Stop()
5659 fmt.Println("stop")
5760 // p.AddBar(1) // panic: send on closed channnel
5861 }