diff --git a/prints/progressbar.go b/prints/progressbar.go index 9adb8546..6be6cf4b 100644 --- a/prints/progressbar.go +++ b/prints/progressbar.go @@ -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() +} diff --git a/prints/progressbar_test.go b/prints/progressbar_test.go index 126b7dcc..6a1636a1 100644 --- a/prints/progressbar_test.go +++ b/prints/progressbar_test.go @@ -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() + } + }) +}