BarNoPop BarOption
Vladimir Bauer
7 years ago
| 37 | 37 |
extendedLines int
|
| 38 | 38 |
toShutdown bool
|
| 39 | 39 |
toDrop bool
|
|
40 |
noPop bool
|
| 40 | 41 |
operateState chan func(*bState)
|
| 41 | 42 |
frameCh chan io.Reader
|
| 42 | 43 |
syncTableCh chan [][]chan int
|
|
| 70 | 71 |
toComplete bool
|
| 71 | 72 |
completeFlushed bool
|
| 72 | 73 |
noBufBOnComplete bool
|
|
74 |
noPop bool
|
| 73 | 75 |
aDecorators []decor.Decorator
|
| 74 | 76 |
pDecorators []decor.Decorator
|
| 75 | 77 |
amountReceivers []decor.AmountReceiver
|
|
| 102 | 104 |
container: container,
|
| 103 | 105 |
priority: bs.priority,
|
| 104 | 106 |
toDrop: bs.dropOnComplete,
|
|
107 |
noPop: bs.noPop,
|
| 105 | 108 |
operateState: make(chan func(*bState)),
|
| 106 | 109 |
frameCh: make(chan io.Reader, 1),
|
| 107 | 110 |
syncTableCh: make(chan [][]chan int),
|
| 166 | 166 |
return MakeFillerTypeSpecificBarOption(chk, cb)
|
| 167 | 167 |
}
|
| 168 | 168 |
|
|
169 |
// BarNoPop disables bar pop out of container. Effective when
|
|
170 |
// PopCompletedMode of container is enabled.
|
|
171 |
func BarNoPop() BarOption {
|
|
172 |
return func(s *bState) {
|
|
173 |
s.noPop = true
|
|
174 |
}
|
|
175 |
}
|
|
176 |
|
| 169 | 177 |
// BarReverse reverse mode, bar will progress from right to left.
|
| 170 | 178 |
func BarReverse() BarOption {
|
| 171 | 179 |
chk := func(filler Filler) (interface{}, bool) {
|
| 260 | 260 |
|
| 261 | 261 |
func (s *pState) flush(cw *cwriter.Writer) error {
|
| 262 | 262 |
var lineCount int
|
| 263 | |
hlen := s.bHeap.Len()
|
| 264 | |
bb := make([]*Bar, hlen)
|
| 265 | |
for i := 0; i < hlen; i++ {
|
|
263 |
bm := make(map[*Bar]struct{}, s.bHeap.Len())
|
|
264 |
for s.bHeap.Len() > 0 {
|
| 266 | 265 |
b := heap.Pop(&s.bHeap).(*Bar)
|
| 267 | 266 |
defer func() {
|
| 268 | 267 |
if b.toShutdown {
|
|
| 277 | 276 |
}()
|
| 278 | 277 |
cw.ReadFrom(<-b.frameCh)
|
| 279 | 278 |
lineCount += b.extendedLines + 1
|
| 280 | |
bb[i] = b
|
| 281 | |
}
|
| 282 | |
|
| 283 | |
for _, b := range bb {
|
| 284 | |
heap.Push(&s.bHeap, b)
|
|
279 |
bm[b] = struct{}{}
|
| 285 | 280 |
}
|
| 286 | 281 |
|
| 287 | 282 |
for _, b := range s.barShutdownQueue {
|
|
| 292 | 287 |
b.toDrop = true
|
| 293 | 288 |
}
|
| 294 | 289 |
if b.toDrop {
|
| 295 | |
heap.Remove(&s.bHeap, b.index)
|
|
290 |
delete(bm, b)
|
| 296 | 291 |
s.heapUpdated = true
|
| 297 | 292 |
} else if s.popCompleted {
|
| 298 | |
defer func() {
|
| 299 | |
s.barPopQueue = append(s.barPopQueue, b)
|
| 300 | |
}()
|
|
293 |
if !b.noPop {
|
|
294 |
defer func() {
|
|
295 |
s.barPopQueue = append(s.barPopQueue, b)
|
|
296 |
}()
|
|
297 |
}
|
| 301 | 298 |
}
|
| 302 | 299 |
b.cancel()
|
| 303 | 300 |
}
|
| 304 | 301 |
s.barShutdownQueue = s.barShutdownQueue[0:0]
|
| 305 | 302 |
|
| 306 | 303 |
for _, b := range s.barPopQueue {
|
| 307 | |
heap.Remove(&s.bHeap, b.index)
|
|
304 |
delete(bm, b)
|
| 308 | 305 |
s.heapUpdated = true
|
| 309 | 306 |
lineCount -= b.extendedLines + 1
|
| 310 | 307 |
}
|
| 311 | 308 |
s.barPopQueue = s.barPopQueue[0:0]
|
|
309 |
|
|
310 |
for b := range bm {
|
|
311 |
heap.Push(&s.bHeap, b)
|
|
312 |
}
|
| 312 | 313 |
|
| 313 | 314 |
return cw.Flush(lineCount)
|
| 314 | 315 |
}
|