diff --git a/options.go b/options.go index 70a2691..de04a90 100644 --- a/options.go +++ b/options.go @@ -2,6 +2,7 @@ import ( "io" + "io/ioutil" "time" "unicode/utf8" @@ -65,8 +66,18 @@ // Output overrides default output os.Stdout func Output(w io.Writer) ProgressOption { return func(c *pConf) { - if w != nil { - c.cw = cwriter.New(w) + if w == nil { + w = ioutil.Discard } + c.cw = cwriter.New(w) } } + +// OutputInterceptors provides a way to write to the underlying progress pool's +// writer. Could be useful if you want to output something below the bars, while +// they're rendering. +func OutputInterceptors(interseptors ...func(io.Writer)) ProgressOption { + return func(c *pConf) { + c.interceptors = interseptors + } +} diff --git a/progress.go b/progress.go index c1cec7b..4c7e9a3 100644 --- a/progress.go +++ b/progress.go @@ -1,6 +1,7 @@ package mpb import ( + "io" "os" "sync" "time" @@ -27,6 +28,7 @@ cw *cwriter.Writer ticker *time.Ticker beforeRender BeforeRender + interceptors []func(io.Writer) shutdownNotifier chan struct{} cancel <-chan struct{} @@ -213,6 +215,10 @@ for buf := range ch { conf.cw.Write(buf) + } + + for _, interceptor := range conf.interceptors { + interceptor(conf.cw) } conf.cw.Flush()