diff --git a/progress.go b/progress.go index 827c66c..3d144da 100644 --- a/progress.go +++ b/progress.go @@ -128,13 +128,26 @@ // New creates a bar by calling `Build` method on provided `BarFillerBuilder`. func (p *Progress) New(total int64, builder BarFillerBuilder, options ...BarOption) *Bar { - return p.AddFiller(total, builder.Build(), options...) -} - -// AddFiller creates a bar which renders itself by provided filler. -// If `total <= 0` triggering complete event by increment methods is disabled. -// Panics if *Progress instance is done, i.e. called after (*Progress).Wait(). -func (p *Progress) AddFiller(total int64, filler BarFiller, options ...BarOption) *Bar { + return p.MustAdd(total, builder.Build(), options...) +} + +// MustAdd creates a bar which renders itself by provided BarFiller. +// If `total <= 0` triggering complete event by increment methods is +// disabled. Panics if *Progress instance is done, i.e. called after +// (*Progress).Wait(). +func (p *Progress) MustAdd(total int64, filler BarFiller, options ...BarOption) *Bar { + bar, err := p.Add(total, filler, options...) + if err != nil { + panic(err) + } + return bar +} + +// Add creates a bar which renders itself by provided BarFiller. +// If `total <= 0` triggering complete event by increment methods +// is disabled. If *Progress instance is done, i.e. called after +// (*Progress).Wait(), return err == DoneError. +func (p *Progress) Add(total int64, filler BarFiller, options ...BarOption) (*Bar, error) { if filler == nil { filler = NopStyle().Build() } @@ -168,9 +181,9 @@ bs.shutdownListeners = append(bs.shutdownListeners, d) } }) - return bar + return bar, nil case <-p.done: - panic(DoneError) + return nil, DoneError } }