diff --git a/bar.go b/bar.go index 58c59a1..efbc5d0 100644 --- a/bar.go +++ b/bar.go @@ -44,7 +44,6 @@ type extFunc func(in io.Reader, reqWidth int, st decor.Statistics) (out io.Reader, lines int) type bState struct { - baseF BarFiller filler BarFiller id int reqWidth int diff --git a/bar_option.go b/bar_option.go index 9a55a8d..866772b 100644 --- a/bar_option.go +++ b/bar_option.go @@ -77,19 +77,22 @@ // BarFillerOnComplete replaces bar's filler with message, on complete event. func BarFillerOnComplete(message string) BarOption { - return func(s *bState) { - s.filler = makeBarFillerOnComplete(s.baseF, message) - } -} - -func makeBarFillerOnComplete(filler BarFiller, message string) BarFiller { - return BarFillerFunc(func(w io.Writer, width int, st decor.Statistics) { - if st.Completed { - io.WriteString(w, message) - } else { - filler.Fill(w, width, st) - } + return BarFillerMiddleware(func(base BarFiller) BarFiller { + return BarFillerFunc(func(w io.Writer, reqWidth int, st decor.Statistics) { + if st.Completed { + io.WriteString(w, message) + } else { + base.Fill(w, reqWidth, st) + } + }) }) +} + +// BarFillerMiddleware provides a way to augment default BarFiller. +func BarFillerMiddleware(middle func(BarFiller) BarFiller) BarOption { + return func(s *bState) { + s.filler = middle(s.filler) + } } // BarPriority sets bar's priority. Zero is highest priority, i.e. bar @@ -138,7 +141,7 @@ SetStyle(string) } return func(s *bState) { - if t, ok := s.baseF.(styleSetter); ok { + if t, ok := s.filler.(styleSetter); ok { t.SetStyle(style) } } @@ -158,7 +161,7 @@ SetReverse(bool) } return func(s *bState) { - if t, ok := s.baseF.(revSetter); ok { + if t, ok := s.filler.(revSetter); ok { t.SetReverse(true) } } @@ -188,7 +191,7 @@ cb func(interface{}), ) BarOption { return func(s *bState) { - if t, ok := typeChecker(s.baseF); ok { + if t, ok := typeChecker(s.filler); ok { cb(t) } } diff --git a/progress.go b/progress.go index e9df179..5a46f24 100644 --- a/progress.go +++ b/progress.go @@ -340,7 +340,6 @@ func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState { bs := &bState{ total: total, - baseF: extractBaseFiller(filler), filler: filler, priority: s.idCount, id: s.idCount, @@ -384,13 +383,3 @@ }() } } - -func extractBaseFiller(f BarFiller) BarFiller { - type wrapper interface { - Base() BarFiller - } - if f, ok := f.(wrapper); ok { - return extractBaseFiller(f.Base()) - } - return f -}