Codebase list golang-github-vbauerster-mpb / b6bfaa3
AddBar Vladimir Bauer 9 years ago
1 changed file(s) with 14 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
2020 Out io.Writer
2121
2222 // Width is the width of the progress bars
23 Width int
23 // Width int
2424
2525 // Bars is the collection of progress bars
2626 // Bars []*Bar
3131 lw *uilive.Writer
3232 // stopChan chan struct{}
3333 // mtx *sync.RWMutex
34 bars chan Bar
34 bars chan *Bar
3535 ticker *time.Ticker
3636 }
3737
3838 // New returns a new progress bar with defaults
3939 func New() *Progress {
4040 p := &Progress{
41 Width: Width,
42 Out: Out,
43 // RefreshInterval: RefreshInterval,
44
45 lw: uilive.New(),
46 // stopChan: make(chan struct{}),
47 bars: make(chan Bar),
41 Out: Out,
42 lw: uilive.New(),
43 bars: make(chan *Bar),
4844 ticker: time.NewTicker(RefreshInterval),
4945 }
5046 go p.server()
5147 return p
5248 }
5349
50 // AddBar creates a new progress bar and adds to the container
51 func (p *Progress) AddBar(total int) *Bar {
52 bar := NewBar(total)
53 // bar.Width = p.Width
54 p.bars <- bar
55 return bar
56 }
57
5458 // Listen listens for updates and renders the progress bars
5559 func (p *Progress) server() {
56 bars := make([]Bar, 0)
60 bars := make([]*Bar, 0)
5761 p.lw.Out = p.Out
5862 loop:
5963 for {