examples update
Vladimir Bauer
9 years ago
| 47 | 47 |
leftEnd: '[',
|
| 48 | 48 |
rightEnd: ']',
|
| 49 | 49 |
alpha: 0.25,
|
| 50 | |
// total: total,
|
| 51 | |
width: width,
|
|
50 |
width: width,
|
|
51 |
|
| 52 | 52 |
incrCh: make(chan int),
|
| 53 | 53 |
redrawReqCh: make(chan chan []byte),
|
| 54 | 54 |
currentReqCh: make(chan chan int),
|
| 19 | 19 |
}
|
| 20 | 20 |
|
| 21 | 21 |
p := mpb.New()
|
| 22 | |
p.Wg.Add(1)
|
| 23 | 22 |
bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor)
|
| 24 | 23 |
|
| 25 | 24 |
blockSize := rand.Intn(maxBlockSize) + 1
|
|
| 32 | 31 |
blockSize = rand.Intn(maxBlockSize) + 1
|
| 33 | 32 |
}
|
| 34 | 33 |
|
| 35 | |
p.WaitAndStop()
|
|
34 |
p.Stop()
|
| 36 | 35 |
fmt.Println("stop")
|
| 37 | 36 |
}
|
| 20 | 20 |
|
| 21 | 21 |
p := mpb.New()
|
| 22 | 22 |
bar := p.AddBar(totalItem).AppendETA().PrependFunc(decor)
|
| 23 | |
p.Wg.Add(1)
|
| 24 | 23 |
|
| 25 | 24 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 26 | 25 |
for i := 0; bar.InProgress(); i++ {
|
|
| 32 | 31 |
blockSize = rand.Intn(maxBlockSize) + 1
|
| 33 | 32 |
}
|
| 34 | 33 |
|
| 35 | |
p.WaitAndStop()
|
|
34 |
p.Stop()
|
| 36 | 35 |
fmt.Println("stop")
|
| 37 | 36 |
}
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"math/rand"
|
|
5 |
"sync"
|
| 5 | 6 |
"time"
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/vbauerster/mpb"
|
|
| 13 | 14 |
|
| 14 | 15 |
func main() {
|
| 15 | 16 |
|
|
17 |
var wg sync.WaitGroup
|
| 16 | 18 |
p := mpb.New().SetWidth(64)
|
| 17 | 19 |
// p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
|
| 18 | 20 |
|
| 19 | 21 |
name1 := "Bar#1:"
|
| 20 | 22 |
bar1 := p.AddBar(50).AppendPercentage().PrependETA(4).PrependName(name1, len(name1))
|
| 21 | |
p.Wg.Add(1)
|
|
23 |
wg.Add(1)
|
| 22 | 24 |
go func() {
|
|
25 |
defer wg.Done()
|
| 23 | 26 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 24 | 27 |
for i := 0; i < 50; i++ {
|
| 25 | 28 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 29 | 32 |
}()
|
| 30 | 33 |
|
| 31 | 34 |
bar2 := p.AddBar(100).AppendPercentage().PrependETA(4).PrependName("", 0-len(name1))
|
| 32 | |
p.Wg.Add(1)
|
|
35 |
wg.Add(1)
|
| 33 | 36 |
go func() {
|
|
37 |
defer wg.Done()
|
| 34 | 38 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 35 | 39 |
for i := 0; i < 100; i++ {
|
| 36 | 40 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 40 | 44 |
}()
|
| 41 | 45 |
|
| 42 | 46 |
bar3 := p.AddBar(80).AppendPercentage().PrependETA(4).PrependName("Bar#3:", 0)
|
| 43 | |
p.Wg.Add(1)
|
|
47 |
wg.Add(1)
|
| 44 | 48 |
go func() {
|
|
49 |
defer wg.Done()
|
| 45 | 50 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 46 | 51 |
for i := 0; i < 80; i++ {
|
| 47 | 52 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 50 | 55 |
}
|
| 51 | 56 |
}()
|
| 52 | 57 |
|
| 53 | |
// time.Sleep(time.Second)
|
| 54 | |
// p.RemoveBar(bar2)
|
| 55 | |
|
| 56 | |
p.WaitAndStop()
|
|
58 |
wg.Wait()
|
|
59 |
p.Stop()
|
| 57 | 60 |
fmt.Println("stop")
|
| 58 | 61 |
// p.AddBar(1) // panic: send on closed channnel
|
| 59 | 62 |
}
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"math/rand"
|
|
5 |
"sync"
|
| 5 | 6 |
"time"
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/vbauerster/mpb"
|
|
| 13 | 14 |
|
| 14 | 15 |
func main() {
|
| 15 | 16 |
|
|
17 |
var wg sync.WaitGroup
|
| 16 | 18 |
p := mpb.New().SetWidth(64)
|
| 17 | 19 |
// p := mpb.New().RefreshRate(80 * time.Millisecond).SetWidth(64)
|
| 18 | 20 |
|
| 19 | 21 |
name1 := "Bar#1:"
|
| 20 | 22 |
bar1 := p.AddBar(50).AppendPercentage().PrependElapsed(3).PrependName(name1, len(name1))
|
| 21 | |
p.Wg.Add(1)
|
|
23 |
wg.Add(1)
|
| 22 | 24 |
go func() {
|
|
25 |
defer wg.Done()
|
| 23 | 26 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 24 | 27 |
for i := 0; i < 50; i++ {
|
| 25 | 28 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 29 | 32 |
}()
|
| 30 | 33 |
|
| 31 | 34 |
bar2 := p.AddBar(100).AppendPercentage().PrependElapsed(3).PrependName("", 0-len(name1))
|
| 32 | |
p.Wg.Add(1)
|
|
35 |
wg.Add(1)
|
| 33 | 36 |
go func() {
|
|
37 |
defer wg.Done()
|
| 34 | 38 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 35 | 39 |
for i := 0; i < 100; i++ {
|
| 36 | 40 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 40 | 44 |
}()
|
| 41 | 45 |
|
| 42 | 46 |
bar3 := p.AddBar(80).AppendPercentage().PrependElapsed(3).PrependName("Bar#3:", 0)
|
| 43 | |
p.Wg.Add(1)
|
|
47 |
wg.Add(1)
|
| 44 | 48 |
go func() {
|
|
49 |
defer wg.Done()
|
| 45 | 50 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 46 | 51 |
for i := 0; i < 80; i++ {
|
| 47 | 52 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 50 | 55 |
}
|
| 51 | 56 |
}()
|
| 52 | 57 |
|
| 53 | |
// time.Sleep(time.Second)
|
| 54 | |
// p.RemoveBar(bar2)
|
| 55 | |
|
| 56 | |
p.WaitAndStop()
|
|
58 |
wg.Wait()
|
|
59 |
p.Stop()
|
| 57 | 60 |
fmt.Println("stop")
|
| 58 | 61 |
// p.AddBar(1) // panic: send on closed channnel
|
| 59 | 62 |
}
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"math/rand"
|
|
5 |
"sync"
|
| 5 | 6 |
"time"
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/vbauerster/mpb"
|
|
| 13 | 14 |
|
| 14 | 15 |
func main() {
|
| 15 | 16 |
|
|
17 |
var wg sync.WaitGroup
|
| 16 | 18 |
p := mpb.New().SetWidth(64)
|
| 17 | 19 |
// p := mpb.New().RefreshRate(100 * time.Millisecond).SetWidth(64)
|
| 18 | 20 |
|
| 19 | 21 |
name1 := "Bar#1:"
|
| 20 | 22 |
bar1 := p.AddBar(50).AppendETA().PrependPercentage(3).PrependName(name1, len(name1))
|
| 21 | |
p.Wg.Add(1)
|
|
23 |
wg.Add(1)
|
| 22 | 24 |
go func() {
|
|
25 |
defer wg.Done()
|
| 23 | 26 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 24 | 27 |
for i := 0; i < 50; i++ {
|
| 25 | 28 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 29 | 32 |
}()
|
| 30 | 33 |
|
| 31 | 34 |
bar2 := p.AddBar(100).AppendETA().PrependPercentage(3).PrependName("", 0-len(name1))
|
| 32 | |
p.Wg.Add(1)
|
|
35 |
wg.Add(1)
|
| 33 | 36 |
go func() {
|
|
37 |
defer wg.Done()
|
| 34 | 38 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 35 | 39 |
for i := 0; i < 100; i++ {
|
| 36 | 40 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 40 | 44 |
}()
|
| 41 | 45 |
|
| 42 | 46 |
bar3 := p.AddBar(80).AppendETA().PrependPercentage(3).PrependName("Bar#3:", 0)
|
| 43 | |
p.Wg.Add(1)
|
|
47 |
wg.Add(1)
|
| 44 | 48 |
go func() {
|
|
49 |
defer wg.Done()
|
| 45 | 50 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 46 | 51 |
for i := 0; i < 80; i++ {
|
| 47 | 52 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 51 | 56 |
}()
|
| 52 | 57 |
|
| 53 | 58 |
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
|
| 54 | 61 |
p.RemoveBar(bar2)
|
| 55 | 62 |
|
| 56 | |
p.WaitAndStop()
|
|
63 |
wg.Wait()
|
|
64 |
p.Stop()
|
| 57 | 65 |
fmt.Println("stop")
|
| 58 | 66 |
// p.AddBar(1) // panic: send on closed channnel
|
| 59 | 67 |
}
|
| 2 | 2 |
import (
|
| 3 | 3 |
"fmt"
|
| 4 | 4 |
"math/rand"
|
|
5 |
"sync"
|
| 5 | 6 |
"time"
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/vbauerster/mpb"
|
|
| 13 | 14 |
|
| 14 | 15 |
func main() {
|
| 15 | 16 |
|
|
17 |
var wg sync.WaitGroup
|
| 16 | 18 |
p := mpb.New().WithSort(mpb.SortTop).SetWidth(60)
|
| 17 | 19 |
|
| 18 | 20 |
name1 := "Bar#1:"
|
| 19 | 21 |
bar1 := p.AddBar(100).AppendETA().PrependFunc(getDecor()).PrependName(name1, len(name1))
|
| 20 | |
p.Wg.Add(1)
|
|
22 |
wg.Add(1)
|
| 21 | 23 |
go func() {
|
|
24 |
defer wg.Done()
|
| 22 | 25 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 23 | 26 |
for i := 0; i < 100; i++ {
|
| 24 | 27 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 28 | 31 |
}()
|
| 29 | 32 |
|
| 30 | 33 |
bar2 := p.AddBar(60).AppendETA().PrependFunc(getDecor()).PrependName("", 0-len(name1))
|
| 31 | |
p.Wg.Add(1)
|
|
34 |
wg.Add(1)
|
| 32 | 35 |
go func() {
|
|
36 |
defer wg.Done()
|
| 33 | 37 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 34 | 38 |
for i := 0; i < 60; i++ {
|
| 35 | 39 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 39 | 43 |
}()
|
| 40 | 44 |
|
| 41 | 45 |
bar3 := p.AddBar(80).AppendETA().PrependFunc(getDecor()).PrependName("Bar#3:", 0)
|
| 42 | |
p.Wg.Add(1)
|
|
46 |
wg.Add(1)
|
| 43 | 47 |
go func() {
|
|
48 |
defer wg.Done()
|
| 44 | 49 |
blockSize := rand.Intn(maxBlockSize) + 1
|
| 45 | 50 |
for i := 0; i < 80; i++ {
|
| 46 | 51 |
time.Sleep(time.Duration(blockSize) * (50*time.Millisecond + time.Duration(rand.Intn(5*int(time.Millisecond)))))
|
|
| 49 | 54 |
}
|
| 50 | 55 |
}()
|
| 51 | 56 |
|
| 52 | |
// time.Sleep(time.Second)
|
| 53 | |
// p.RemoveBar(bar2)
|
| 54 | |
|
| 55 | |
p.WaitAndStop()
|
|
57 |
wg.Wait()
|
|
58 |
p.Stop()
|
| 56 | 59 |
fmt.Println("stop")
|
| 57 | 60 |
// p.AddBar(1) // panic: send on closed channnel
|
| 58 | 61 |
}
|