Skip to content

Commit

Permalink
feat(prints): Add a WithProgressBar method.
Browse files Browse the repository at this point in the history
Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 committed Feb 7, 2024
1 parent 7b869cf commit 3ac3f26
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prints/progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ func NewProgressBar(total int, opts ...ProgressBarOption) *ProgressBar {

return p
}

func WithProgressBar(total int, fc func(bar *ProgressBar), opts ...ProgressBarOption) {
bar := NewProgressBar(total, opts...)
fc(bar)
bar.Finish()
}
8 changes: 8 additions & 0 deletions prints/progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ func TestNewProgressBar(t *testing.T) {
}
p2.Finish()
}

func TestWithProgressBar(t *testing.T) {

Check warning on line 28 in prints/progressbar_test.go

View workflow job for this annotation

GitHub Actions / lint

unused-parameter: parameter 't' seems to be unused, consider removing or renaming it as _ (revive)
WithProgressBar(100, func(p *ProgressBar) {
for i := 1; i <= 100; i++ {
p.Increment()
}
})
}

0 comments on commit 3ac3f26

Please sign in to comment.