AddBar
Vladimir Bauer
9 years ago
| 20 | 20 | Out io.Writer |
| 21 | 21 | |
| 22 | 22 | // Width is the width of the progress bars |
| 23 | Width int | |
| 23 | // Width int | |
| 24 | 24 | |
| 25 | 25 | // Bars is the collection of progress bars |
| 26 | 26 | // Bars []*Bar |
| 31 | 31 | lw *uilive.Writer |
| 32 | 32 | // stopChan chan struct{} |
| 33 | 33 | // mtx *sync.RWMutex |
| 34 | bars chan Bar | |
| 34 | bars chan *Bar | |
| 35 | 35 | ticker *time.Ticker |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | // New returns a new progress bar with defaults |
| 39 | 39 | func New() *Progress { |
| 40 | 40 | 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), | |
| 48 | 44 | ticker: time.NewTicker(RefreshInterval), |
| 49 | 45 | } |
| 50 | 46 | go p.server() |
| 51 | 47 | return p |
| 52 | 48 | } |
| 53 | 49 | |
| 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 | ||
| 54 | 58 | // Listen listens for updates and renders the progress bars |
| 55 | 59 | func (p *Progress) server() { |
| 56 | bars := make([]Bar, 0) | |
| 60 | bars := make([]*Bar, 0) | |
| 57 | 61 | p.lw.Out = p.Out |
| 58 | 62 | loop: |
| 59 | 63 | for { |