diff --git a/bar.go b/bar.go index 1e31d9c..063906f 100644 --- a/bar.go +++ b/bar.go @@ -43,6 +43,7 @@ triggerComplete bool dropOnComplete bool noPop bool + forceAutoRefresh bool aDecorators []decor.Decorator pDecorators []decor.Decorator averageDecorators []decor.AverageDecorator @@ -185,7 +186,7 @@ if s.current >= s.total { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } else { s.triggerComplete = true } @@ -213,7 +214,7 @@ if triggerCompleteNow { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } }: case <-b.done: @@ -231,7 +232,7 @@ if s.triggerComplete && s.current >= s.total { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } }: case <-b.done: @@ -253,7 +254,7 @@ if s.triggerComplete && s.current >= s.total { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } }: case <-b.done: @@ -281,7 +282,7 @@ if s.triggerComplete && s.current >= s.total { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } }: case <-b.done: @@ -311,7 +312,7 @@ if s.triggerComplete && s.current >= s.total { s.current = s.total s.completed = true - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) } }: case <-b.done: @@ -349,7 +350,7 @@ } s.aborted = true s.dropOnComplete = drop - b.forceRefresh(s.refreshCh) + b.forceRefresh(s.forceAutoRefresh, s.refreshCh) }: case <-b.done: } @@ -448,8 +449,12 @@ } } -func (b *Bar) forceRefresh(refreshCh chan<- time.Time) { - go b.forceRefreshImpl(refreshCh) +func (b *Bar) forceRefresh(force bool, refreshCh chan<- time.Time) { + if force { + go b.forceRefreshImpl(refreshCh) + } else { + b.cancel() + } } func (b *Bar) forceRefreshImpl(refreshCh chan<- time.Time) { diff --git a/progress.go b/progress.go index cdfcb39..2fd6d85 100644 --- a/progress.go +++ b/progress.go @@ -88,7 +88,10 @@ cw := cwriter.New(s.output) if (cw.IsTerminal() || s.forceAutoRefresh) && !s.manualRefresh { + s.forceAutoRefresh = true go s.autoRefresh(s.renderDelay != nil) + } else { + s.forceAutoRefresh = false } p := &Progress{ @@ -247,7 +250,7 @@ } case <-p.done: update := make(chan bool) - for err == nil { + for s.forceAutoRefresh && err == nil { s.hm.state(update) if <-update { err = render() @@ -382,12 +385,13 @@ func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState { bs := &bState{ - id: s.idCount, - priority: s.idCount, - reqWidth: s.reqWidth, - total: total, - filler: filler, - refreshCh: s.refreshCh, + id: s.idCount, + priority: s.idCount, + reqWidth: s.reqWidth, + total: total, + filler: filler, + refreshCh: s.refreshCh, + forceAutoRefresh: s.forceAutoRefresh, } if total > 0 {