diff --git a/progress.go b/progress.go index 52261c5..f090c4c 100644 --- a/progress.go +++ b/progress.go @@ -63,8 +63,7 @@ // New creates new Progress instance, which orchestrates bars rendering process. // Accepts mpb.ProgressOption funcs for customization. func New(options ...ProgressOption) *Progress { - // defaults - conf := pState{ + s := &pState{ bars: make([]*Bar, 0, 3), width: pwidth, format: pformat, @@ -75,17 +74,17 @@ } for _, opt := range options { - opt(&conf) + opt(s) } p := &Progress{ - ewg: conf.ewg, + ewg: s.ewg, wg: new(sync.WaitGroup), done: make(chan struct{}), ops: make(chan func(*pState)), quit: make(chan struct{}), } - go p.server(conf) + go p.server(s) return p } @@ -94,11 +93,11 @@ p.wg.Add(1) result := make(chan *Bar, 1) select { - case p.ops <- func(c *pState) { - options = append(options, barWidth(c.width), barFormat(c.format)) - b := newBar(c.idCounter, total, p.wg, c.cancel, options...) - c.bars = append(c.bars, b) - c.idCounter++ + case p.ops <- func(s *pState) { + options = append(options, barWidth(s.width), barFormat(s.format)) + b := newBar(s.idCounter, total, p.wg, s.cancel, options...) + s.bars = append(s.bars, b) + s.idCounter++ result <- b }: return <-result @@ -111,12 +110,12 @@ func (p *Progress) RemoveBar(b *Bar) bool { result := make(chan bool, 1) select { - case p.ops <- func(c *pState) { + case p.ops <- func(s *pState) { var ok bool - for i, bar := range c.bars { + for i, bar := range s.bars { if bar == b { bar.Complete() - c.bars = append(c.bars[:i], c.bars[i+1:]...) + s.bars = append(s.bars[:i], s.bars[i+1:]...) ok = true break } @@ -133,8 +132,8 @@ func (p *Progress) BarCount() int { result := make(chan int, 1) select { - case p.ops <- func(c *pState) { - result <- len(c.bars) + case p.ops <- func(s *pState) { + result <- len(s.bars) }: return <-result case <-p.quit: diff --git a/progress_posix.go b/progress_posix.go index 5012535..39cb68f 100644 --- a/progress_posix.go +++ b/progress_posix.go @@ -13,7 +13,7 @@ "github.com/vbauerster/mpb/cwriter" ) -func (p *Progress) server(s pState) { +func (p *Progress) server(s *pState) { winch := make(chan os.Signal, 1) signal.Notify(winch, syscall.SIGWINCH) @@ -34,7 +34,7 @@ for { select { case op := <-p.ops: - op(&s) + op(s) case <-s.ticker.C: if len(s.bars) == 0 { runtime.Gosched() diff --git a/progress_windows.go b/progress_windows.go index ddbe8b1..931ae1c 100644 --- a/progress_windows.go +++ b/progress_windows.go @@ -10,7 +10,7 @@ "github.com/vbauerster/mpb/cwriter" ) -func (p *Progress) server(s pState) { +func (p *Progress) server(s *pState) { defer func() { if s.shutdownNotifier != nil { close(s.shutdownNotifier) @@ -23,7 +23,7 @@ for { select { case op := <-p.ops: - op(&s) + op(s) case <-s.ticker.C: if len(s.bars) == 0 { runtime.Gosched()