Codebase list golang-github-vbauerster-mpb / d48e1f6
refactoring WithAutoRefresh Vladimir Bauer 3 years ago
3 changed file(s) with 11 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
120120 p := mpb.New(
121121 mpb.WithWidth(100),
122122 mpb.WithOutput(&buf),
123 mpb.ForceAutoRefresh(),
123 mpb.WithAutoRefresh(),
124124 )
125125
126126 total := 100
152152 p := mpb.New(
153153 mpb.WithWidth(80),
154154 mpb.WithOutput(&buf),
155 mpb.ForceAutoRefresh(),
155 mpb.WithAutoRefresh(),
156156 )
157157
158158 total := 50
180180 p := mpb.New(
181181 mpb.WithWidth(80),
182182 mpb.WithOutput(&buf),
183 mpb.ForceAutoRefresh(),
183 mpb.WithAutoRefresh(),
184184 )
185185 bs := mpb.BarStyle()
186186 bs.Lbound(string(runes[0]))
256256 ctx, cancel := context.WithCancel(context.Background())
257257 p := mpb.NewWithContext(ctx,
258258 mpb.WithOutput(io.Discard),
259 mpb.ForceAutoRefresh(),
259 mpb.WithAutoRefresh(),
260260 mpb.WithShutdownNotifier(shutdown),
261261 )
262262 a := p.AddBar(100)
7777 }
7878
7979 // WithOutput overrides default os.Stdout output. If underlying io.Writer
80 // is not a terminal then auto refresh is disabled unless ForceAutoRefresh
81 // option is provided.
80 // is not a terminal then auto refresh is disabled unless WithAutoRefresh
81 // option is set.
8282 func WithOutput(w io.Writer) ContainerOption {
8383 if w == nil {
8484 w = io.Discard
9898 }
9999 }
100100
101 // ForceAutoRefresh force auto refresh even if output is not terminal.
101 // WithAutoRefresh force auto refresh regardless of what output is set to.
102102 // Applicable only if not WithManualRefresh set.
103 // Useful for testing purposes.
104 func ForceAutoRefresh() ContainerOption {
103 func WithAutoRefresh() ContainerOption {
105104 return func(s *pState) {
106105 s.autoRefresh = true
107106 }
5050 mpb.WithShutdownNotifier(shutdown),
5151 mpb.WithOutput(io.Discard),
5252 mpb.WithDebugOutput(&debug),
53 mpb.ForceAutoRefresh(),
53 mpb.WithAutoRefresh(),
5454 )
5555
5656 var errReturnCount int
9898 p := mpb.New(
9999 mpb.WithShutdownNotifier(shutdown),
100100 mpb.WithOutput(io.Discard),
101 mpb.ForceAutoRefresh(),
101 mpb.WithAutoRefresh(),
102102 )
103103 b := p.AddBar(100)
104104
134134 p := mpb.New(
135135 mpb.WithShutdownNotifier(shutdown),
136136 mpb.WithOutput(io.Discard),
137 mpb.ForceAutoRefresh(),
137 mpb.WithAutoRefresh(),
138138 )
139139 b := p.AddBar(100)
140140