Codebase list golang-gopkg-cheggaaa-pb.v1 / 63732d4
Imported Upstream version 1.0.5 Peter Colberg 7 years ago
4 changed file(s) with 44 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
111111
112112 // and copy
113113 io.Copy(writer, r)
114
115 bar.Finish()
114116 ```
115117
116118 ## Custom Progress Bar Look-and-feel
1212 )
1313
1414 // Current version
15 const Version = "1.0.2"
15 const Version = "1.0.5"
1616
1717 const (
1818 // Default refresh rate - 200ms
8080 Width int
8181 ForceWidth bool
8282 ManualUpdate bool
83 AutoStat bool
8384
8485 // Default width for the time box.
8586 UnitsWidth int
114115 if pb.Total == 0 {
115116 pb.ShowTimeLeft = false
116117 pb.ShowPercent = false
118 pb.AutoStat = false
117119 }
118120 if !pb.ManualUpdate {
119121 pb.Update() // Initial printing of the bar before running the bar refresher.
125127 // Increment current value
126128 func (pb *ProgressBar) Increment() int {
127129 return pb.Add(1)
130 }
131
132 // Get current value
133 func (pb *ProgressBar) Get() int64 {
134 c := atomic.LoadInt64(&pb.current)
135 return c
128136 }
129137
130138 // Set current value
241249 }
242250
243251 // Create new proxy reader over bar
252 // Takes io.Reader or io.ReadCloser
244253 func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader {
245254 return &Reader{r, pb}
246255 }
397406 pb.write(c)
398407 pb.currentValue = c
399408 }
409 if pb.AutoStat {
410 if c == 0 {
411 pb.startTime = time.Now()
412 pb.startValue = 0
413 } else if c >= pb.Total && pb.isFinish != true {
414 pb.Finish()
415 }
416 }
400417 }
401418
402419 func (pb *ProgressBar) String() string {
22 import (
33 "strings"
44 "testing"
5 "time"
56
67 "github.com/fatih/color"
78 "github.com/mattn/go-colorable"
5556 bar.Finish()
5657 bar.Finish()
5758 }
59
60 func Test_AutoStat(t *testing.T) {
61 bar := New(5)
62 bar.AutoStat = true
63 bar.Start()
64 time.Sleep(2 * time.Second)
65 //real start work
66 for i := 0; i < 5; i++ {
67 time.Sleep(500 * time.Millisecond)
68 bar.Increment()
69 }
70 //real finish work
71 time.Sleep(2 * time.Second)
72 bar.Finish()
73 }
1414 r.bar.Add(n)
1515 return
1616 }
17
18 // Close the reader when it implements io.Closer
19 func (r *Reader) Close() (err error) {
20 if closer, ok := r.Reader.(io.Closer); ok {
21 return closer.Close()
22 }
23 return
24 }