diff --git a/bar.go b/bar.go index 2c5ef11..0c3e9e4 100644 --- a/bar.go +++ b/bar.go @@ -29,7 +29,7 @@ trimLeftCh chan bool trimRightCh chan bool refillCh chan *refill - decoratorCh chan *decorator + dCommandCh chan *dCommandData flushedCh chan struct{} removeReqCh chan struct{} completeReqCh chan struct{} @@ -89,7 +89,7 @@ trimLeftCh: make(chan bool), trimRightCh: make(chan bool), refillCh: make(chan *refill), - decoratorCh: make(chan *decorator), + dCommandCh: make(chan *dCommandData), flushedCh: make(chan struct{}, 1), removeReqCh: make(chan struct{}), completeReqCh: make(chan struct{}), @@ -212,7 +212,7 @@ if isClosed(b.done) { return b } - b.decoratorCh <- &decorator{decPrepend, f} + b.dCommandCh <- &dCommandData{dPrepend, f} return b } @@ -221,7 +221,7 @@ if isClosed(b.done) { return } - b.decoratorCh <- &decorator{decPrependZero, nil} + b.dCommandCh <- &dCommandData{dPrependZero, nil} } // AppendFunc appends DecoratorFunc @@ -229,7 +229,7 @@ if isClosed(b.done) { return b } - b.decoratorCh <- &decorator{decAppend, f} + b.dCommandCh <- &dCommandData{dAppend, f} return b } @@ -238,7 +238,7 @@ if isClosed(b.done) { return } - b.decoratorCh <- &decorator{decAppendZero, nil} + b.dCommandCh <- &dCommandData{dAppendZero, nil} } // Completed signals to the bar, that process has been completed. @@ -298,15 +298,15 @@ } barState.current = n prevStartTime = blockStartTime - case d := <-b.decoratorCh: - switch d.kind { - case decAppend: - barState.appendFuncs = append(barState.appendFuncs, d.f) - case decAppendZero: + case data := <-b.dCommandCh: + switch data.action { + case dAppend: + barState.appendFuncs = append(barState.appendFuncs, data.f) + case dAppendZero: barState.appendFuncs = nil - case decPrepend: - barState.prependFuncs = append(barState.prependFuncs, d.f) - case decPrependZero: + case dPrepend: + barState.prependFuncs = append(barState.prependFuncs, data.f) + case dPrependZero: barState.prependFuncs = nil } case ch := <-b.stateReqCh: diff --git a/decorators.go b/decorators.go index e7a31dc..5f006f5 100644 --- a/decorators.go +++ b/decorators.go @@ -21,21 +21,21 @@ DextraSpace ) -type decoratorOperation uint +type decoratorAction uint const ( - decAppend decoratorOperation = iota - decPrepend - decAppendZero - decPrependZero + dAppend decoratorAction = iota + dPrepend + dAppendZero + dPrependZero ) // DecoratorFunc is a function that can be prepended and appended to the progress bar type DecoratorFunc func(s *Statistics, myWidth chan<- int, maxWidth <-chan int) string -type decorator struct { - kind decoratorOperation - f DecoratorFunc +type dCommandData struct { + action decoratorAction + f DecoratorFunc } // PrependName prepends name argument to the bar. diff --git a/progress.go b/progress.go index d74def9..bcdaaf0 100644 --- a/progress.go +++ b/progress.go @@ -20,23 +20,12 @@ type ( // BeforeRender is a func, which gets called before render process BeforeRender func([]*Bar) - barOpType uint - - operation struct { - kind barOpType + barAction uint + + bCommandData struct { + action barAction bar *Bar result chan bool - } - - indexedBarBuffer struct { - index int - buf []byte - } - - indexedBar struct { - index int - termWidth int - bar *Bar } widthSync struct { @@ -46,8 +35,8 @@ ) const ( - barAdd barOpType = iota - barRemove + bAdd barAction = iota + bRemove ) const ( @@ -70,7 +59,7 @@ width int format string - operationCh chan *operation + bCommandCh chan *bCommandData rrChangeReqCh chan time.Duration outChangeReqCh chan io.Writer barCountReqCh chan chan int @@ -85,7 +74,7 @@ func New() *Progress { p := &Progress{ width: pwidth, - operationCh: make(chan *operation), + bCommandCh: make(chan *bCommandData), rrChangeReqCh: make(chan time.Duration), outChangeReqCh: make(chan io.Writer), barCountReqCh: make(chan chan int), @@ -165,7 +154,7 @@ } result := make(chan bool) bar := newBar(id, total, p.width, p.format, p.wg, p.cancel) - p.operationCh <- &operation{barAdd, bar, result} + p.bCommandCh <- &bCommandData{bAdd, bar, result} if <-result { p.wg.Add(1) } @@ -179,7 +168,7 @@ panic(ErrCallAfterStop) } result := make(chan bool) - p.operationCh <- &operation{barRemove, b, result} + p.bCommandCh <- &bCommandData{bRemove, b, result} return <-result } @@ -213,7 +202,7 @@ if isClosed(p.done) { return } - close(p.operationCh) + close(p.bCommandCh) } // server monitors underlying channels and renders any progress bars @@ -245,25 +234,25 @@ case w := <-p.outChangeReqCh: cw.Flush() cw = cwriter.New(w) - case op, ok := <-p.operationCh: + case data, ok := <-p.bCommandCh: if !ok { return } - switch op.kind { - case barAdd: - bars = append(bars, op.bar) - op.result <- true - case barRemove: + switch data.action { + case bAdd: + bars = append(bars, data.bar) + data.result <- true + case bRemove: var ok bool for i, b := range bars { - if b == op.bar { + if b == data.bar { bars = append(bars[:i], bars[i+1:]...) ok = true b.remove() break } } - op.result <- ok + data.result <- ok } case respCh := <-p.barCountReqCh: respCh <- len(bars)