aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v7/bar_option.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v7/bar_option.go')
-rw-r--r--vendor/github.com/vbauerster/mpb/v7/bar_option.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v7/bar_option.go b/vendor/github.com/vbauerster/mpb/v7/bar_option.go
index 46b7de0bf..660e7c487 100644
--- a/vendor/github.com/vbauerster/mpb/v7/bar_option.go
+++ b/vendor/github.com/vbauerster/mpb/v7/bar_option.go
@@ -5,12 +5,20 @@ import (
"io"
"github.com/vbauerster/mpb/v7/decor"
- "github.com/vbauerster/mpb/v7/internal"
)
// BarOption is a func option to alter default behavior of a bar.
type BarOption func(*bState)
+func skipNil(decorators []decor.Decorator) (filtered []decor.Decorator) {
+ for _, d := range decorators {
+ if d != nil {
+ filtered = append(filtered, d)
+ }
+ }
+ return
+}
+
func (s *bState) addDecorators(dest *[]decor.Decorator, decorators ...decor.Decorator) {
type mergeWrapper interface {
MergeUnwrap() []decor.Decorator
@@ -26,14 +34,14 @@ func (s *bState) addDecorators(dest *[]decor.Decorator, decorators ...decor.Deco
// AppendDecorators let you inject decorators to the bar's right side.
func AppendDecorators(decorators ...decor.Decorator) BarOption {
return func(s *bState) {
- s.addDecorators(&s.aDecorators, decorators...)
+ s.addDecorators(&s.aDecorators, skipNil(decorators)...)
}
}
// PrependDecorators let you inject decorators to the bar's left side.
func PrependDecorators(decorators ...decor.Decorator) BarOption {
return func(s *bState) {
- s.addDecorators(&s.pDecorators, decorators...)
+ s.addDecorators(&s.pDecorators, skipNil(decorators)...)
}
}
@@ -138,9 +146,12 @@ func BarNoPop() BarOption {
}
}
-// BarOptional will invoke provided option only when pick is true.
-func BarOptional(option BarOption, pick bool) BarOption {
- return BarOptOn(option, internal.Predicate(pick))
+// BarOptional will invoke provided option only when cond is true.
+func BarOptional(option BarOption, cond bool) BarOption {
+ if cond {
+ return option
+ }
+ return nil
}
// BarOptOn will invoke provided option only when higher order predicate