Codebase list golang-github-vbauerster-mpb / b1093d1
New upstream version 7.0.3 Reinhard Tartler 4 years ago
63 changed file(s) with 635 addition(s) and 388 deletion(s). Raw diff Collapse all Expand all
00 # Multi Progress Bar
11
2 [![GoDoc](https://pkg.go.dev/badge/github.com/vbauerster/mpb)](https://pkg.go.dev/github.com/vbauerster/mpb/v6)
2 [![GoDoc](https://pkg.go.dev/badge/github.com/vbauerster/mpb)](https://pkg.go.dev/github.com/vbauerster/mpb/v7)
33 [![Build Status](https://travis-ci.org/vbauerster/mpb.svg?branch=master)](https://travis-ci.org/vbauerster/mpb)
44 [![Go Report Card](https://goreportcard.com/badge/github.com/vbauerster/mpb)](https://goreportcard.com/report/github.com/vbauerster/mpb)
5 [![Donate with PayPal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/vbauerster)
56
67 **mpb** is a Go lib for rendering progress bars in terminal applications.
78
2526 "math/rand"
2627 "time"
2728
28 "github.com/vbauerster/mpb/v6"
29 "github.com/vbauerster/mpb/v6/decor"
29 "github.com/vbauerster/mpb/v7"
30 "github.com/vbauerster/mpb/v7/decor"
3031 )
3132
3233 func main() {
3839 // adding a single bar, which will inherit container's width
3940 bar := p.Add(int64(total),
4041 // progress bar filler with customized style
41 mpb.NewBarFiller("╢▌▌░╟"),
42 mpb.NewBarFiller(mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟")),
4243 mpb.PrependDecorators(
4344 // display our name with one space on the right
4445 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
6465
6566 ```go
6667 var wg sync.WaitGroup
67 // pass &wg (optional), so p will wait for it eventually
68 // passed &wg will be accounted at p.Wait() call
6869 p := mpb.New(mpb.WithWaitGroup(&wg))
6970 total, numBars := 100, 3
7071 wg.Add(numBars)
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v6"
10 "github.com/vbauerster/mpb/v6/decor"
9 "github.com/vbauerster/mpb/v7"
10 "github.com/vbauerster/mpb/v7/decor"
1111 )
1212
1313 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v6"
10 "github.com/vbauerster/mpb/v6/decor"
9 "github.com/vbauerster/mpb/v7"
10 "github.com/vbauerster/mpb/v7/decor"
1111 )
1212
1313 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func init() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
44 "math/rand"
55 "time"
66
7 "github.com/vbauerster/mpb/v6"
8 "github.com/vbauerster/mpb/v6/decor"
7 "github.com/vbauerster/mpb/v7"
8 "github.com/vbauerster/mpb/v7/decor"
99 )
1010
1111 func main() {
2323 decor.AverageETA(decor.ET_STYLE_GO), "done",
2424 ),
2525 ),
26 mpb.BarExtender(nlBarFiller(mpb.NewBarFiller("╢▌▌░╟"))),
26 mpb.BarExtender(nlBarFiller(mpb.NewBarFiller(mpb.BarStyle()))),
2727 )
2828 // simulating some work
2929 max := 100 * time.Millisecond
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
44 "math/rand"
55 "time"
66
7 "github.com/vbauerster/mpb/v6"
8 "github.com/vbauerster/mpb/v6/decor"
7 "github.com/vbauerster/mpb/v7"
8 "github.com/vbauerster/mpb/v7/decor"
99 )
1010
1111 func init() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "io/ioutil"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
1919 )
2020
2121 bar := p.Add(total,
22 mpb.NewBarFiller("[=>-|"),
22 mpb.NewBarFiller(mpb.BarStyle().Rbound("|")),
2323 mpb.PrependDecorators(
2424 decor.CountersKibiByte("% .2f / % .2f"),
2525 ),
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
0 module github.com/vbauerster/mpb/_examples/mexicanBar
1
2 go 1.14
3
4 require github.com/vbauerster/mpb/v7 v7.0.3
0 package main
1
2 import (
3 "math/rand"
4 "time"
5
6 "github.com/vbauerster/mpb/v7"
7 "github.com/vbauerster/mpb/v7/decor"
8 )
9
10 func main() {
11 // initialize progress container, with custom width
12 p := mpb.New(mpb.WithWidth(80))
13
14 total := 100
15 name := "Complex Filler:"
16 bs := mpb.BarStyle()
17 bs.Lbound("[\u001b[36;1m")
18 bs.Filler("_")
19 bs.Tip("\u001b[0m⛵\u001b[36;1m")
20 bs.Padding("_")
21 bs.Rbound("\u001b[0m]")
22 bar := p.Add(int64(total),
23 mpb.NewBarFiller(bs),
24 mpb.PrependDecorators(decor.Name(name)),
25 mpb.AppendDecorators(decor.Percentage()),
26 )
27 // simulating some work
28 max := 100 * time.Millisecond
29 for i := 0; i < total; i++ {
30 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
31 bar.Increment()
32 }
33 // wait for our bar to complete
34 p.Wait()
35 }
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
1313 var wg sync.WaitGroup
14 // pass &wg (optional), so p will wait for it eventually
14 // passed &wg will be accounted at p.Wait() call
1515 p := mpb.New(mpb.WithWaitGroup(&wg))
1616 total, numBars := 100, 3
1717 wg.Add(numBars)
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v6"
10 "github.com/vbauerster/mpb/v6/decor"
9 "github.com/vbauerster/mpb/v7"
10 "github.com/vbauerster/mpb/v7/decor"
1111 )
1212
1313 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
44 "math/rand"
55 "time"
66
7 "github.com/vbauerster/mpb/v6"
8 "github.com/vbauerster/mpb/v6/decor"
7 "github.com/vbauerster/mpb/v7"
8 "github.com/vbauerster/mpb/v7/decor"
99 )
1010
1111 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
66 "sync"
77 "time"
88
9 "github.com/vbauerster/mpb/v6"
10 "github.com/vbauerster/mpb/v6/decor"
9 "github.com/vbauerster/mpb/v7"
10 "github.com/vbauerster/mpb/v7/decor"
1111 )
1212
1313 var quietMode bool
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
1818
1919 for i := 0; i < numBars; i++ {
2020 name := fmt.Sprintf("Bar#%d:", i)
21 bs := mpb.BarStyle()
22 if i == 1 {
23 // reverse Bar#1
24 bs = bs.Tip("<").Reverse()
25 }
2126 bar := p.Add(int64(total),
22 // reverse Bar#1
23 mpb.NewBarFillerPick("", i == 1),
27 mpb.NewBarFiller(bs),
2428 mpb.PrependDecorators(
2529 // simple name decorator
2630 decor.Name(name),
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
33 "math/rand"
44 "time"
55
6 "github.com/vbauerster/mpb/v6"
7 "github.com/vbauerster/mpb/v6/decor"
6 "github.com/vbauerster/mpb/v7"
7 "github.com/vbauerster/mpb/v7/decor"
88 )
99
1010 func main() {
1616 // adding a single bar, which will inherit container's width
1717 bar := p.Add(int64(total),
1818 // progress bar filler with customized style
19 mpb.NewBarFiller("╢▌▌░╟"),
19 mpb.NewBarFiller(mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟")),
2020 mpb.PrependDecorators(
2121 // display our name with one space on the right
2222 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
0 module github.com/vbauerster/mpb/_examples/spinTipBar
1
2 go 1.14
3
4 require github.com/vbauerster/mpb/v7 v7.0.3
0 package main
1
2 import (
3 "math/rand"
4 "time"
5
6 "github.com/vbauerster/mpb/v7"
7 "github.com/vbauerster/mpb/v7/decor"
8 )
9
10 func main() {
11 // initialize progress container, with custom width
12 p := mpb.New(mpb.WithWidth(80))
13
14 total := 100
15 name := "Single Bar:"
16 bar := p.Add(int64(total),
17 mpb.NewBarFiller(mpb.BarStyle().Tip(`-`, `\`, `|`, `/`)),
18 mpb.PrependDecorators(decor.Name(name)),
19 mpb.AppendDecorators(decor.Percentage()),
20 )
21 // simulating some work
22 max := 100 * time.Millisecond
23 for i := 0; i < total; i++ {
24 time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
25 bar.Increment()
26 }
27 // wait for our bar to complete and flush
28 p.Wait()
29 }
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
2525 var bar *mpb.Bar
2626 if i == 0 {
2727 bar = p.Add(int64(total),
28 mpb.NewBarFiller("╢▌▌░╟"),
28 mpb.NewBarFiller(mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟")),
2929 mpb.PrependDecorators(
3030 // simple name decorator
3131 decor.Name(name),
4040 )
4141 } else {
4242 bar = p.Add(int64(total),
43 mpb.NewSpinnerFiller(spinnerStyle, mpb.SpinnerOnMiddle),
43 mpb.NewBarFiller(mpb.SpinnerStyle(spinnerStyle...)),
4444 mpb.PrependDecorators(
4545 // simple name decorator
4646 decor.Name(name),
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 func main() {
11
22 go 1.14
33
4 require github.com/vbauerster/mpb/v6 v6.0.3
4 require github.com/vbauerster/mpb/v7 v7.0.3
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v7"
9 "github.com/vbauerster/mpb/v7/decor"
1010 )
1111
1212 const (
22 go 1.14
33
44 require (
5 github.com/mattn/go-runewidth v0.0.10
6 github.com/vbauerster/mpb/v6 v6.0.3
5 github.com/mattn/go-runewidth v0.0.13
6 github.com/vbauerster/mpb/v7 v7.0.3
77 )
88 "time"
99
1010 "github.com/mattn/go-runewidth"
11 "github.com/vbauerster/mpb/v6"
12 "github.com/vbauerster/mpb/v6/decor"
11 "github.com/vbauerster/mpb/v7"
12 "github.com/vbauerster/mpb/v7/decor"
1313 )
1414
1515 func main() {
1111
1212 "github.com/acarl005/stripansi"
1313 "github.com/mattn/go-runewidth"
14 "github.com/vbauerster/mpb/v6/decor"
14 "github.com/vbauerster/mpb/v7/decor"
1515 )
1616
1717 // Bar represents a progress bar.
389389 }
390390
391391 func (s *bState) draw(stat decor.Statistics) io.Reader {
392 if !s.trimSpace {
393 stat.AvailableWidth -= 2
394 s.bufB.WriteByte(' ')
395 defer s.bufB.WriteByte(' ')
396 }
397
398392 nlr := strings.NewReader("\n")
399393 tw := stat.AvailableWidth
400394 for _, d := range s.pDecorators {
402396 stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
403397 s.bufP.WriteString(str)
404398 }
405 if stat.AvailableWidth <= 0 {
399 if stat.AvailableWidth < 1 {
406400 trunc := strings.NewReader(runewidth.Truncate(stripansi.Strip(s.bufP.String()), tw, "…"))
407401 s.bufP.Reset()
408 return io.MultiReader(trunc, s.bufB, nlr)
402 return io.MultiReader(trunc, nlr)
403 }
404
405 if !s.trimSpace && stat.AvailableWidth > 1 {
406 stat.AvailableWidth -= 2
407 s.bufB.WriteByte(' ')
408 defer s.bufB.WriteByte(' ')
409409 }
410410
411411 tw = stat.AvailableWidth
414414 stat.AvailableWidth -= runewidth.StringWidth(stripansi.Strip(str))
415415 s.bufA.WriteString(str)
416416 }
417 if stat.AvailableWidth <= 0 {
417 if stat.AvailableWidth < 1 {
418418 trunc := strings.NewReader(runewidth.Truncate(stripansi.Strip(s.bufA.String()), tw, "…"))
419419 s.bufA.Reset()
420420 return io.MultiReader(s.bufP, s.bufB, trunc, nlr)
22 import (
33 "io"
44
5 "github.com/vbauerster/mpb/v6/decor"
5 "github.com/vbauerster/mpb/v7/decor"
66 )
77
88 // BarFiller interface.
1313 //
1414 // Default implementations can be obtained via:
1515 //
16 // func NewBarFiller(style string) BarFiller
17 // func NewBarFillerRev(style string) BarFiller
18 // func NewBarFillerPick(style string, rev bool) BarFiller
19 // func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller
16 // func NewBarFiller(BarStyle()) BarFiller
17 // func NewBarFiller(SpinnerStyle()) BarFiller
2018 //
2119 type BarFiller interface {
2220 Fill(w io.Writer, reqWidth int, stat decor.Statistics)
21 }
22
23 // BarFillerBuilder interface.
24 type BarFillerBuilder interface {
25 Build() BarFiller
2326 }
2427
2528 // BarFillerFunc is function type adapter to convert function into BarFiller.
2831 func (f BarFillerFunc) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
2932 f(w, reqWidth, stat)
3033 }
34
35 // NewBarFiller constructs a BarFiller from provided BarFillerBuilder.
36 func NewBarFiller(b BarFillerBuilder) BarFiller {
37 return b.Build()
38 }
00 package mpb
11
22 import (
3 "bytes"
43 "io"
5 "unicode/utf8"
6
4
5 "github.com/acarl005/stripansi"
76 "github.com/mattn/go-runewidth"
8 "github.com/rivo/uniseg"
9 "github.com/vbauerster/mpb/v6/decor"
10 "github.com/vbauerster/mpb/v6/internal"
7 "github.com/vbauerster/mpb/v7/decor"
8 "github.com/vbauerster/mpb/v7/internal"
119 )
1210
1311 const (
14 rLeft = iota
15 rFill
16 rTip
17 rSpace
18 rRight
19 rRevTip
20 rRefill
12 iLbound = iota
13 iRbound
14 iFiller
15 iRefiller
16 iPadding
17 components
2118 )
2219
23 // BarDefaultStyle is a style for rendering a progress bar.
24 // It consist of 7 ordered runes:
25 //
26 // '1st rune' stands for left boundary rune
27 //
28 // '2nd rune' stands for fill rune
29 //
30 // '3rd rune' stands for tip rune
31 //
32 // '4th rune' stands for space rune
33 //
34 // '5th rune' stands for right boundary rune
35 //
36 // '6th rune' stands for reverse tip rune
37 //
38 // '7th rune' stands for refill rune
39 //
40 const BarDefaultStyle string = "[=>-]<+"
41
42 type barFiller struct {
43 format [][]byte
44 rwidth []int
45 tip []byte
46 refill int64
47 reverse bool
48 flush func(io.Writer, *space, [][]byte)
49 }
50
51 type space struct {
52 space []byte
53 rwidth int
54 count int
55 }
56
57 // NewBarFiller returns a BarFiller implementation which renders a
58 // progress bar in regular direction. If style is empty string,
59 // BarDefaultStyle is applied. To be used with `*Progress.Add(...)
60 // *Bar` method.
61 func NewBarFiller(style string) BarFiller {
62 return newBarFiller(style, false)
63 }
64
65 // NewBarFillerRev returns a BarFiller implementation which renders a
66 // progress bar in reverse direction. If style is empty string,
67 // BarDefaultStyle is applied. To be used with `*Progress.Add(...)
68 // *Bar` method.
69 func NewBarFillerRev(style string) BarFiller {
70 return newBarFiller(style, true)
71 }
72
73 // NewBarFillerPick pick between regular and reverse BarFiller implementation
74 // based on rev param. To be used with `*Progress.Add(...) *Bar` method.
75 func NewBarFillerPick(style string, rev bool) BarFiller {
76 return newBarFiller(style, rev)
77 }
78
79 func newBarFiller(style string, rev bool) BarFiller {
80 bf := &barFiller{
81 format: make([][]byte, len(BarDefaultStyle)),
82 rwidth: make([]int, len(BarDefaultStyle)),
83 reverse: rev,
84 }
85 bf.parse(BarDefaultStyle)
86 if style != "" && style != BarDefaultStyle {
87 bf.parse(style)
20 // BarStyleComposer interface.
21 type BarStyleComposer interface {
22 BarFillerBuilder
23 Lbound(string) BarStyleComposer
24 Rbound(string) BarStyleComposer
25 Filler(string) BarStyleComposer
26 Refiller(string) BarStyleComposer
27 Padding(string) BarStyleComposer
28 Tip(...string) BarStyleComposer
29 Reverse() BarStyleComposer
30 }
31
32 type bFiller struct {
33 components [components]*component
34 tip struct {
35 count uint
36 frames []*component
37 }
38 flush func(dst io.Writer, filling, padding [][]byte)
39 }
40
41 type component struct {
42 width int
43 bytes []byte
44 }
45
46 type barStyle struct {
47 lbound string
48 rbound string
49 filler string
50 refiller string
51 padding string
52 tip []string
53 rev bool
54 }
55
56 // BarStyle constructs default bar style which can be altered via
57 // BarStyleComposer interface.
58 func BarStyle() BarStyleComposer {
59 return &barStyle{
60 lbound: "[",
61 rbound: "]",
62 filler: "=",
63 refiller: "+",
64 padding: "-",
65 tip: []string{">"},
66 }
67 }
68
69 func (s *barStyle) Lbound(bound string) BarStyleComposer {
70 s.lbound = bound
71 return s
72 }
73
74 func (s *barStyle) Rbound(bound string) BarStyleComposer {
75 s.rbound = bound
76 return s
77 }
78
79 func (s *barStyle) Filler(filler string) BarStyleComposer {
80 s.filler = filler
81 return s
82 }
83
84 func (s *barStyle) Refiller(refiller string) BarStyleComposer {
85 s.refiller = refiller
86 return s
87 }
88
89 func (s *barStyle) Padding(padding string) BarStyleComposer {
90 s.padding = padding
91 return s
92 }
93
94 func (s *barStyle) Tip(tip ...string) BarStyleComposer {
95 if len(tip) != 0 {
96 s.tip = append(s.tip[:0], tip...)
97 }
98 return s
99 }
100
101 func (s *barStyle) Reverse() BarStyleComposer {
102 s.rev = true
103 return s
104 }
105
106 func (s *barStyle) Build() BarFiller {
107 bf := new(bFiller)
108 if s.rev {
109 bf.flush = func(dst io.Writer, filling, padding [][]byte) {
110 flush(dst, padding, filling)
111 }
112 } else {
113 bf.flush = flush
114 }
115 bf.components[iLbound] = &component{
116 width: runewidth.StringWidth(stripansi.Strip(s.lbound)),
117 bytes: []byte(s.lbound),
118 }
119 bf.components[iRbound] = &component{
120 width: runewidth.StringWidth(stripansi.Strip(s.rbound)),
121 bytes: []byte(s.rbound),
122 }
123 bf.components[iFiller] = &component{
124 width: runewidth.StringWidth(stripansi.Strip(s.filler)),
125 bytes: []byte(s.filler),
126 }
127 bf.components[iRefiller] = &component{
128 width: runewidth.StringWidth(stripansi.Strip(s.refiller)),
129 bytes: []byte(s.refiller),
130 }
131 bf.components[iPadding] = &component{
132 width: runewidth.StringWidth(stripansi.Strip(s.padding)),
133 bytes: []byte(s.padding),
134 }
135 bf.tip.frames = make([]*component, len(s.tip))
136 for i, t := range s.tip {
137 bf.tip.frames[i] = &component{
138 width: runewidth.StringWidth(stripansi.Strip(t)),
139 bytes: []byte(t),
140 }
88141 }
89142 return bf
90143 }
91144
92 func (s *barFiller) parse(style string) {
93 if !utf8.ValidString(style) {
94 panic("invalid bar style")
95 }
96 srcFormat := make([][]byte, len(BarDefaultStyle))
97 srcRwidth := make([]int, len(BarDefaultStyle))
98 i := 0
99 for gr := uniseg.NewGraphemes(style); i < len(BarDefaultStyle) && gr.Next(); i++ {
100 srcFormat[i] = gr.Bytes()
101 srcRwidth[i] = runewidth.StringWidth(gr.Str())
102 }
103 copy(s.format, srcFormat[:i])
104 copy(s.rwidth, srcRwidth[:i])
105 if s.reverse {
106 s.tip = s.format[rRevTip]
107 s.flush = reverseFlush
108 } else {
109 s.tip = s.format[rTip]
110 s.flush = regularFlush
111 }
112 }
113
114 func (s *barFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
115 width := internal.CheckRequestedWidth(reqWidth, stat.AvailableWidth)
116 brackets := s.rwidth[rLeft] + s.rwidth[rRight]
145 func (s *bFiller) Fill(w io.Writer, width int, stat decor.Statistics) {
146 width = internal.CheckRequestedWidth(width, stat.AvailableWidth)
147 brackets := s.components[iLbound].width + s.components[iRbound].width
117148 if width < brackets {
118149 return
119150 }
120151 // don't count brackets as progress
121152 width -= brackets
122153
123 w.Write(s.format[rLeft])
124 defer w.Write(s.format[rRight])
125
126 cwidth := int(internal.PercentageRound(stat.Total, stat.Current, width))
127 space := &space{
128 space: s.format[rSpace],
129 rwidth: s.rwidth[rSpace],
130 count: width - cwidth,
131 }
132
133 index, refill := 0, 0
134 bb := make([][]byte, cwidth)
135
136 if cwidth > 0 && cwidth != width {
137 bb[index] = s.tip
138 cwidth -= s.rwidth[rTip]
139 index++
140 }
141
142 if stat.Refill > 0 {
143 refill = int(internal.PercentageRound(stat.Total, int64(stat.Refill), width))
144 if refill > cwidth {
145 refill = cwidth
146 }
147 cwidth -= refill
148 }
149
150 for cwidth > 0 {
151 bb[index] = s.format[rFill]
152 cwidth -= s.rwidth[rFill]
153 index++
154 }
155
156 for refill > 0 {
157 bb[index] = s.format[rRefill]
158 refill -= s.rwidth[rRefill]
159 index++
160 }
161
162 if cwidth+refill < 0 || space.rwidth > 1 {
163 buf := new(bytes.Buffer)
164 s.flush(buf, space, bb[:index])
165 io.WriteString(w, runewidth.Truncate(buf.String(), width, "…"))
166 return
167 }
168
169 s.flush(w, space, bb)
170 }
171
172 func regularFlush(w io.Writer, space *space, bb [][]byte) {
173 for i := len(bb) - 1; i >= 0; i-- {
174 w.Write(bb[i])
175 }
176 for space.count > 0 {
177 w.Write(space.space)
178 space.count -= space.rwidth
179 }
180 }
181
182 func reverseFlush(w io.Writer, space *space, bb [][]byte) {
183 for space.count > 0 {
184 w.Write(space.space)
185 space.count -= space.rwidth
186 }
187 for i := 0; i < len(bb); i++ {
188 w.Write(bb[i])
189 }
190 }
154 w.Write(s.components[iLbound].bytes)
155 defer w.Write(s.components[iRbound].bytes)
156
157 curWidth := int(internal.PercentageRound(stat.Total, stat.Current, width))
158 refWidth, filled := 0, curWidth
159 filling := make([][]byte, 0, curWidth)
160
161 if curWidth > 0 && curWidth != width {
162 tipFrame := s.tip.frames[s.tip.count%uint(len(s.tip.frames))]
163 filling = append(filling, tipFrame.bytes)
164 curWidth -= tipFrame.width
165 s.tip.count++
166 }
167
168 if stat.Refill > 0 && curWidth > 0 {
169 refWidth = int(internal.PercentageRound(stat.Total, int64(stat.Refill), width))
170 if refWidth > curWidth {
171 refWidth = curWidth
172 }
173 curWidth -= refWidth
174 }
175
176 for curWidth > 0 && curWidth >= s.components[iFiller].width {
177 filling = append(filling, s.components[iFiller].bytes)
178 curWidth -= s.components[iFiller].width
179 if s.components[iFiller].width == 0 {
180 break
181 }
182 }
183
184 for refWidth > 0 && refWidth >= s.components[iRefiller].width {
185 filling = append(filling, s.components[iRefiller].bytes)
186 refWidth -= s.components[iRefiller].width
187 if s.components[iRefiller].width == 0 {
188 break
189 }
190 }
191
192 filled -= curWidth + refWidth
193 padWidth := width - filled
194 padding := make([][]byte, 0, padWidth)
195 for padWidth > 0 && padWidth >= s.components[iPadding].width {
196 padding = append(padding, s.components[iPadding].bytes)
197 padWidth -= s.components[iPadding].width
198 if s.components[iPadding].width == 0 {
199 break
200 }
201 }
202
203 for padWidth > 0 {
204 padding = append(padding, []byte("…"))
205 padWidth--
206 }
207
208 s.flush(w, filling, padding)
209 }
210
211 func flush(dst io.Writer, filling, padding [][]byte) {
212 for i := len(filling) - 1; i >= 0; i-- {
213 dst.Write(filling[i])
214 }
215 for i := 0; i < len(padding); i++ {
216 dst.Write(padding[i])
217 }
218 }
33 "io"
44 "strings"
55
6 "github.com/acarl005/stripansi"
67 "github.com/mattn/go-runewidth"
7 "github.com/vbauerster/mpb/v6/decor"
8 "github.com/vbauerster/mpb/v6/internal"
8 "github.com/vbauerster/mpb/v7/decor"
9 "github.com/vbauerster/mpb/v7/internal"
910 )
1011
11 // SpinnerAlignment enum.
12 type SpinnerAlignment int
13
14 // SpinnerAlignment kinds.
1512 const (
16 SpinnerOnLeft SpinnerAlignment = iota
17 SpinnerOnMiddle
18 SpinnerOnRight
13 positionLeft = 1 + iota
14 positionRight
1915 )
2016
21 // SpinnerDefaultStyle is a style for rendering a spinner.
22 var SpinnerDefaultStyle = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
23
24 type spinnerFiller struct {
25 frames []string
26 count uint
27 alignment SpinnerAlignment
17 // SpinnerStyleComposer interface.
18 type SpinnerStyleComposer interface {
19 BarFillerBuilder
20 PositionLeft() SpinnerStyleComposer
21 PositionRight() SpinnerStyleComposer
2822 }
2923
30 // NewSpinnerFiller returns a BarFiller implementation which renders
31 // a spinner. If style is nil or zero length, SpinnerDefaultStyle is
32 // applied. To be used with `*Progress.Add(...) *Bar` method.
33 func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller {
34 if len(style) == 0 {
35 style = SpinnerDefaultStyle
36 }
37 filler := &spinnerFiller{
38 frames: style,
39 alignment: alignment,
40 }
41 return filler
24 type sFiller struct {
25 count uint
26 position uint
27 frames []string
4228 }
4329
44 func (s *spinnerFiller) Fill(w io.Writer, reqWidth int, stat decor.Statistics) {
45 width := internal.CheckRequestedWidth(reqWidth, stat.AvailableWidth)
30 type spinnerStyle struct {
31 position uint
32 frames []string
33 }
34
35 // SpinnerStyle constructs default spinner style which can be altered via
36 // SpinnerStyleComposer interface.
37 func SpinnerStyle(frames ...string) SpinnerStyleComposer {
38 ss := new(spinnerStyle)
39 if len(frames) != 0 {
40 ss.frames = append(ss.frames, frames...)
41 } else {
42 ss.frames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
43 }
44 return ss
45 }
46
47 func (s *spinnerStyle) PositionLeft() SpinnerStyleComposer {
48 s.position = positionLeft
49 return s
50 }
51
52 func (s *spinnerStyle) PositionRight() SpinnerStyleComposer {
53 s.position = positionRight
54 return s
55 }
56
57 func (s *spinnerStyle) Build() BarFiller {
58 sf := &sFiller{
59 position: s.position,
60 frames: s.frames,
61 }
62 return sf
63 }
64
65 func (s *sFiller) Fill(w io.Writer, width int, stat decor.Statistics) {
66 width = internal.CheckRequestedWidth(width, stat.AvailableWidth)
4667
4768 frame := s.frames[s.count%uint(len(s.frames))]
48 frameWidth := runewidth.StringWidth(frame)
69 frameWidth := runewidth.StringWidth(stripansi.Strip(frame))
4970
5071 if width < frameWidth {
5172 return
5273 }
5374
54 switch rest := width - frameWidth; s.alignment {
55 case SpinnerOnLeft:
75 rest := width - frameWidth
76 switch s.position {
77 case positionLeft:
5678 io.WriteString(w, frame+strings.Repeat(" ", rest))
57 case SpinnerOnMiddle:
79 case positionRight:
80 io.WriteString(w, strings.Repeat(" ", rest)+frame)
81 default:
5882 str := strings.Repeat(" ", rest/2) + frame + strings.Repeat(" ", rest/2+rest%2)
5983 io.WriteString(w, str)
60 case SpinnerOnRight:
61 io.WriteString(w, strings.Repeat(" ", rest)+frame)
6284 }
6385 s.count++
6486 }
33 "bytes"
44 "io"
55
6 "github.com/vbauerster/mpb/v6/decor"
7 "github.com/vbauerster/mpb/v6/internal"
6 "github.com/vbauerster/mpb/v7/decor"
7 "github.com/vbauerster/mpb/v7/internal"
88 )
99
1010 // BarOption is a func option to alter default behavior of a bar.
99 "time"
1010 "unicode/utf8"
1111
12 "github.com/vbauerster/mpb/v6"
13 "github.com/vbauerster/mpb/v6/decor"
12 "github.com/vbauerster/mpb/v7"
13 "github.com/vbauerster/mpb/v7/decor"
1414 )
1515
1616 func TestBarCompleted(t *testing.T) {
6060
6161 total := 100
6262 till := 30
63 refillRune, _ := utf8.DecodeLastRuneInString(mpb.BarDefaultStyle)
64
65 bar := p.AddBar(int64(total), mpb.BarFillerTrim())
63 refiller := "+"
64
65 bar := p.Add(int64(total), mpb.NewBarFiller(mpb.BarStyle().Refiller(refiller)), mpb.BarFillerTrim())
6666
6767 bar.SetRefill(int64(till))
6868 bar.IncrBy(till)
7575 p.Wait()
7676
7777 wantBar := fmt.Sprintf("[%s%s]",
78 strings.Repeat(string(refillRune), till-1),
78 strings.Repeat(refiller, till-1),
7979 strings.Repeat("=", total-till-1),
8080 )
8181
142142 func TestBarStyle(t *testing.T) {
143143 var buf bytes.Buffer
144144 customFormat := "╢▌▌░╟"
145 runes := []rune(customFormat)
145146 total := 80
146147 p := mpb.New(mpb.WithWidth(total), mpb.WithOutput(&buf))
147 bar := p.Add(int64(total), mpb.NewBarFiller(customFormat), mpb.BarFillerTrim())
148
149 for i := 0; i < total; i++ {
150 bar.Increment()
151 time.Sleep(10 * time.Millisecond)
152 }
153
154 p.Wait()
155
156 runes := []rune(customFormat)
157 wantBar := fmt.Sprintf("%s%s%s",
148 bs := mpb.BarStyle()
149 bs.Lbound(string(runes[0]))
150 bs.Filler(string(runes[1]))
151 bs.Tip(string(runes[2]))
152 bs.Padding(string(runes[3]))
153 bs.Rbound(string(runes[4]))
154 bar := p.Add(int64(total), mpb.NewBarFiller(bs), mpb.BarFillerTrim())
155
156 for i := 0; i < total; i++ {
157 bar.Increment()
158 time.Sleep(10 * time.Millisecond)
159 }
160
161 p.Wait()
162
163 wantBar := fmt.Sprintf("%s%s%s%s",
158164 string(runes[0]),
159 strings.Repeat(string(runes[1]), total-2),
160 string(runes[len(runes)-1]),
165 strings.Repeat(string(runes[1]), total-3),
166 string(runes[2]),
167 string(runes[4]),
161168 )
162169 got := string(getLastLine(buf.Bytes()))
163170
246253 }
247254 }
248255
256 func TestDecorStatisticsAvailableWidth(t *testing.T) {
257 td1 := func(s decor.Statistics) string {
258 if s.AvailableWidth != 80 {
259 t.Errorf("expected AvailableWidth %d got %d\n", 80, s.AvailableWidth)
260 }
261 return fmt.Sprintf("\x1b[31;1;4m%s\x1b[0m", strings.Repeat("0", 20))
262 }
263 checkDone := make(chan struct{})
264 td2 := func(s decor.Statistics) string {
265 defer func() {
266 checkDone <- struct{}{}
267 }()
268 if s.AvailableWidth != 40 {
269 t.Errorf("expected AvailableWidth %d got %d\n", 40, s.AvailableWidth)
270 }
271 return ""
272 }
273 total := 100
274 down := make(chan struct{})
275 p := mpb.New(
276 mpb.WithWidth(100),
277 mpb.WithShutdownNotifier(down),
278 mpb.WithOutput(ioutil.Discard),
279 )
280 bar := p.AddBar(int64(total),
281 mpb.BarFillerTrim(),
282 mpb.PrependDecorators(
283 decor.Name(strings.Repeat("0", 20)),
284 decor.Any(td1),
285 ),
286 mpb.AppendDecorators(
287 decor.Name(strings.Repeat("0", 20)),
288 decor.Any(td2),
289 ),
290 )
291 go func() {
292 for {
293 select {
294 case <-checkDone:
295 bar.Abort(false)
296 case <-down:
297 return
298 }
299 }
300 }()
301 for !bar.Completed() {
302 bar.Increment()
303 }
304 p.Wait()
305 }
306
249307 func panicDecorator(panicMsg string, cond func(decor.Statistics) bool) decor.Decorator {
250308 return decor.Any(func(st decor.Statistics) string {
251309 if cond(st) {
33 "io/ioutil"
44 "testing"
55
6 "github.com/vbauerster/mpb/v6/decor"
6 "github.com/vbauerster/mpb/v7/decor"
77 )
88
99 func BenchmarkIncrSingleBar(b *testing.B) {
55 "sync"
66 "time"
77
8 "github.com/vbauerster/mpb/v6/internal"
8 "github.com/vbauerster/mpb/v7/internal"
99 )
1010
1111 // ContainerOption is a func option to alter default behavior of a bar
0 // +build zos
1
2 package cwriter
3
4 import "golang.org/x/sys/unix"
5
6 const ioctlReadTermios = unix.TCGETS
0 // Package decor provides common decorators for "github.com/vbauerster/mpb/v6" module.
1 /*
2 Some decorators returned by this package might have a closure state. It is ok to use
3 decorators concurrently, unless you share the same decorator among multiple
4 *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance.
5
6 Don't:
7
8 p := mpb.New()
9 name := decor.Name("bar")
10 p.AddBar(100, mpb.AppendDecorators(name))
11 p.AddBar(100, mpb.AppendDecorators(name))
12
13 Do:
14
15 p := mpb.New()
16 p.AddBar(100, mpb.AppendDecorators(decor.Name("bar1")))
17 p.AddBar(100, mpb.AppendDecorators(decor.Name("bar2")))
18 */
0 // Package decor provides common decorators for "github.com/vbauerster/mpb/v7" module.
1 //
2 // Some decorators returned by this package might have a closure state. It is ok to use
3 // decorators concurrently, unless you share the same decorator among multiple
4 // *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance.
5 //
6 // Don't:
7 //
8 // p := mpb.New()
9 // name := decor.Name("bar")
10 // p.AddBar(100, mpb.AppendDecorators(name))
11 // p.AddBar(100, mpb.AppendDecorators(name))
12 //
13 // Do:
14 //
15 // p := mpb.New()
16 // p.AddBar(100, mpb.AppendDecorators(decor.Name("bar1")))
17 // p.AddBar(100, mpb.AppendDecorators(decor.Name("bar2")))
1918 package decor
44 "io"
55 "strconv"
66
7 "github.com/vbauerster/mpb/v6/internal"
7 "github.com/vbauerster/mpb/v7/internal"
88 )
99
1010 type percentageType float64
33 "sync"
44 "testing"
55
6 "github.com/vbauerster/mpb/v6"
7 "github.com/vbauerster/mpb/v6/decor"
6 "github.com/vbauerster/mpb/v7"
7 "github.com/vbauerster/mpb/v7/decor"
88 )
99
1010 func TestNameDecorator(t *testing.T) {
88 func TestDraw(t *testing.T) {
99 // key is termWidth
1010 testSuite := map[int][]struct {
11 style BarStyleComposer
1112 name string
12 style string
1313 total int64
1414 current int64
1515 refill int64
1616 barWidth int
1717 trim bool
18 reverse bool
1918 want string
2019 }{
2120 0: {
2322 name: "t,c{60,20}",
2423 total: 60,
2524 current: 20,
26 want: "… ",
27 },
28 {
29 name: "t,c{60,20}trim",
30 total: 60,
31 current: 20,
32 trim: true,
3325 want: "",
3426 },
27 {
28 name: "t,c{60,20}trim",
29 total: 60,
30 current: 20,
31 trim: true,
32 want: "",
33 },
3534 },
3635 1: {
3736 {
3837 name: "t,c{60,20}",
3938 total: 60,
4039 current: 20,
41 want: "… ",
40 want: "",
4241 },
4342 {
4443 name: "t,c{60,20}trim",
183182 want: "[==================>---------------------------------------]",
184183 },
185184 },
185 99: {
186 {
187 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
188 name: "[のだつ] t,c{99,1}",
189 total: 99,
190 current: 1,
191 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
192 },
193 {
194 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
195 name: "[のだつ] t,c{99,2}",
196 total: 99,
197 current: 2,
198 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
199 },
200 {
201 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
202 name: "[のだつ] t,c{99,3}",
203 total: 99,
204 current: 3,
205 want: " [だつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
206 },
207 {
208 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
209 name: "[のだつ] t,c{99,4}",
210 total: 99,
211 current: 4,
212 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
213 },
214 {
215 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
216 name: "[のだつ] t,c{99,5}",
217 total: 99,
218 current: 5,
219 want: " [のだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
220 },
221 {
222 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]"),
223 name: "[のだつ] t,c{99,6}",
224 total: 99,
225 current: 6,
226 want: " [ののだつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつ…] ",
227 },
228 {
229 style: BarStyle().Lbound("[").Filler("の").Tip("だ").Padding("つ").Rbound("]").Reverse(),
230 name: "[のだつ] t,c{99,6}rev",
231 total: 99,
232 current: 6,
233 want: " […つつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつつだのの] ",
234 },
235 },
186236 100: {
187237 {
188238 name: "t,c{100,0}",
258308 want: "[===============================>------------------------------------------------------------------]",
259309 },
260310 {
311 style: BarStyle().Tip("<").Reverse(),
261312 name: "t,c{100,33}trim,rev",
262313 total: 100,
263314 current: 33,
264315 trim: true,
265 reverse: true,
266316 want: "[------------------------------------------------------------------<===============================]",
267317 },
268318 {
281331 want: "[+++++++++++++++++++++++++++++++>------------------------------------------------------------------]",
282332 },
283333 {
334 style: BarStyle().Tip("<").Reverse(),
284335 name: "t,c,r{100,33,33}trim,rev",
285336 total: 100,
286337 current: 33,
287338 refill: 33,
288339 trim: true,
289 reverse: true,
290340 want: "[------------------------------------------------------------------<+++++++++++++++++++++++++++++++]",
291341 },
292342 {
305355 want: "[++++++++++++++++++++++++++++++++======>-----------------------------------------------------------]",
306356 },
307357 {
358 style: BarStyle().Tip("<").Reverse(),
308359 name: "t,c,r{100,40,33},rev",
309360 total: 100,
310361 current: 40,
311362 refill: 33,
312 reverse: true,
313363 want: " [----------------------------------------------------------<=====++++++++++++++++++++++++++++++++] ",
314364 },
315365 {
366 style: BarStyle().Tip("<").Reverse(),
316367 name: "t,c,r{100,40,33}trim,rev",
317368 total: 100,
318369 current: 40,
319370 refill: 33,
320371 trim: true,
321 reverse: true,
322372 want: "[-----------------------------------------------------------<======++++++++++++++++++++++++++++++++]",
323 },
324 {
325 name: "[=の-] t,c{100,1}",
326 style: "[=の-]",
327 total: 100,
328 current: 1,
329 want: " [の---------------------------------------------------------------------------------------------…] ",
330373 },
331374 },
332375 197: {
345388 var tmpBuf bytes.Buffer
346389 for tw, cases := range testSuite {
347390 for _, tc := range cases {
348 s := newTestState(tc.style, tc.reverse)
391 if tc.style == nil {
392 tc.style = BarStyle()
393 }
394 s := newTestState(NewBarFiller(tc.style))
349395 s.reqWidth = tc.barWidth
350396 s.total = tc.total
351397 s.current = tc.current
366412 }
367413 }
368414
369 func newTestState(style string, rev bool) *bState {
415 func newTestState(filler BarFiller) *bState {
370416 s := &bState{
371 filler: NewBarFillerPick(style, rev),
417 filler: filler,
372418 bufP: new(bytes.Buffer),
373419 bufB: new(bytes.Buffer),
374420 bufA: new(bytes.Buffer),
66 "math/rand"
77 "time"
88
9 "github.com/vbauerster/mpb/v6"
10 "github.com/vbauerster/mpb/v6/decor"
9 "github.com/vbauerster/mpb/v7"
10 "github.com/vbauerster/mpb/v7/decor"
1111 )
1212
1313 func Example() {
1919 // adding a single bar, which will inherit container's width
2020 bar := p.Add(int64(total),
2121 // progress bar filler with customized style
22 mpb.NewBarFiller("╢▌▌░╟"),
22 mpb.NewBarFiller(mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟")),
2323 mpb.PrependDecorators(
2424 // display our name with one space on the right
2525 decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
0 module github.com/vbauerster/mpb/v6
0 module github.com/vbauerster/mpb/v7
11
22 require (
3 github.com/VividCortex/ewma v1.1.1
3 github.com/VividCortex/ewma v1.2.0
44 github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
5 github.com/mattn/go-runewidth v0.0.10
6 github.com/rivo/uniseg v0.2.0
7 golang.org/x/sys v0.0.0-20210324051608-47abb6519492
5 github.com/mattn/go-runewidth v0.0.13
6 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
87 )
98
109 go 1.14
0 github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
1 github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
0 github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
1 github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
22 github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
33 github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
4 github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
5 github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
6 github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
4 github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
5 github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
76 github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
87 github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
9 golang.org/x/sys v0.0.0-20210324051608-47abb6519492 h1:Paq34FxTluEPvVyayQqMPgHm+vTOrIifmcYxFBx9TLg=
10 golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio=
9 golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22 // CheckRequestedWidth checks that requested width doesn't overflow
33 // available width
44 func CheckRequestedWidth(requested, available int) int {
5 if requested <= 0 || requested >= available {
5 if requested < 1 || requested >= available {
66 return available
77 }
88 return requested
1212 "sync"
1313 "time"
1414
15 "github.com/vbauerster/mpb/v6/cwriter"
16 "github.com/vbauerster/mpb/v6/decor"
15 "github.com/vbauerster/mpb/v7/cwriter"
16 "github.com/vbauerster/mpb/v7/decor"
1717 )
1818
1919 const (
9999 }
100100
101101 // AddBar creates a bar with default bar filler. Different filler can
102 // be choosen and applied via `*Progress.Add(...) *Bar` method.
102 // be chosen and applied via `*Progress.Add(...) *Bar` method.
103103 func (p *Progress) AddBar(total int64, options ...BarOption) *Bar {
104 return p.Add(total, NewBarFiller(BarDefaultStyle), options...)
104 return p.Add(total, NewBarFiller(BarStyle()), options...)
105105 }
106106
107107 // AddSpinner creates a bar with default spinner filler. Different
108 // filler can be choosen and applied via `*Progress.Add(...) *Bar`
108 // filler can be chosen and applied via `*Progress.Add(...) *Bar`
109109 // method.
110 func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar {
111 return p.Add(total, NewSpinnerFiller(SpinnerDefaultStyle, alignment), options...)
110 func (p *Progress) AddSpinner(total int64, options ...BarOption) *Bar {
111 return p.Add(total, NewBarFiller(SpinnerStyle()), options...)
112112 }
113113
114114 // Add creates a bar which renders itself by provided filler.
88 "testing"
99 "time"
1010
11 "github.com/vbauerster/mpb/v6"
12 "github.com/vbauerster/mpb/v6/decor"
11 "github.com/vbauerster/mpb/v7"
12 "github.com/vbauerster/mpb/v7/decor"
1313 )
1414
1515 func init() {
66 "strings"
77 "testing"
88
9 "github.com/vbauerster/mpb/v6"
9 "github.com/vbauerster/mpb/v7"
1010 )
1111
1212 const content = `Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do