diff --git a/progress/progress.go b/progress/progress.go index cfeb845..c83caab 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -44,9 +44,6 @@ func New(info ProgressInfo) *ProgressBar { func (p *ProgressBar) render(final bool) { - p.lock.Lock() - defer p.lock.Unlock() - var sb strings.Builder numFilled := math.Round((float64(p.currentBytes) / float64(p.maxBytes)) * 40) @@ -121,7 +118,7 @@ func (p *ProgressBar) render(final bool) { if width == 0 { lineNum = 1 } else { - lineNum = ((len(removeANSIEscapeCodes(sb.String())) + width - 1) / width) + lineNum = (len(removeANSIEscapeCodes(sb.String())) + width - 1) / width } if p.hasStarted { @@ -142,9 +139,11 @@ func (p *ProgressBar) render(final bool) { } func (p *ProgressBar) Add(num int64) { + p.lock.Lock() p.currentBytes = p.currentBytes + num p.render(false) + p.lock.Unlock() } func (p *ProgressBar) Close() (err error) { @@ -161,7 +160,7 @@ func (p *ProgressBar) Close() (err error) { if width == 0 { lineNum = 1 } else { - lineNum = ((p.textWidth + width - 1) / width) + lineNum = (p.textWidth + width - 1) / width } for i := 0; i < lineNum; i++ {