diff --git a/bar.go b/bar.go index 07651b3..5a946dc 100644 --- a/bar.go +++ b/bar.go @@ -34,13 +34,13 @@ priority int index int - runningBar *Bar - cacheState *bState - operateState chan func(*bState) - int64Ch chan int64 - boolCh chan bool - frameReaderCh chan *frameReader - syncTableCh chan [][]chan int + runningBar *Bar + cacheState *bState + operateState chan func(*bState) + int64Ch chan int64 + boolCh chan bool + bFrameCh chan *bFrame + syncTableCh chan [][]chan int // done is closed by Bar's goroutine, after cacheState is written done chan struct{} @@ -74,8 +74,8 @@ priority int runningBar *Bar } - frameReader struct { - io.Reader + bFrame struct { + rd io.Reader extendedLines int toShutdown bool removeOnComplete bool @@ -116,15 +116,15 @@ } b := &Bar{ - priority: s.priority, - runningBar: s.runningBar, - operateState: make(chan func(*bState)), - int64Ch: make(chan int64), - boolCh: make(chan bool), - frameReaderCh: make(chan *frameReader, 1), - syncTableCh: make(chan [][]chan int), - done: make(chan struct{}), - shutdown: make(chan struct{}), + priority: s.priority, + runningBar: s.runningBar, + operateState: make(chan func(*bState)), + int64Ch: make(chan int64), + boolCh: make(chan bool), + bFrameCh: make(chan *bFrame, 1), + syncTableCh: make(chan [][]chan int), + done: make(chan struct{}), + shutdown: make(chan struct{}), } if b.runningBar != nil { @@ -284,8 +284,8 @@ if p := recover(); p != nil { s.panicMsg = fmt.Sprintf("panic: %v", p) fmt.Fprintf(debugOut, "%s %s bar id %02d %v\n", "[mpb]", time.Now(), s.id, s.panicMsg) - b.frameReaderCh <- &frameReader{ - Reader: strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg)), + b.bFrameCh <- &bFrame{ + rd: strings.NewReader(fmt.Sprintf(fmt.Sprintf("%%.%ds\n", tw), s.panicMsg)), toShutdown: true, } } @@ -297,8 +297,8 @@ extendedLines = countLines(s.bufE.Bytes()) r = io.MultiReader(r, s.bufE) } - b.frameReaderCh <- &frameReader{ - Reader: r, + b.bFrameCh <- &bFrame{ + rd: r, extendedLines: extendedLines, toShutdown: s.toComplete && !s.completeFlushed, removeOnComplete: s.removeOnComplete, @@ -314,8 +314,8 @@ extendedLines = countLines(s.bufE.Bytes()) r = io.MultiReader(r, s.bufE) } - b.frameReaderCh <- &frameReader{ - Reader: r, + b.bFrameCh <- &bFrame{ + rd: r, extendedLines: extendedLines, } } diff --git a/progress.go b/progress.go index 05433e6..c4401d0 100644 --- a/progress.go +++ b/progress.go @@ -230,9 +230,9 @@ var lineCount int for s.bHeap.Len() > 0 { bar := heap.Pop(s.bHeap).(*Bar) - frameReader := <-bar.frameReaderCh + frame := <-bar.bFrameCh defer func() { - if frameReader.toShutdown { + if frame.toShutdown { // force next refresh asap, without waiting for ticker go func() { select { @@ -250,15 +250,15 @@ s.heapUpdated = true delete(s.waitBars, bar) } - if frameReader.removeOnComplete { + if frame.removeOnComplete { s.heapUpdated = true return } } heap.Push(s.bHeap, bar) }() - cw.ReadFrom(frameReader) - lineCount += frameReader.extendedLines + 1 + cw.ReadFrom(frame.rd) + lineCount += frame.extendedLines + 1 } for i := len(s.shutdownPending) - 1; i >= 0; i-- {