Codebase list golang-github-vbauerster-mpb / c12801a
New ProgressOption, OutputInterceptors. See issue #8 Vladimir Bauer 8 years ago
2 changed file(s) with 19 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11
22 import (
33 "io"
4 "io/ioutil"
45 "time"
56 "unicode/utf8"
67
6465 // Output overrides default output os.Stdout
6566 func Output(w io.Writer) ProgressOption {
6667 return func(c *pConf) {
67 if w != nil {
68 c.cw = cwriter.New(w)
68 if w == nil {
69 w = ioutil.Discard
6970 }
71 c.cw = cwriter.New(w)
7072 }
7173 }
74
75 // OutputInterceptors provides a way to write to the underlying progress pool's
76 // writer. Could be useful if you want to output something below the bars, while
77 // they're rendering.
78 func OutputInterceptors(interseptors ...func(io.Writer)) ProgressOption {
79 return func(c *pConf) {
80 c.interceptors = interseptors
81 }
82 }
00 package mpb
11
22 import (
3 "io"
34 "os"
45 "sync"
56 "time"
2627 cw *cwriter.Writer
2728 ticker *time.Ticker
2829 beforeRender BeforeRender
30 interceptors []func(io.Writer)
2931
3032 shutdownNotifier chan struct{}
3133 cancel <-chan struct{}
212214
213215 for buf := range ch {
214216 conf.cw.Write(buf)
217 }
218
219 for _, interceptor := range conf.interceptors {
220 interceptor(conf.cw)
215221 }
216222
217223 conf.cw.Flush()