diff --git a/bar_option.go b/bar_option.go index 625f784..a14b286 100644 --- a/bar_option.go +++ b/bar_option.go @@ -47,8 +47,15 @@ } } +// BarWidth sets bar width independent of the container. +func BarWidth(width int) BarOption { + return func(s *bState) { + s.width = width + } +} + // BarRemoveOnComplete is a flag, if set whole bar line will be removed -// on complete event. If both BarRemoveOnComplete and BarClearOnComplete +// on complete event. If both BarRemoveOnComplete and BarClearOnComplete // are set, first bar section gets cleared and then whole bar line // gets removed completely. func BarRemoveOnComplete() BarOption { @@ -58,7 +65,7 @@ } // BarReplaceOnComplete is indicator for delayed bar start, after the -// `runningBar` is complete. To achieve bar replacement effect, +// `runningBar` is complete. To achieve bar replacement effect, // `runningBar` should has its `BarRemoveOnComplete` option set. func BarReplaceOnComplete(runningBar *Bar) BarOption { return func(s *bState) { @@ -67,7 +74,7 @@ } // BarClearOnComplete is a flag, if set will clear bar section on -// complete event. If you need to remove a whole bar line, refer to +// complete event. If you need to remove a whole bar line, refer to // BarRemoveOnComplete. func BarClearOnComplete() BarOption { return func(s *bState) { @@ -75,9 +82,9 @@ } } -// BarPriority sets bar's priority. -// Zero is highest priority, i.e. bar will be on top. If -// `BarReplaceOnComplete` option is supplied, this option is ignored. +// BarPriority sets bar's priority. Zero is highest priority, i.e. bar +// will be on top. If `BarReplaceOnComplete` option is supplied, this +// option is ignored. func BarPriority(priority int) BarOption { return func(s *bState) { s.priority = priority @@ -85,7 +92,7 @@ } // BarNewLineExtend takes user defined efn, which gets called each -// render cycle. Any write to provided writer of efn, will appear on +// render cycle. Any write to provided writer of efn, will appear on // new line of respective bar. func BarNewLineExtend(efn func(io.Writer, *decor.Statistics)) BarOption { return func(s *bState) { @@ -141,8 +148,8 @@ } // MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's -// actual type. If you implement your own Filler, so most probably -// you'll need this. See BarStyle or SpinnerStyle for example. +// actual type. If you implement your own Filler, so most probably +// you'll need this. See BarStyle or SpinnerStyle for example. func MakeFillerTypeSpecificBarOption( typeChecker func(Filler) (interface{}, bool), cb func(interface{}), @@ -153,3 +160,11 @@ } } } + +// OptionOnCondition returns option when condition evaluates to true. +func OptionOnCondition(option BarOption, condition func() bool) BarOption { + if condition() { + return option + } + return nil +}