Codebase list golang-github-vbauerster-mpb / 944d698
Setting output to nil, disables progress bar Vladimir Bauer 7 years ago
1 changed file(s) with 9 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "context"
44 "io"
5 "io/ioutil"
56 "sync"
67 "time"
78 )
2425 // width, as long as no BarWidth is applied.
2526 func WithWidth(w int) ContainerOption {
2627 return func(s *pState) {
27 if w >= 0 {
28 s.width = w
28 if w < 0 {
29 return
2930 }
31 s.width = w
3032 }
3133 }
3234
3335 // WithRefreshRate overrides default 120ms refresh rate.
3436 func WithRefreshRate(d time.Duration) ContainerOption {
3537 return func(s *pState) {
36 if d < 10*time.Millisecond {
37 return
38 }
3938 s.rr = d
4039 }
4140 }
6665 }
6766 }
6867
69 // WithOutput overrides default output os.Stdout.
68 // WithOutput overrides default os.Stdout output. Setting it to nil will
69 // effectively disable auto refresh rate and discard any output, usefull
70 // if you want to disable progress bars with little overhead.
7071 func WithOutput(w io.Writer) ContainerOption {
7172 return func(s *pState) {
7273 if w == nil {
74 s.manualRefreshCh = make(chan time.Time)
75 s.output = ioutil.Discard
7376 return
7477 }
7578 s.output = w