Codebase list golang-github-vbauerster-mpb / add6c92
update sort example Vladimir Bauer 9 years ago
1 changed file(s) with 8 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1313
1414 func main() {
1515
16 p := mpb.New().RefreshRate(80 * time.Millisecond).WithSort(mpb.SortTop).SetWidth(60)
16 p := mpb.New().WithSort(mpb.SortTop).SetWidth(60)
1717
18 bar1 := p.AddBar(100).AppendETA().PrependFunc(getDecor("Bar#1"))
18 name1 := "Bar#1:"
19 bar1 := p.AddBar(100).AppendETA().PrependFunc(getDecor()).PrependName(name1, len(name1))
1920 go func() {
2021 blockSize := rand.Intn(maxBlockSize) + 1
2122 for i := 0; i < 100; i++ {
2526 }
2627 }()
2728
28 bar2 := p.AddBar(60).AppendETA().PrependFunc(getDecor("Bar#2"))
29 bar2 := p.AddBar(60).AppendETA().PrependFunc(getDecor()).PrependName("", 0-len(name1))
2930 go func() {
3031 blockSize := rand.Intn(maxBlockSize) + 1
3132 for i := 0; i < 60; i++ {
3536 }
3637 }()
3738
38 bar3 := p.AddBar(80).AppendETA().PrependFunc(getDecor("Bar#3"))
39 bar3 := p.AddBar(80).AppendETA().PrependFunc(getDecor()).PrependName("Bar#3:", 0)
3940 go func() {
4041 blockSize := rand.Intn(maxBlockSize) + 1
4142 for i := 0; i < 80; i++ {
4950 // p.RemoveBar(bar2)
5051
5152 p.WaitAndStop()
52 bar2.Incr(2)
5353 fmt.Println("stop")
5454 // p.AddBar(1) // panic: send on closed channnel
5555 }
5656
57 func getDecor(name string) mpb.DecoratorFunc {
57 func getDecor() mpb.DecoratorFunc {
5858 return func(s *mpb.Statistics) string {
59 str := fmt.Sprintf("%d/%d", s.Completed, s.Total)
60 return fmt.Sprintf("%s %-7s", name, str)
59 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
60 return fmt.Sprintf("%-7s", str)
6161 }
6262 }