From cc253fb3307260a8b7f94a07c88f3276ce7a0dbc Mon Sep 17 00:00:00 2001 From: NigHThERon <14975428+black-night-heron@users.noreply.github.com> Date: Sat, 20 Apr 2024 18:40:44 +0800 Subject: [PATCH] fix: Finish() should update state.currentBytes --- progressbar.go | 5 +---- progressbar_test.go | 6 ++++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/progressbar.go b/progressbar.go index dbdeb0a..1d60be3 100644 --- a/progressbar.go +++ b/progressbar.go @@ -494,10 +494,7 @@ func (p *ProgressBar) Reset() { // Finish will fill the bar to full func (p *ProgressBar) Finish() error { - p.lock.Lock() - p.state.currentNum = p.config.max - p.lock.Unlock() - return p.Add(0) + return p.Set64(p.config.max) } // Exit will exit the bar to keep current state diff --git a/progressbar_test.go b/progressbar_test.go index ce780e8..cf46bec 100644 --- a/progressbar_test.go +++ b/progressbar_test.go @@ -94,10 +94,12 @@ func ExampleOptionClearOnFinish() { } func ExampleProgressBar_Finish() { - bar := NewOptions(100, OptionSetWidth(10)) + bar := NewOptions(100, OptionSetWidth(10), OptionShowCount(), OptionShowBytes(true), OptionShowIts()) + bar.Reset() + time.Sleep(1 * time.Second) bar.Finish() // Output: - // 100% |██████████| + // 100% |██████████| (100/100 B, 100 B/s, 100 it/s) } func Example_xOutOfY() {