Skip to content

Commit

Permalink
Merge pull request #182 from black-night-heron/fix/finish-update-curr…
Browse files Browse the repository at this point in the history
…ent-bytes

Finish() should update state.currentBytes
  • Loading branch information
schollz authored May 20, 2024
2 parents 1e76c26 + cc253fb commit 37cfbad
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 37cfbad

Please sign in to comment.