func (p *Progress) Stop() {
	p.tdone <- true
	<-p.tdone
}
Stop stops listening
package uiprogress
import (
	"fmt"
	"io"
	"os"
	"sync"
	"time"
	"github.com/gosuri/uilive"
)
var Out = os.Stdout
var RefreshInterval = time.Millisecond * 10
var defaultProgress = New()
type Progress struct {
	Out io.Writer
	Width int
	Bars []*Bar
	RefreshInterval time.Duration
	lw     *uilive.Writer
	ticker *time.Ticker
	tdone  chan bool
	mtx    *sync.RWMutex
}
func New() *Progress {
	lw := uilive.New()
	lw.Out = Out
	return &Progress{
		Width:           Width,
		Out:             Out,
		Bars:            make([]*Bar, 0),
		RefreshInterval: RefreshInterval,
		tdone: make(chan bool),
		lw:    uilive.New(),
		mtx:   &sync.RWMutex{},
	}
}
func AddBar(total int) *Bar {
	return defaultProgress.AddBar(total)
}
func Start() {
	defaultProgress.Start()
}
func Stop() {
	defaultProgress.Stop()
}
func Listen() {
	defaultProgress.Listen()
}
func (p *Progress) SetOut(o io.Writer) {
	p.mtx.Lock()
	defer p.mtx.Unlock()
	p.Out = o
	p.lw.Out = o
}
func (p *Progress) SetRefreshInterval(interval time.Duration) {
	p.mtx.Lock()
	defer p.mtx.Unlock()
	p.RefreshInterval = interval
}
func (p *Progress) AddBar(total int) *Bar {
	p.mtx.Lock()
	defer p.mtx.Unlock()
	bar := NewBar(total)
	bar.Width = p.Width
	p.Bars = append(p.Bars, bar)
	return bar
}
func (p *Progress) Listen() {
	for {
		p.mtx.Lock()
		interval := p.RefreshInterval
		p.mtx.Unlock()
		select {
		case <-time.After(interval):
			p.print()
		case <-p.tdone:
			p.print()
			close(p.tdone)
			return
		}
	}
}
func (p *Progress) print() {
	p.mtx.Lock()
	defer p.mtx.Unlock()
	for _, bar := range p.Bars {
		fmt.Fprintln(p.lw, bar.String())
	}
	p.lw.Flush()
}
func (p *Progress) Start() {
	go p.Listen()
}