diff --git a/bar.go b/bar.go index eda7f20..8b9e856 100644 --- a/bar.go +++ b/bar.go @@ -29,12 +29,12 @@ f(w, width, stat) } -// BaseFiller interface. -// If you ever need to implement a custom Filler based on mpb.NewBarFiller, -// then you may need to implement this one as well, in order to retain -// functionality of some `BarOption`s and method like *Bar.SetRefill. -type BaseFiller interface { - BaseFiller() Filler +// Wrapper interface. +// If you're implementing custom Filler by wrapping a built-in one, +// it is necessary to implement this interface to retain functionality +// of built-in Filler. +type Wrapper interface { + Base() Filler } // Bar represents a progress Bar. diff --git a/progress.go b/progress.go index 4a0f3c1..546d7a1 100644 --- a/progress.go +++ b/progress.go @@ -332,7 +332,7 @@ func (s *pState) makeBarState(total int64, filler Filler, options ...BarOption) *bState { bs := &bState{ total: total, - baseF: filler, + baseF: extractBaseFiller(filler), filler: filler, priority: s.idCount, id: s.idCount, @@ -341,10 +341,6 @@ extender: func(r io.Reader, _ int, _ *decor.Statistics) (io.Reader, int) { return r, 0 }, - } - - if f, ok := filler.(BaseFiller); ok { - bs.baseF = f.BaseFiller() } for _, opt := range options { @@ -412,3 +408,10 @@ return multiplexedStream } + +func extractBaseFiller(f Filler) Filler { + if f, ok := f.(Wrapper); ok { + return extractBaseFiller(f.Base()) + } + return f +}