modulepackage
2.0.6+incompatible
Repository: https://github.com/shiftleftsecurity/pb.git
Documentation: pkg.go.dev
# README
Terminal progress bar for Go
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)
}
}
# Packages
No description provided by the author
# Functions
No description provided by the author
New creates new ProgressBar object.
New64 creates new ProgressBar object using int64 as total.
RegisterElement give you a chance to use custom elements.
Start64 starts new ProgressBar with Default template.
StartNew starts new ProgressBar with Default template.
No description provided by the author
No description provided by the author
# Constants
Bytes means we're working with byte sizes.
Color by default is true when output is tty, but you can set to false for disabling colors.
ReturnSymbol - by default in terminal mode it's '\r'.
Static means progress bar will not update automaticly.
Terminal means we're will print to terminal and can use ascii sequences Also we're will try to use terminal width.
Version of ProgressBar library.
# Variables
Default - preset like Full but without elapsed time Example: 'Prefix 20/100 [-->______] 20% 1 p/s ETA 1m Suffix'.
ElementBar make progress bar view [-->__] Optionally can take up to 5 string arguments.
ElementCounters shows current and total values.
ElementCycle return next argument for every call In template use as follows: {{cycle .
ElementElapsedTime shows elapsed time Optionally cat take one argument - it's format for time string.
ElementPercent shows current percent of progress.
ElementRemainingTime calculates remaining time based on speed (EWMA) Optionally can take one or two string arguments.
ElementSpeed calculates current speed by EWMA Optionally can take one or two string arguments.
ElementString get value from bar by given key and print them bar.Set("myKey", "string to print") In template use as follows: {{string .
Full - preset with all default available elements Example: 'Prefix 20/100 [-->______] 20% 1 p/s ETA 1m Suffix'.
Simple - preset without speed and any timers.
# Structs
ProgressBar is the main object of bar.
Reader it's a wrapper for given reader, but with progress handle.
State represents the current state of bar Need for bar elements.
# Interfaces
Element is an interface for bar elements.
# Type aliases
ElementFunc type implements Element interface and created for simplify elements.
ProgressBarTemplate that template string.