Skip to content

Commit

Permalink
feat(prints): Add a WithProgressBar method. (#92)
Browse files Browse the repository at this point in the history
* chore(prints): Make some adjustments to color configurations

Signed-off-by: Flc゛ <[email protected]>

* feat(prints): Add a `WithProgressBar` method.

Signed-off-by: Flc゛ <[email protected]>

* feat(prints): Add a `WithProgressBar` method.

Signed-off-by: Flc゛ <[email protected]>

---------

Signed-off-by: Flc゛ <[email protected]>
  • Loading branch information
flc1125 authored Feb 7, 2024
1 parent ea462d1 commit 316ffdf
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(*testing.T) {
WithProgressBar(100, func(p *ProgressBar) {
for i := 1; i <= 100; i++ {
p.Increment()
}
})
}

0 comments on commit 316ffdf

Please sign in to comment.