diff --git a/bar.go b/bar.go index 8ada51d..5b2efea 100644 --- a/bar.go +++ b/bar.go @@ -63,7 +63,8 @@ trimRightSpace bool toComplete bool dynamic bool - noBarOnComplete bool + barClearOnComplete bool + completeFlushed bool startTime time.Time blockStartTime time.Time timeElapsed time.Duration @@ -321,7 +322,8 @@ r = strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg)) fmt.Fprintf(debugOut, "%s %s bar id %02d %v\n", "[mpb]", time.Now(), s.id, s.panicMsg) } - ch <- &bFrame{b, r, s.toComplete} + ch <- &bFrame{b, r, s.toComplete && !(s.barClearOnComplete && !s.completeFlushed)} + s.completeFlushed = s.toComplete }() r = s.draw(tw, pSyncer, aSyncer) }: @@ -333,7 +335,7 @@ } else { r = s.draw(tw, pSyncer, aSyncer) } - ch <- &bFrame{b, r, s.toComplete} + ch <- &bFrame{b, r, true} } }() @@ -361,7 +363,7 @@ prependCount := utf8.RuneCount(s.bufP.Bytes()) appendCount := utf8.RuneCount(s.bufA.Bytes()) - if s.toComplete && s.noBarOnComplete { + if s.barClearOnComplete && s.completeFlushed { return io.MultiReader(s.bufP, s.bufA) } @@ -440,7 +442,7 @@ func newStatistics(s *bState) *decor.Statistics { return &decor.Statistics{ ID: s.id, - Completed: s.toComplete, + Completed: s.completeFlushed, Total: s.total, Current: s.current, StartTime: s.startTime, diff --git a/bar_option.go b/bar_option.go index 18ba396..57a9c04 100644 --- a/bar_option.go +++ b/bar_option.go @@ -60,24 +60,27 @@ } } -// BarDynamicTotal enables dynamic total behaviour. +// 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 amount, when trigger percentage remained till bar completion. +// 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 %. -func BarAutoIncrTotal(trigger, amount int64) BarOption { +// Effective only if BarDynamicTotal option is set. +func BarAutoIncrTotal(trigger, n int64) BarOption { return func(s *bState) { - s.dynamic = true s.totalAutoIncrTrigger = trigger - s.totalAutoIncrBy = amount + s.totalAutoIncrBy = n } } -// BarRemoveOnComplete is a flag, which will trigger bar auto remove on completion event. +// 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. func BarRemoveOnComplete() BarOption { return func(s *bState) { s.removeOnComplete = true @@ -92,10 +95,11 @@ } } -// BarClearOnComplete clears the bar section on complete event. +// BarClearOnComplete is a flag, if set will clear bar section on complete event. +// If you need to remove a whole bar line, refer to BarRemoveOnComplete. func BarClearOnComplete() BarOption { return func(s *bState) { - s.noBarOnComplete = true + s.barClearOnComplete = true } }