@@ -2,7 +2,7 @@ package meter
22
33import (
44 "fmt"
5- "os "
5+ "io "
66 "sync"
77 "sync/atomic"
88 "time"
@@ -30,9 +30,10 @@ type Progress interface {
3030var Spinners = []string {"|" , "(" , "<" , "-" , "<" , "(" , "|" , ")" , ">" , "-" , ">" , ")" }
3131
3232// progressMeter is a `Progress` that reports the current state every
33- // `period`.
33+ // `period` to an `io.Writer` .
3434type progressMeter struct {
3535 lock sync.Mutex
36+ w io.Writer
3637 format string
3738 period time.Duration
3839 lastShownCount int64
@@ -48,8 +49,9 @@ type progressMeter struct {
4849// NewProgressMeter returns a progress meter that can be used to show
4950// progress to a TTY periodically, including an increasing int64
5051// value.
51- func NewProgressMeter (period time.Duration ) Progress {
52+ func NewProgressMeter (w io. Writer , period time.Duration ) Progress {
5253 return & progressMeter {
54+ w : w ,
5355 period : period ,
5456 }
5557}
@@ -81,7 +83,7 @@ func (p *progressMeter) Start(format string) {
8183 } else {
8284 s = ""
8385 }
84- fmt .Fprintf (os . Stderr , p .format , c , s , "\r " )
86+ fmt .Fprintf (p . w , p .format , c , s , "\r " )
8587 p .lock .Unlock ()
8688 }
8789 }()
@@ -100,7 +102,7 @@ func (p *progressMeter) Done() {
100102 defer p .lock .Unlock ()
101103 p .ticker = nil
102104 c := atomic .LoadInt64 (& p .count )
103- fmt .Fprintf (os . Stderr , p .format , c , " " , "\n " )
105+ fmt .Fprintf (p . w , p .format , c , " " , "\n " )
104106}
105107
106108// NoProgressMeter is a `Progress` that doesn't actually report
0 commit comments