diff --git a/bar.go b/bar.go index 74f5f69..fd9852c 100644 --- a/bar.go +++ b/bar.go @@ -189,17 +189,29 @@ // PrependFunc prepends DecoratorFunc func (b *Bar) PrependFunc(f DecoratorFunc) *Bar { if !b.isDone() { - b.decoratorCh <- &decorator{decoratorPrepend, f} - } - return b + b.decoratorCh <- &decorator{decPrepend, f} + } + return b +} + +func (b *Bar) RemoveAllPrependers() { + if !b.isDone() { + b.decoratorCh <- &decorator{decPrependZero, nil} + } } // AppendFunc appends DecoratorFunc func (b *Bar) AppendFunc(f DecoratorFunc) *Bar { if !b.isDone() { - b.decoratorCh <- &decorator{decoratorAppend, f} - } - return b + b.decoratorCh <- &decorator{decAppend, f} + } + return b +} + +func (b *Bar) RemoveAllAppenders() { + if !b.isDone() { + b.decoratorCh <- &decorator{decAppendZero, nil} + } } func (b *Bar) bytes(width int) []byte { @@ -242,10 +254,14 @@ blockStartTime = time.Now() case d := <-b.decoratorCh: switch d.kind { - case decoratorAppend: + case decAppend: state.appendFuncs = append(state.appendFuncs, d.f) - case decoratorPrepend: + case decAppendZero: + state.appendFuncs = nil + case decPrepend: state.prependFuncs = append(state.prependFuncs, d.f) + case decPrependZero: + state.prependFuncs = nil } case ch := <-b.stateReqCh: ch <- state @@ -336,7 +352,7 @@ func (b *Bar) fillBar(total, current int64, width int) []byte { if width < 2 { - return []byte{b.leftEnd, b.rightEnd} + return []byte{} } buf := make([]byte, width) diff --git a/decorators.go b/decorators.go index cc3a18a..3d54a51 100644 --- a/decorators.go +++ b/decorators.go @@ -9,8 +9,10 @@ type decoratorFuncType uint const ( - decoratorAppend decoratorFuncType = iota - decoratorPrepend + decAppend decoratorFuncType = iota + decPrepend + decAppendZero + decPrependZero ) // DecoratorFunc is a function that can be prepended and appended to the progress bar