diff --git a/bar.go b/bar.go index de14848..353f2ba 100644 --- a/bar.go +++ b/bar.go @@ -52,27 +52,24 @@ type ( bState struct { - id int - width int - total int64 - current int64 - totalAutoIncrTrigger int64 - totalAutoIncrBy int64 - runes barRunes - trimLeftSpace bool - trimRightSpace bool - toComplete bool - dynamic bool - removeOnComplete bool - barClearOnComplete bool - completeFlushed bool - aDecorators []decor.Decorator - pDecorators []decor.Decorator - amountReceivers []decor.AmountReceiver - shutdownListeners []decor.ShutdownListener - refill *refill - bufP, bufB, bufA *bytes.Buffer - panicMsg string + id int + width int + total int64 + current int64 + runes barRunes + trimLeftSpace bool + trimRightSpace bool + toComplete bool + removeOnComplete bool + barClearOnComplete bool + completeFlushed bool + aDecorators []decor.Decorator + pDecorators []decor.Decorator + amountReceivers []decor.AmountReceiver + shutdownListeners []decor.ShutdownListener + refill *refill + bufP, bufB, bufA *bytes.Buffer + panicMsg string // following options are assigned to the *Bar priority int @@ -90,8 +87,7 @@ ) func newBar(wg *sync.WaitGroup, id int, total int64, cancel <-chan struct{}, options ...BarOption) *Bar { - dynamic := total <= 0 - if dynamic { + if total <= 0 { total = time.Now().Unix() } @@ -99,7 +95,6 @@ id: id, priority: id, total: total, - dynamic: dynamic, } for _, opt := range options { @@ -195,15 +190,17 @@ } } -// SetTotal sets total dynamically. The final param indicates the very last set, -// in other words you should set it to true when total is determined. -// After final has been set, IncrBy should be called at least once. +// SetTotal sets total dynamically. +// Set final to true, when total is known, it will trigger bar complete event. func (b *Bar) SetTotal(total int64, final bool) { b.operateState <- func(s *bState) { - if total != 0 { + if total > 0 { s.total = total } - s.dynamic = !final + if final { + s.current = s.total + s.toComplete = true + } } } @@ -227,12 +224,7 @@ select { case b.operateState <- func(s *bState) { s.current += int64(n) - if s.dynamic { - curp := internal.Percentage(s.total, s.current, 100) - if 100-curp <= s.totalAutoIncrTrigger { - s.total += s.totalAutoIncrBy - } - } else if s.current >= s.total { + if s.current >= s.total { s.current = s.total s.toComplete = true } diff --git a/bar_option.go b/bar_option.go index adec4a9..77b67e7 100644 --- a/bar_option.go +++ b/bar_option.go @@ -67,24 +67,6 @@ } } -// BarDynamicTotal is a flag, if set enables dynamic total behaviour. -// If provided total <= 0, it is set implicitly. -func BarDynamicTotal() BarOption { - return func(s *bState) { - s.dynamic = true - } -} - -// BarAutoIncrTotal auto increment total by n, when trigger percentage remained till bar completion. -// In other words: say you've set trigger = 10, then auto increment will start after bar reaches 90 %. -// Effective only if BarDynamicTotal option is set. -func BarAutoIncrTotal(trigger, n int64) BarOption { - return func(s *bState) { - s.totalAutoIncrTrigger = trigger - s.totalAutoIncrBy = n - } -} - // BarRemoveOnComplete is a flag, if set whole bar line will be removed on complete event. // If both BarRemoveOnComplete and BarClearOnComplete are set, first bar section gets cleared // and then whole bar line gets removed completely.