Skip to content

Commit

Permalink
add Set and Set64
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Dec 24, 2019
1 parent 040caca commit 5889533
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
13 changes: 13 additions & 0 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ func (p *ProgressBar) Add(num int) error {
return p.Add64(int64(num))
}

// Set wil set the bar to a current number
func (p *ProgressBar) Set(num int) error {
return p.Set64(int64(num))
}

// Set64 wil set the bar to a current number
func (p *ProgressBar) Set64(num int64) error {
p.lock.Lock()
toAdd := int64(num) - p.state.currentNum
p.lock.Unlock()
return p.Add64(toAdd)
}

// Add64 will add the specified amount to the progressbar
func (p *ProgressBar) Add64(num int64) error {
p.lock.Lock()
Expand Down
15 changes: 15 additions & 0 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ func ExampleProgressBar() {
// Output:
// 10% |████ | [0s:0s]
}

func ExampleProgressBarSet() {
bar := New(100)
bar.Set(10)
// Output:
// 10% |████ | [0s:0s]
}

func ExampleProgressBarSet64() {
bar := New(100)
bar.Set64(10)
// Output:
// 10% |████ | [0s:0s]
}

func ExampleProgressBarBasic() {
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false))
bar.Reset()
Expand Down

0 comments on commit 5889533

Please sign in to comment.