func (b *Bar) SetTotal(total int64, final bool) {
	b.operateState <- func(s *bState) {
		if total != 0 {
			s.total = total
		}
		s.dynamic = !final
	}
}
SetTotal sets total dynamically. The final param indicates the very last set,
in other words you should set it to true when total is determined.
After final has been set, IncrBy should be called at least once.
package mpb
import (
	"bytes"
	"fmt"
	"io"
	"strings"
	"sync"
	"time"
	"unicode/utf8"
	"github.com/vbauerster/mpb/decor"
	"github.com/vbauerster/mpb/internal"
)
const (
	rLeft = iota
	rFill
	rTip
	rEmpty
	rRight
)
const (
	formatLen = 5
)
type barRunes [formatLen]rune
type Bar struct {
	priority int
	index    int
	runningBar    *Bar
	cacheState    *bState
	operateState  chan func(*bState)
	frameReaderCh chan io.Reader
	done chan struct{}
	shutdown chan struct{}
}
type (
	bState struct {
		id                   int
		width                int
		runes                barRunes
		total                int64
		current              int64
		totalAutoIncrTrigger int64
		totalAutoIncrBy      int64
		trimLeftSpace        bool
		trimRightSpace       bool
		toComplete           bool
		dynamic              bool
		removeOnComplete     bool
		barClearOnComplete   bool
		completeFlushed      bool
		aDecorators          []decor.Decorator
		pDecorators          []decor.Decorator
		amountReceivers      []decor.AmountReceiver
		shutdownListeners    []decor.ShutdownListener
		refill               *refill
		bufP, bufB, bufA     *bytes.Buffer
		panicMsg             string
		priority   int
		runningBar *Bar
	}
	refill struct {
		char rune
		till int64
	}
	frameReader struct {
		io.Reader
		toShutdown       bool
		removeOnComplete bool
	}
)
func newBar(wg *sync.WaitGroup, id int, total int64, cancel <-chan struct{}, options ...BarOption) *Bar {
	dynamic := total <= 0
	if dynamic {
		total = time.Now().Unix()
	}
	s := &bState{
		id:       id,
		priority: id,
		total:    total,
		dynamic:  dynamic,
	}
	for _, opt := range options {
		if opt != nil {
			opt(s)
		}
	}
	s.bufP = bytes.NewBuffer(make([]byte, 0, s.width))
	s.bufB = bytes.NewBuffer(make([]byte, 0, s.width))
	s.bufA = bytes.NewBuffer(make([]byte, 0, s.width))
	b := &Bar{
		priority:      s.priority,
		runningBar:    s.runningBar,
		operateState:  make(chan func(*bState)),
		frameReaderCh: make(chan io.Reader, 1),
		done:          make(chan struct{}),
		shutdown:      make(chan struct{}),
	}
	if b.runningBar != nil {
		b.priority = b.runningBar.priority
	}
	go b.serve(wg, s, cancel)
	return b
}
func (b *Bar) RemoveAllPrependers() {
	select {
	case b.operateState <- func(s *bState) { s.pDecorators = nil }:
	case <-b.done:
	}
}
func (b *Bar) RemoveAllAppenders() {
	select {
	case b.operateState <- func(s *bState) { s.aDecorators = nil }:
	case <-b.done:
	}
}
func (b *Bar) ProxyReader(r io.Reader) *Reader {
	proxyReader := &Reader{
		Reader: r,
		bar:    b,
	}
	return proxyReader
}
func (b *Bar) NumOfAppenders() int {
	result := make(chan int)
	select {
	case b.operateState <- func(s *bState) { result <- len(s.aDecorators) }:
		return <-result
	case <-b.done:
		return len(b.cacheState.aDecorators)
	}
}
func (b *Bar) NumOfPrependers() int {
	result := make(chan int)
	select {
	case b.operateState <- func(s *bState) { result <- len(s.pDecorators) }:
		return <-result
	case <-b.done:
		return len(b.cacheState.pDecorators)
	}
}
func (b *Bar) ID() int {
	result := make(chan int)
	select {
	case b.operateState <- func(s *bState) { result <- s.id }:
		return <-result
	case <-b.done:
		return b.cacheState.id
	}
}
func (b *Bar) Current() int64 {
	result := make(chan int64)
	select {
	case b.operateState <- func(s *bState) { result <- s.current }:
		return <-result
	case <-b.done:
		return b.cacheState.current
	}
}
func (b *Bar) Total() int64 {
	result := make(chan int64)
	select {
	case b.operateState <- func(s *bState) { result <- s.total }:
		return <-result
	case <-b.done:
		return b.cacheState.total
	}
}