Skip to content

Commit

Permalink
fix: Finish() should update state.currentBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
black-night-heron committed Apr 20, 2024
1 parent 304f5f4 commit cc253fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 1 addition & 4 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit cc253fb

Please sign in to comment.