Codebase list golang-github-vbauerster-mpb / 1a12c6b
RemoveAllPrependers, RemoveAllAppenders Vladimir Bauer 9 years ago
2 changed file(s) with 29 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
188188 // PrependFunc prepends DecoratorFunc
189189 func (b *Bar) PrependFunc(f DecoratorFunc) *Bar {
190190 if !b.isDone() {
191 b.decoratorCh <- &decorator{decoratorPrepend, f}
192 }
193 return b
191 b.decoratorCh <- &decorator{decPrepend, f}
192 }
193 return b
194 }
195
196 func (b *Bar) RemoveAllPrependers() {
197 if !b.isDone() {
198 b.decoratorCh <- &decorator{decPrependZero, nil}
199 }
194200 }
195201
196202 // AppendFunc appends DecoratorFunc
197203 func (b *Bar) AppendFunc(f DecoratorFunc) *Bar {
198204 if !b.isDone() {
199 b.decoratorCh <- &decorator{decoratorAppend, f}
200 }
201 return b
205 b.decoratorCh <- &decorator{decAppend, f}
206 }
207 return b
208 }
209
210 func (b *Bar) RemoveAllAppenders() {
211 if !b.isDone() {
212 b.decoratorCh <- &decorator{decAppendZero, nil}
213 }
202214 }
203215
204216 func (b *Bar) bytes(width int) []byte {
241253 blockStartTime = time.Now()
242254 case d := <-b.decoratorCh:
243255 switch d.kind {
244 case decoratorAppend:
256 case decAppend:
245257 state.appendFuncs = append(state.appendFuncs, d.f)
246 case decoratorPrepend:
258 case decAppendZero:
259 state.appendFuncs = nil
260 case decPrepend:
247261 state.prependFuncs = append(state.prependFuncs, d.f)
262 case decPrependZero:
263 state.prependFuncs = nil
248264 }
249265 case ch := <-b.stateReqCh:
250266 ch <- state
335351
336352 func (b *Bar) fillBar(total, current int64, width int) []byte {
337353 if width < 2 {
338 return []byte{b.leftEnd, b.rightEnd}
354 return []byte{}
339355 }
340356
341357 buf := make([]byte, width)
88 type decoratorFuncType uint
99
1010 const (
11 decoratorAppend decoratorFuncType = iota
12 decoratorPrepend
11 decAppend decoratorFuncType = iota
12 decPrepend
13 decAppendZero
14 decPrependZero
1315 )
1416
1517 // DecoratorFunc is a function that can be prepended and appended to the progress bar