RemoveAllPrependers, RemoveAllAppenders
Vladimir Bauer
9 years ago
| 188 | 188 |
// PrependFunc prepends DecoratorFunc
|
| 189 | 189 |
func (b *Bar) PrependFunc(f DecoratorFunc) *Bar {
|
| 190 | 190 |
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 |
}
|
| 194 | 200 |
}
|
| 195 | 201 |
|
| 196 | 202 |
// AppendFunc appends DecoratorFunc
|
| 197 | 203 |
func (b *Bar) AppendFunc(f DecoratorFunc) *Bar {
|
| 198 | 204 |
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 |
}
|
| 202 | 214 |
}
|
| 203 | 215 |
|
| 204 | 216 |
func (b *Bar) bytes(width int) []byte {
|
|
| 241 | 253 |
blockStartTime = time.Now()
|
| 242 | 254 |
case d := <-b.decoratorCh:
|
| 243 | 255 |
switch d.kind {
|
| 244 | |
case decoratorAppend:
|
|
256 |
case decAppend:
|
| 245 | 257 |
state.appendFuncs = append(state.appendFuncs, d.f)
|
| 246 | |
case decoratorPrepend:
|
|
258 |
case decAppendZero:
|
|
259 |
state.appendFuncs = nil
|
|
260 |
case decPrepend:
|
| 247 | 261 |
state.prependFuncs = append(state.prependFuncs, d.f)
|
|
262 |
case decPrependZero:
|
|
263 |
state.prependFuncs = nil
|
| 248 | 264 |
}
|
| 249 | 265 |
case ch := <-b.stateReqCh:
|
| 250 | 266 |
ch <- state
|
|
| 335 | 351 |
|
| 336 | 352 |
func (b *Bar) fillBar(total, current int64, width int) []byte {
|
| 337 | 353 |
if width < 2 {
|
| 338 | |
return []byte{b.leftEnd, b.rightEnd}
|
|
354 |
return []byte{}
|
| 339 | 355 |
}
|
| 340 | 356 |
|
| 341 | 357 |
buf := make([]byte, width)
|
| 8 | 8 |
type decoratorFuncType uint
|
| 9 | 9 |
|
| 10 | 10 |
const (
|
| 11 | |
decoratorAppend decoratorFuncType = iota
|
| 12 | |
decoratorPrepend
|
|
11 |
decAppend decoratorFuncType = iota
|
|
12 |
decPrepend
|
|
13 |
decAppendZero
|
|
14 |
decPrependZero
|
| 13 | 15 |
)
|
| 14 | 16 |
|
| 15 | 17 |
// DecoratorFunc is a function that can be prepended and appended to the progress bar
|