diff --git a/bar.go b/bar.go index 8505a99..1b617a4 100644 --- a/bar.go +++ b/bar.go @@ -170,22 +170,18 @@ } // 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) bool { +// Set toComplete to true, to trigger bar complete event now. +func (b *Bar) SetTotal(total int64, toComplete bool) { select { case b.operateState <- func(s *bState) { - if total > 0 { - s.total = total - } - if final && !s.toComplete { + s.total = total + if toComplete && !s.toComplete { s.current = s.total s.toComplete = true go b.refreshNowTillShutdown() } }: - return true - case <-b.done: - return false + case <-b.done: } } @@ -213,7 +209,7 @@ select { case b.operateState <- func(s *bState) { s.current += int64(n) - if s.current >= s.total && !s.toComplete { + if s.total > 0 && s.current >= s.total { s.current = s.total s.toComplete = true go b.refreshNowTillShutdown() diff --git a/progress.go b/progress.go index a97416b..54e54e8 100644 --- a/progress.go +++ b/progress.go @@ -111,9 +111,6 @@ // Add creates a bar which renders itself by provided filler. func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar { - if total <= 0 { - total = time.Now().Unix() - } if filler == nil { filler = newDefaultBarFiller() }