1
0
Fork 0
mirror of https://github.com/Luzifer/gallery.git synced 2024-11-12 16:02:43 +00:00
gallery/vendor/github.com/cheggaaa/pb
Knut Ahlers 7eea7aaa62
Vendor dependencies
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-04-28 22:10:37 +02:00
..
.gitignore Vendor dependencies 2018-04-28 22:10:37 +02:00
.travis.yml Vendor dependencies 2018-04-28 22:10:37 +02:00
element.go Vendor dependencies 2018-04-28 22:10:37 +02:00
Gopkg.lock Vendor dependencies 2018-04-28 22:10:37 +02:00
Gopkg.toml Vendor dependencies 2018-04-28 22:10:37 +02:00
LICENSE Vendor dependencies 2018-04-28 22:10:37 +02:00
pb.go Vendor dependencies 2018-04-28 22:10:37 +02:00
preset.go Vendor dependencies 2018-04-28 22:10:37 +02:00
reader.go Vendor dependencies 2018-04-28 22:10:37 +02:00
README.md Vendor dependencies 2018-04-28 22:10:37 +02:00
speed.go Vendor dependencies 2018-04-28 22:10:37 +02:00
template.go Vendor dependencies 2018-04-28 22:10:37 +02:00
util.go Vendor dependencies 2018-04-28 22:10:37 +02:00

Terminal progress bar for Go

Coverage Status

It's beta, some features may be changed

This is proposal for the second version of progress bar

  • based on text/template
  • can take custom elements
  • using colors is easy

Installation

go get gopkg.in/cheggaaa/pb.v2

Usage

package main

import (
	"gopkg.in/cheggaaa/pb.v2"
	"time"
)

func main() {
	simple()
	fromPreset()
	customTemplate(`Custom template: {{counters . }}`)
	customTemplate(`{{ red "With colors:" }} {{bar . | green}} {{speed . | blue }}`)
	customTemplate(`{{ red "With funcs:" }} {{ bar . "<" "-" (cycle . "↖" "↗" "↘" "↙" ) "." ">"}} {{speed . | rndcolor }}`)
	customTemplate(`{{ bar . "[<" "·····•·····" (rnd "ᗧ" "◔" "◕" "◷" ) "•" ">]"}}`)
}

func simple() {
	count := 1000
	bar := pb.StartNew(count)
	for i := 0; i < count; i++ {
		bar.Increment()
		time.Sleep(time.Millisecond * 2)
	}
	bar.Finish()
}

func fromPreset() {
	count := 1000
	//bar := pb.Default.Start(total)
	//bar := pb.Simple.Start(total)
	bar := pb.Full.Start(count)
	defer bar.Finish()
	bar.Set("prefix", "fromPreset(): ")
	for i := 0; i < count/2; i++ {
		bar.Add(2)
		time.Sleep(time.Millisecond * 4)
	}
}

func customTemplate(tmpl string) {
	count := 1000
	bar := pb.ProgressBarTemplate(tmpl).Start(count)
	defer bar.Finish()
	for i := 0; i < count/2; i++ {
		bar.Add(2)
		time.Sleep(time.Millisecond * 4)
	}
}