diff --git a/bar.go b/bar.go index 2afaf72..0301b18 100644 --- a/bar.go +++ b/bar.go @@ -552,19 +552,17 @@ return table } -func (s *bState) sortDecorators() { - for _, decorators := range s.decorators { - for _, d := range decorators { - d := unwrap(d) - if d, ok := d.(decor.AverageDecorator); ok { - s.averageDecorators = append(s.averageDecorators, d) - } - if d, ok := d.(decor.EwmaDecorator); ok { - s.ewmaDecorators = append(s.ewmaDecorators, d) - } - if d, ok := d.(decor.ShutdownListener); ok { - s.shutdownListeners = append(s.shutdownListeners, d) - } +func (s *bState) sortDecorators(decorators []decor.Decorator) { + for _, d := range decorators { + d := unwrap(d) + if d, ok := d.(decor.AverageDecorator); ok { + s.averageDecorators = append(s.averageDecorators, d) + } + if d, ok := d.(decor.EwmaDecorator); ok { + s.ewmaDecorators = append(s.ewmaDecorators, d) + } + if d, ok := d.(decor.ShutdownListener); ok { + s.shutdownListeners = append(s.shutdownListeners, d) } } } diff --git a/bar_option.go b/bar_option.go index d5aa5b9..d001db3 100644 --- a/bar_option.go +++ b/bar_option.go @@ -24,6 +24,7 @@ func PrependDecorators(decorators ...decor.Decorator) BarOption { decorators = inspect(decorators) return func(s *bState) { + s.sortDecorators(decorators) s.decorators[0] = decorators } } @@ -32,6 +33,7 @@ func AppendDecorators(decorators ...decor.Decorator) BarOption { decorators = inspect(decorators) return func(s *bState) { + s.sortDecorators(decorators) s.decorators[1] = decorators } } diff --git a/progress.go b/progress.go index b4eaf75..8009faf 100644 --- a/progress.go +++ b/progress.go @@ -451,7 +451,5 @@ bs.buffers[1] = bytes.NewBuffer(make([]byte, 0, 128)) // append bs.buffers[2] = bytes.NewBuffer(make([]byte, 0, 256)) // filler - bs.sortDecorators() - return bs }