| 237 | 237 |
}
|
| 238 | 238 |
wg.Done()
|
| 239 | 239 |
}
|
|
240 |
|
| 240 | 241 |
var beforeRender BeforeRender
|
| 241 | 242 |
cw := cwriter.New(os.Stdout)
|
| 242 | 243 |
bars := make([]*Bar, 0, 3)
|
|
| 280 | 281 |
beforeRender(bars)
|
| 281 | 282 |
}
|
| 282 | 283 |
|
| 283 | |
prependWs := newWidthSync(userRR, numBars, bars[0].NumOfPrependers())
|
| 284 | |
appendWs := newWidthSync(userRR, numBars, bars[0].NumOfAppenders())
|
|
284 |
quitWidthSyncCh := make(chan struct{})
|
|
285 |
time.AfterFunc(userRR, func() {
|
|
286 |
close(quitWidthSyncCh)
|
|
287 |
})
|
|
288 |
|
|
289 |
b0 := bars[0]
|
|
290 |
prependWs := newWidthSync(quitWidthSyncCh, numBars, b0.NumOfPrependers())
|
|
291 |
appendWs := newWidthSync(quitWidthSyncCh, numBars, b0.NumOfAppenders())
|
| 285 | 292 |
|
| 286 | 293 |
width, _, _ := cwriter.GetTermSize()
|
| 287 | 294 |
ibars := iBarsGen(bars, width)
|
|
| 326 | 333 |
}
|
| 327 | 334 |
}
|
| 328 | 335 |
|
| 329 | |
func newWidthSync(userRR time.Duration, numBars, numColumn int) *widthSync {
|
|
336 |
func newWidthSync(quit <-chan struct{}, numBars, numColumn int) *widthSync {
|
| 330 | 337 |
ws := &widthSync{
|
| 331 | 338 |
listen: make([]chan int, numColumn),
|
| 332 | 339 |
result: make([]chan int, numColumn),
|
|
| 339 | 346 |
go func(listenCh <-chan int, resultCh chan<- int) {
|
| 340 | 347 |
defer close(resultCh)
|
| 341 | 348 |
widths := make([]int, 0, numBars)
|
| 342 | |
abandon := time.After(userRR)
|
| 343 | 349 |
loop:
|
| 344 | 350 |
for {
|
| 345 | 351 |
select {
|
|
| 348 | 354 |
if len(widths) == numBars {
|
| 349 | 355 |
break loop
|
| 350 | 356 |
}
|
| 351 | |
case <-abandon:
|
|
357 |
case <-quit:
|
| 352 | 358 |
return
|
| 353 | 359 |
}
|
| 354 | 360 |
}
|