diff --git a/bar.go b/bar.go index 7a6cf31..4282907 100644 --- a/bar.go +++ b/bar.go @@ -181,10 +181,19 @@ return b } +func (b *Bar) AppendPercentage() *Bar { + b.AppendFunc(func(s *Statistics) string { + completed := int(100 * float64(s.Completed) / float64(s.Total)) + return fmt.Sprintf("%3d %%", completed) + }) + return b +} + func (b *Bar) PrependPercentage() *Bar { b.PrependFunc(func(s *Statistics) string { completed := int(100 * float64(s.Completed) / float64(s.Total)) - return fmt.Sprintf("%3d %%", completed) + str := fmt.Sprintf("%3d %%", completed) + return fmt.Sprintf("%-5s", str) }) return b } @@ -273,10 +282,6 @@ return buf } -func (b *Bar) flushed() { - b.flushedCh <- struct{}{} -} - func (b *Bar) updateTimePerItemEstimate(items int, blockStartTime time.Time) { lastBlockTime := time.Since(blockStartTime) lastItemEstimate := float64(lastBlockTime) / float64(items) diff --git a/progress.go b/progress.go index e5bf49d..6c494be 100644 --- a/progress.go +++ b/progress.go @@ -25,8 +25,7 @@ width int stopped bool - op chan *operation - + op chan *operation rrChangeReqCh chan time.Duration wg *sync.WaitGroup @@ -138,7 +137,7 @@ lw.Flush() for _, b := range bars { go func(b *Bar) { - b.flushed() + b.flushedCh <- struct{}{} }(b) } case d := <-p.rrChangeReqCh: