diff --git a/bar.go b/bar.go index efbc5d0..7aeb8c2 100644 --- a/bar.go +++ b/bar.go @@ -44,8 +44,8 @@ type extFunc func(in io.Reader, reqWidth int, st decor.Statistics) (out io.Reader, lines int) type bState struct { - filler BarFiller id int + priority int reqWidth int total int64 current int64 @@ -56,6 +56,7 @@ toComplete bool completeFlushed bool ignoreComplete bool + dropOnComplete bool noPop bool aDecorators []decor.Decorator pDecorators []decor.Decorator @@ -63,12 +64,10 @@ ewmaDecorators []decor.EwmaDecorator shutdownListeners []decor.ShutdownListener bufP, bufB, bufA *bytes.Buffer + filler BarFiller + middleware func(BarFiller) BarFiller extender extFunc - // priority overrides *Bar's priority, if set - priority int - // dropOnComplete propagates to *Bar - dropOnComplete bool // runningBar is a key for *pState.parkedBars runningBar *Bar diff --git a/bar_option.go b/bar_option.go index 866772b..31b7939 100644 --- a/bar_option.go +++ b/bar_option.go @@ -91,7 +91,7 @@ // BarFillerMiddleware provides a way to augment default BarFiller. func BarFillerMiddleware(middle func(BarFiller) BarFiller) BarOption { return func(s *bState) { - s.filler = middle(s.filler) + s.middleware = middle } } diff --git a/progress.go b/progress.go index 5a46f24..4b21faf 100644 --- a/progress.go +++ b/progress.go @@ -339,21 +339,23 @@ func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState { bs := &bState{ + id: s.idCount, + priority: s.idCount, + reqWidth: s.reqWidth, total: total, filler: filler, - priority: s.idCount, - id: s.idCount, - reqWidth: s.reqWidth, + extender: func(r io.Reader, _ int, _ decor.Statistics) (io.Reader, int) { return r, 0 }, debugOut: s.debugOut, - extender: func(r io.Reader, _ int, _ decor.Statistics) (io.Reader, int) { - return r, 0 - }, } for _, opt := range options { if opt != nil { opt(bs) } + } + + if bs.middleware != nil { + bs.filler = bs.middleware(filler) } if s.popCompleted && !bs.noPop {