Skip to content

hlubek/pb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Terminal progress bar for Go

Simple progress bar for console programms. Fork of https://github.com/cheggaaa/pb with usage of channels and refresh of time when progress stalls.

Installation

go get github.com/chlu/pb

Usage

package main

import (
	"github.com/chlu/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.RefreshRate = 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

// and start
bar.Start()

Not like the looks?

// insert before usage
pb.BarStart = "<"
pb.BarEnd   = ">"
pb.Empty    = " "
pb.Current  = "-"
pb.CurrentN = "."

About

Console progress bar for Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%