Codebase list golang-github-vbauerster-mpb / 3b4fea9
p.SetOut nil check Vladimir Bauer 9 years ago
2 changed file(s) with 12 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "fmt"
44 "math/rand"
5 "runtime"
65 "time"
76
87 "github.com/vbauerster/uiprogress"
98 )
109
1110 const (
12 maxBlockSize = 14
11 maxBlockSize = 12
1312 )
1413
1514 func main() {
16 runtime.GOMAXPROCS(runtime.NumCPU())
17
1815 decor := func(s *uiprogress.Statistics) string {
1916 str := fmt.Sprintf("%d/%d", s.Completed, s.Total)
2017 return fmt.Sprintf("%-7s", str)
2118 }
2219
23 p := uiprogress.New()
20 p := uiprogress.New().RefreshRate(80 * time.Millisecond)
2421
2522 bar1 := p.AddBar(50).AppendETA().PrependFunc(decor)
2623 go func() {
5454 return p
5555 }
5656
57 // SetOut sets underlying writer of progress
58 // default is os.Stdout
59 func (p *progress) SetOut(w io.Writer) *progress {
60 if w == nil {
61 return p
62 }
63 p.out = w
64 return p
65 }
66
5767 // AddBar creates a new progress bar and adds to the container
5868 func (p *progress) AddBar(total int) *Bar {
5969 p.wg.Add(1)
7484 p.interval <- d
7585 return p
7686 }
77
78 // SetOut sets underlying writer of progress
79 // default is os.Stdout
80 func (p *progress) SetOut(w io.Writer) *progress {
81 p.out = w
82 return p
83 }
84
85 // Bypass returns a writer which allows non-buffered data to be written to the underlying output
86 // func (p *progress) Bypass() io.Writer {
87 // return p.lw.Bypass()
88 // }
8987
9088 // WaitAndStop stops listening
9189 func (p *progress) WaitAndStop() {