| 33 | 33 |
}
|
| 34 | 34 |
|
| 35 | 35 |
type pState struct {
|
| 36 | |
bHeap *priorityQueue
|
|
36 |
bHeap priorityQueue
|
| 37 | 37 |
heapUpdated bool
|
| 38 | 38 |
pMatrix map[int][]chan int
|
| 39 | 39 |
aMatrix map[int][]chan int
|
|
| 61 | 61 |
// context. It's not possible to reuse instance after *Progress.Wait()
|
| 62 | 62 |
// method has been called.
|
| 63 | 63 |
func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress {
|
| 64 | |
pq := make(priorityQueue, 0)
|
| 65 | |
heap.Init(&pq)
|
| 66 | 64 |
|
| 67 | 65 |
s := &pState{
|
| 68 | |
bHeap: &pq,
|
|
66 |
bHeap: priorityQueue{},
|
| 69 | 67 |
width: pwidth,
|
| 70 | 68 |
rr: prr,
|
| 71 | 69 |
parkedBars: make(map[*Bar]*Bar),
|
|
| 138 | 136 |
}
|
| 139 | 137 |
ps.parkedBars[bs.runningBar] = bar
|
| 140 | 138 |
} else {
|
| 141 | |
heap.Push(ps.bHeap, bar)
|
|
139 |
heap.Push(&ps.bHeap, bar)
|
| 142 | 140 |
ps.heapUpdated = true
|
| 143 | 141 |
}
|
| 144 | 142 |
ps.idCount++
|
|
| 157 | 155 |
if b.index < 0 {
|
| 158 | 156 |
return
|
| 159 | 157 |
}
|
| 160 | |
s.heapUpdated = heap.Remove(s.bHeap, b.index) != nil
|
|
158 |
s.heapUpdated = heap.Remove(&s.bHeap, b.index) != nil
|
| 161 | 159 |
}:
|
| 162 | 160 |
case <-p.done:
|
| 163 | 161 |
}
|
|
| 247 | 245 |
tw = s.width
|
| 248 | 246 |
}
|
| 249 | 247 |
for i := 0; i < s.bHeap.Len(); i++ {
|
| 250 | |
bar := (*s.bHeap)[i]
|
|
248 |
bar := s.bHeap[i]
|
| 251 | 249 |
go bar.render(tw)
|
| 252 | 250 |
}
|
| 253 | 251 |
|
|
| 257 | 255 |
func (s *pState) flush(cw *cwriter.Writer) error {
|
| 258 | 256 |
var lineCount int
|
| 259 | 257 |
for s.bHeap.Len() > 0 {
|
| 260 | |
bar := heap.Pop(s.bHeap).(*Bar)
|
|
258 |
bar := heap.Pop(&s.bHeap).(*Bar)
|
| 261 | 259 |
defer func() {
|
| 262 | 260 |
if bar.toShutdown {
|
| 263 | 261 |
// shutdown at next flush, in other words decrement underlying WaitGroup
|
|
| 265 | 263 |
// ensures no bar ends up with less than 100% rendered.
|
| 266 | 264 |
s.barShutdownQueue = append(s.barShutdownQueue, bar.cancel)
|
| 267 | 265 |
if parkedBar := s.parkedBars[bar]; parkedBar != nil {
|
| 268 | |
heap.Push(s.bHeap, parkedBar)
|
|
266 |
heap.Push(&s.bHeap, parkedBar)
|
| 269 | 267 |
s.heapUpdated = true
|
| 270 | 268 |
delete(s.parkedBars, bar)
|
| 271 | 269 |
}
|
|
| 274 | 272 |
return
|
| 275 | 273 |
}
|
| 276 | 274 |
}
|
| 277 | |
heap.Push(s.bHeap, bar)
|
|
275 |
heap.Push(&s.bHeap, bar)
|
| 278 | 276 |
}()
|
| 279 | 277 |
cw.ReadFrom(<-bar.frameCh)
|
| 280 | 278 |
lineCount += bar.extendedLines + 1
|
|
| 300 | 298 |
s.pMatrix = make(map[int][]chan int)
|
| 301 | 299 |
s.aMatrix = make(map[int][]chan int)
|
| 302 | 300 |
for i := 0; i < s.bHeap.Len(); i++ {
|
| 303 | |
bar := (*s.bHeap)[i]
|
|
301 |
bar := s.bHeap[i]
|
| 304 | 302 |
table := bar.wSyncTable()
|
| 305 | 303 |
pRow, aRow := table[0], table[1]
|
| 306 | 304 |
|