Skip to content

Commit

Permalink
Add SetWriter to specify io.Writer
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Jan 29, 2018
1 parent 702bf7c commit 974cb68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"os"
"time"

"github.com/schollz/progressbar"
Expand All @@ -18,6 +19,14 @@ func main() {
bar.Reset()
for i := 0; i < 1000; i++ {
bar.Add(1)
time.Sleep(10 * time.Millisecond)
time.Sleep(5 * time.Millisecond)
}

bar.Reset()
bar.SetWriter(os.Stderr)
for i := 0; i < 1000; i++ {
bar.Add(1)
time.Sleep(5 * time.Millisecond)
}

}
7 changes: 7 additions & 0 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func (p *ProgressBar) SetSize(size int) {
p.size = size
}

// SetWriter will specify a different writer than os.Stdout
func (p *ProgressBar) SetWriter(w io.Writer) {
p.Lock()
defer p.Unlock()
p.w = w
}

// Add with increase the current count on the progress bar
func (p *ProgressBar) Add(num int) error {
p.RLock()
Expand Down

0 comments on commit 974cb68

Please sign in to comment.