Codebase list golang-github-vbauerster-mpb / 8609301
refactor: examples update to use p.New() Vladimir Bauer 9 years ago
12 changed file(s) with 26 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
1818 var wg sync.WaitGroup
1919 ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
2020 defer cancel()
21 p := mpb.New(ctx).SetWidth(64)
21 p := mpb.New().SetWidth(64).WithContext(ctx)
2222
2323 name1 := "Bar#1:"
2424 bar1 := p.AddBar(50).
1818 url2 := "https://homebrew.bintray.com/bottles/libtiff-4.0.7.sierra.bottle.tar.gz"
1919
2020 var wg sync.WaitGroup
21 p := mpb.New(nil).SetWidth(60)
21 p := mpb.New().SetWidth(60)
2222
2323 for i, url := range [...]string{url1, url2} {
2424 wg.Add(1)
3434 }
3535 defer dest.Close()
3636
37 p := mpb.New(nil).SetWidth(64)
37 p := mpb.New().SetWidth(64)
3838
3939 bar := p.AddBar(size).
4040 PrependCounters("%3s / %3s", mpb.UnitBytes, 18, 0).
1515 func main() {
1616
1717 var wg sync.WaitGroup
18 p := mpb.New(nil).SetWidth(64)
19 // p := mpb.New(nil).RefreshRate(80 * time.Millisecond).SetWidth(64)
18 p := mpb.New().SetWidth(64)
2019
2120 name1 := "Bar#1:"
2221 bar1 := p.AddBar(50).
1515 func main() {
1616
1717 var wg sync.WaitGroup
18 p := mpb.New(nil).SetWidth(64)
19 // p := mpb.New(nil).RefreshRate(80 * time.Millisecond).SetWidth(64)
18 p := mpb.New().SetWidth(64)
2019
2120 name1 := "Bar#1:"
2221 bar1 := p.AddBar(50).
1515 func main() {
1616
1717 var wg sync.WaitGroup
18 p := mpb.New(nil).SetWidth(64)
19 // p := mpb.New(nil).RefreshRate(100 * time.Millisecond).SetWidth(64)
18 p := mpb.New().SetWidth(64)
2019
2120 name1 := "Bar#1:"
2221 bar1 := p.AddBar(50).
1010
1111 func main() {
1212 var wg sync.WaitGroup
13 p := mpb.New(nil)
13 p := mpb.New()
1414 wg.Add(3) // add wg delta
1515 for i := 0; i < 3; i++ {
1616 name := fmt.Sprintf("Bar#%d:", i)
3030 }
3131 wg.Wait() // Wait for goroutines to finish
3232 p.Stop() // Stop mpb's rendering goroutine
33 // p.AddBar(1) // panic: you cannot reuse p, create new one!
34 fmt.Println("finish")
3533 }
88
99 func main() {
1010 // Star mpb's rendering goroutine.
11 // If you don't plan to cancel, feed with nil
12 // otherwise provide context.Context, see cancel example
13 p := mpb.New(nil)
14 // Set custom width for every bar, which mpb will contain
11 p := mpb.New()
12 // Set custom width for every bar, which mpb will render
1513 // The default one in 70
1614 p.SetWidth(80)
1715 // Set custom format for every bar, the default one is "[=>-]"
4343 func main() {
4444
4545 var wg sync.WaitGroup
46 p := mpb.New(nil).SetWidth(60).BeforeRenderFunc(sortByProgressFunc())
46 p := mpb.New().SetWidth(60).BeforeRenderFunc(sortByProgressFunc())
4747
4848 name1 := "Bar#1:"
4949 bar1 := p.AddBar(100).
1616 func main() {
1717
1818 var wg sync.WaitGroup
19 p := mpb.New(nil)
19 p := mpb.New()
2020 wg.Add(totalBars)
2121
2222 for i := 0; i < totalBars; i++ {
33 "fmt"
44 "math/rand"
55 "time"
6 "unicode/utf8"
67
78 "github.com/vbauerster/mpb"
89 )
1112 // Star mpb's rendering goroutine.
1213 // If you don't plan to cancel, feed with nil
1314 // otherwise provide context.Context, see cancel example
14 p := mpb.New(nil)
15 p := mpb.New()
1516 // Set custom width for every bar, which mpb will contain
1617 // The default one in 70
1718 p.SetWidth(80)
3839 }
3940
4041 func ExampleBar_InProgress() {
41 p := mpb.New(nil)
42 p := mpb.New()
4243 bar := p.AddBar(100).AppendPercentage(5, 0)
4344
4445 for bar.InProgress() {
4950
5051 func ExampleBar_PrependFunc() {
5152 decor := func(s *mpb.Statistics, myWidth chan<- int, maxWidth <-chan int) string {
52 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
53 return fmt.Sprintf("%8s", str)
53 str := fmt.Sprintf("%3d/%3d", s.Current, s.Total)
54 myWidth <- utf8.RuneCountInString(str)
55 max := <-maxWidth
56 return fmt.Sprintf(fmt.Sprintf("%%%ds", max+1), str)
5457 }
5558
5659 totalItem := 100
57 p := mpb.New(nil)
60 p := mpb.New()
5861 bar := p.AddBar(int64(totalItem)).PrependFunc(decor)
5962
6063 for i := 0; i < totalItem; i++ {
6568
6669 func ExampleBar_AppendFunc() {
6770 decor := func(s *mpb.Statistics, myWidth chan<- int, maxWidth <-chan int) string {
68 str := fmt.Sprintf("%d/%d", s.Current, s.Total)
69 return fmt.Sprintf("%8s", str)
71 str := fmt.Sprintf("%3d/%3d", s.Current, s.Total)
72 myWidth <- utf8.RuneCountInString(str)
73 max := <-maxWidth
74 return fmt.Sprintf(fmt.Sprintf("%%%ds", max+1), str)
7075 }
7176
7277 totalItem := 100
73 p := mpb.New(nil)
78 p := mpb.New()
7479 bar := p.AddBar(int64(totalItem)).AppendFunc(decor)
7580
7681 for i := 0; i < totalItem; i++ {
66
77 func TestAddBar(t *testing.T) {
88 var buf bytes.Buffer
9 p := New(nil).SetWidth(60).SetOut(&buf)
9 p := New().SetWidth(60).SetOut(&buf)
1010 count := p.BarCount()
1111 if count != 0 {
1212 t.Errorf("Count want: %q, got: %q\n", 0, count)
2323 }
2424
2525 func TestRemoveBar(t *testing.T) {
26 p := New(nil)
26 p := New()
2727 b := p.AddBar(10)
2828
2929 if !p.RemoveBar(b) {