kubo/Godeps/_workspace/src/github.com/cheggaaa/pb
Ho-Sheng Hsiao bf22aeec0a Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs
- Modified Godeps/Godeps.json by hand
- [TEST] Updated welcome docs hash to sharness
- [TEST] Updated contact doc
- [TEST] disabled breaking test (t0080-repo refs local)
2015-03-31 12:52:25 -07:00
..
example Reorged imports from jbenet/go-ipfs to ipfs/go-ipfs 2015-03-31 12:52:25 -07:00
format_test.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
format.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
LICENSE core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb_nix.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb_solaris.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb_test.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb_win.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb_x.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
pb.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
reader.go core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00
README.md core/commands: Added progress bar to 'cat' 2015-01-23 18:29:30 -08:00

Terminal progress bar for Go

Simple progress bar for console programms.

Installation

go get github.com/cheggaaa/pb

Usage

package main

import (
	"github.com/cheggaaa/pb"
	"time"
)

func main() {
	count := 100000
	bar := pb.StartNew(count)
	for i := 0; i < count; i++ {
		bar.Increment()
		time.Sleep(time.Millisecond)
	}
	bar.FinishPrint("The End!")
}

Result will be like this:

> go run test.go
37158 / 100000 [================>_______________________________] 37.16% 1m11s

More functions?

// create bar
bar := pb.New(count)

// refresh info every second (default 200ms)
bar.SetRefreshRate(time.Second)

// show percents (by default already true)
bar.ShowPercent = true

// show bar (by default already true)
bar.ShowBar = true

// no need counters
bar.ShowCounters = false

// show "time left"
bar.ShowTimeLeft = true

// show average speed    
bar.ShowSpeed = true

// sets the width of the progress bar
bar.SetWith(80)

// sets the width of the progress bar, but if terminal size smaller will be ignored
bar.SetMaxWith(80)

// convert output to readable format (like KB, MB)     
bar.SetUnits(pb.U_BYTES)

// and start
bar.Start()

Want handle progress of io operations?

// create and start bar
bar := pb.New(myDataLen).SetUnits(pb.U_BYTES)
bar.Start()

// my io.Reader
r := myReader

// my io.Writer
w := myWriter

// create multi writer
writer := io.MultiWriter(w, bar)

// and copy
io.Copy(writer, r)

// show example/copy/copy.go for advanced example

Not like the looks?

bar.Format("<.- >")