Skip to content

Commit

Permalink
Merge pull request #176 from kevin-hanselman/master
Browse files Browse the repository at this point in the history
add ProgressBar.AddTotal
  • Loading branch information
cheggaaa committed Mar 1, 2021
2 parents 2553c89 + cc30ea4 commit 058b093
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions v3/pb.go
Expand Up @@ -238,6 +238,12 @@ func (pb *ProgressBar) SetTotal(value int64) *ProgressBar {
return pb
}

// AddTotal adds to the total bar value
func (pb *ProgressBar) AddTotal(value int64) *ProgressBar {
atomic.AddInt64(&pb.total, value)
return pb
}

// SetCurrent sets the current bar value
func (pb *ProgressBar) SetCurrent(value int64) *ProgressBar {
atomic.StoreInt64(&pb.current, value)
Expand Down
15 changes: 15 additions & 0 deletions v3/pb_test.go
Expand Up @@ -94,6 +94,21 @@ func TestPBMaxWidth(t *testing.T) {
}
}

func TestAddTotal(t *testing.T) {
bar := new(ProgressBar)
bar.SetTotal(0)
bar.AddTotal(50)
got := bar.Total()
if got != 50 {
t.Errorf("bar.Total() = %v, want %v", got, 50)
}
bar.AddTotal(-10)
got = bar.Total()
if got != 40 {
t.Errorf("bar.Total() = %v, want %v", got, 40)
}
}

func TestPBTemplate(t *testing.T) {
bar := new(ProgressBar)
result := bar.SetTotal(100).SetCurrent(50).SetWidth(40).String()
Expand Down

0 comments on commit 058b093

Please sign in to comment.