diff --git a/bar.go b/bar.go index 6e0f96b..86e7569 100644 --- a/bar.go +++ b/bar.go @@ -101,7 +101,7 @@ // SetWidth overrides width of individual bar func (b *Bar) SetWidth(n int) *Bar { - if n < 2 || IsClosed(b.done) { + if n < 2 || isClosed(b.done) { return b } b.widthCh <- n @@ -110,7 +110,7 @@ // TrimLeftSpace removes space befor LeftEnd charater func (b *Bar) TrimLeftSpace() *Bar { - if IsClosed(b.done) { + if isClosed(b.done) { return b } b.trimLeftCh <- true @@ -119,7 +119,7 @@ // TrimRightSpace removes space after RightEnd charater func (b *Bar) TrimRightSpace() *Bar { - if IsClosed(b.done) { + if isClosed(b.done) { return b } b.trimRightCh <- true @@ -128,7 +128,7 @@ // Format overrides format of individual bar func (b *Bar) Format(format string) *Bar { - if utf8.RuneCountInString(format) != numFmtRunes || IsClosed(b.done) { + if utf8.RuneCountInString(format) != numFmtRunes || isClosed(b.done) { return b } b.formatCh <- format @@ -139,7 +139,7 @@ // Defaults to 0.25 // Normally you shouldn't touch this func (b *Bar) SetEtaAlpha(a float64) *Bar { - if IsClosed(b.done) { + if isClosed(b.done) { return b } b.etaAlphaCh <- a @@ -153,7 +153,7 @@ // Incr increments progress bar func (b *Bar) Incr(n int) { - if n < 1 || IsClosed(b.done) { + if n < 1 || isClosed(b.done) { return } b.incrCh <- int64(n) @@ -161,7 +161,7 @@ // IncrWithReFill increments pb with different fill character func (b *Bar) IncrWithReFill(n int, r rune) { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.Incr(n) @@ -196,12 +196,12 @@ // InProgress returns true, while progress is running // Can be used as condition in for loop func (b *Bar) InProgress() bool { - return !IsClosed(b.done) + return !isClosed(b.done) } // PrependFunc prepends DecoratorFunc func (b *Bar) PrependFunc(f DecoratorFunc) *Bar { - if IsClosed(b.done) { + if isClosed(b.done) { return b } b.decoratorCh <- &decorator{decPrepend, f} @@ -210,7 +210,7 @@ // RemoveAllPrependers removes all prepend functions func (b *Bar) RemoveAllPrependers() { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.decoratorCh <- &decorator{decPrependZero, nil} @@ -218,7 +218,7 @@ // AppendFunc appends DecoratorFunc func (b *Bar) AppendFunc(f DecoratorFunc) *Bar { - if IsClosed(b.done) { + if isClosed(b.done) { return b } b.decoratorCh <- &decorator{decAppend, f} @@ -227,7 +227,7 @@ // RemoveAllAppenders removes all append functions func (b *Bar) RemoveAllAppenders() { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.decoratorCh <- &decorator{decAppendZero, nil} @@ -237,14 +237,14 @@ // You should call this method when total is unknown and you've reached the point // of process completion. func (b *Bar) Completed() { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.completeReqCh <- struct{}{} } func (b *Bar) getState() state { - if IsClosed(b.done) { + if isClosed(b.done) { return b.state } ch := make(chan state, 1) @@ -334,14 +334,14 @@ } func (b *Bar) flushed() { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.flushedCh <- struct{}{} } func (b *Bar) remove() { - if IsClosed(b.done) { + if isClosed(b.done) { return } b.removeReqCh <- struct{}{} diff --git a/progress.go b/progress.go index 7042893..06a861d 100644 --- a/progress.go +++ b/progress.go @@ -109,7 +109,7 @@ // SetOut sets underlying writer of progress. Default is os.Stdout // pancis, if called on stopped Progress instance, i.e after Stop() func (p *Progress) SetOut(w io.Writer) *Progress { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } if w == nil { @@ -122,7 +122,7 @@ // RefreshRate overrides default (100ms) refresh rate value // pancis, if called on stopped Progress instance, i.e after Stop() func (p *Progress) RefreshRate(d time.Duration) *Progress { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } p.rrChangeReqCh <- d @@ -131,7 +131,7 @@ // BeforeRenderFunc accepts a func, which gets called before render process. func (p *Progress) BeforeRenderFunc(f BeforeRender) *Progress { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } p.brCh <- f @@ -147,7 +147,7 @@ // AddBarWithID creates a new progress bar and adds to the container // pancis, if called on stopped Progress instance, i.e after Stop() func (p *Progress) AddBarWithID(id int, total int64) *Bar { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } result := make(chan bool) @@ -162,7 +162,7 @@ // RemoveBar removes bar at any time // pancis, if called on stopped Progress instance, i.e after Stop() func (p *Progress) RemoveBar(b *Bar) bool { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } result := make(chan bool) @@ -173,7 +173,7 @@ // BarCount returns bars count in the container. // Pancis if called on stopped Progress instance, i.e after Stop() func (p *Progress) BarCount() int { - if IsClosed(p.done) { + if isClosed(p.done) { panic(ErrCallAfterStop) } respCh := make(chan int) @@ -194,7 +194,7 @@ // Stop waits for bars to finish rendering and stops the rendering goroutine func (p *Progress) Stop() { p.wg.Wait() - if IsClosed(p.done) { + if isClosed(p.done) { return } close(p.operationCh) @@ -305,9 +305,9 @@ return ibars } -// IsClosed check if ch closed +// isClosed check if ch closed // caution see: http://www.tapirgames.com/blog/golang-channel-closing -func IsClosed(ch <-chan struct{}) bool { +func isClosed(ch <-chan struct{}) bool { select { case <-ch: return true