Compare commits
2 Commits
7be196e4c3
...
fd0fd8954a
| Author | SHA1 | Date | |
|---|---|---|---|
| fd0fd8954a | |||
| 628db14f59 |
@@ -56,16 +56,16 @@ func newProgressIndicatorWithClock(total int, description string, c clock) *Prog
|
|||||||
|
|
||||||
func (p *ProgressIndicator) Update(current int) {
|
func (p *ProgressIndicator) Update(current int) {
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
defer p.mu.Unlock()
|
|
||||||
|
|
||||||
p.current = current
|
p.current = current
|
||||||
now := p.clock.Now()
|
now := p.clock.Now()
|
||||||
|
|
||||||
if now.Sub(p.lastUpdate) < 100*time.Millisecond {
|
if now.Sub(p.lastUpdate) < 100*time.Millisecond {
|
||||||
|
p.mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.lastUpdate = now
|
p.lastUpdate = now
|
||||||
|
p.mu.Unlock()
|
||||||
p.display()
|
p.display()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,15 +44,14 @@ func captureOutput(fn func()) string {
|
|||||||
r, w, _ := os.Pipe()
|
r, w, _ := os.Pipe()
|
||||||
os.Stdout = w
|
os.Stdout = w
|
||||||
|
|
||||||
defer func() {
|
|
||||||
_ = w.Close()
|
|
||||||
os.Stdout = old
|
|
||||||
}()
|
|
||||||
|
|
||||||
fn()
|
fn()
|
||||||
|
|
||||||
|
_ = w.Close()
|
||||||
|
os.Stdout = old
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, _ = io.Copy(&buf, r)
|
_, _ = io.Copy(&buf, r)
|
||||||
|
_ = r.Close()
|
||||||
return buf.String()
|
return buf.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user