import "github.com/schollz/progressbar"
type Option func(p *ProgressBar)
Option is the type all options need to adhere to
OptionClearOnFinish will clear the bar once its finished
OptionEnableColorCodes enables or disables support for color codes using mitchellh/colorstring
OptionSetBytes will also print the bytes/second
OptionSetBytes64 will also print the bytes/second
OptionSetDescription sets the description of the bar to render in front of it
OptionSetPredictTime will also attempt to predict the time remaining.
Code:
bar := NewOptions(100, OptionSetWidth(10), OptionSetPredictTime(false)) _ = bar.Add(10)
Output:
10% |█ | [10:100]
OptionSetRenderBlankState sets whether or not to render a 0% bar on construction
OptionSetTheme sets the elements the bar is constructed of
OptionSetWidth sets the width of the bar
OptionSetWriter sets the output writer (defaults to os.StdOut)
OptionShowCount will also print current count out of total
OptionShowIts will also print the iterations/second
OptionThrottle will wait the specified duration before updating again. The default duration is 0 seconds.
type ProgressBar struct {
// contains filtered or unexported fields
}
ProgressBar is a thread-safe, simple progress bar
Code:
bar := New(100) bar.Add(10)
Output:
10% |████ | [0s:0s]
func New(max int) *ProgressBar
New returns a new ProgressBar with the specified maximum
func New64(max int64) *ProgressBar
New64 returns a new ProgressBar with the specified maximum
func NewOptions(max int, options ...Option) *ProgressBar
NewOptions constructs a new instance of ProgressBar, with any options you specify
func NewOptions64(max int64, options ...Option) *ProgressBar
NewOptions64 constructs a new instance of ProgressBar, with any options you specify
func (p *ProgressBar) Add(num int) error
Add will add the specified amount to the progressbar
func (p *ProgressBar) Add64(num int64) error
Add64 will add the specified amount to the progressbar
func (p *ProgressBar) ChangeMax(newMax int)
ChangeMax takes in a int and changes the max value of the progress bar
func (p *ProgressBar) ChangeMax64(newMax int64)
ChangeMax64 is basically the same as ChangeMax, but takes in a int64 to avoid casting
func (p *ProgressBar) Clear() error
Clear erases the progress bar from the current line
func (p *ProgressBar) Describe(description string)
Describe will change the description shown before the progress, which can be changed on the fly (as for a slow running process).
func (p *ProgressBar) Finish() error
Finish will fill the bar to full
func (p *ProgressBar) GetMax() int
Get the max of a bar
func (p *ProgressBar) GetMax64() int64
Same as GetMax, but returns int64
func (p *ProgressBar) Read(b []byte) (n int, err error)
Read implement io.Reader
func (p *ProgressBar) RenderBlank() error
RenderBlank renders the current bar state, you can use this to render a 0% state
Code:
NewOptions(10, OptionSetWidth(10), OptionSetRenderBlankState(true))
Output:
0% | | [0s:0s]
func (p *ProgressBar) Reset()
Reset will reset the clock that is used to calculate current time and the time left.
func (p *ProgressBar) State() State
State returns the current state
func (p *ProgressBar) Write(b []byte) (n int, err error)
Write implement io.Writer
Reader is the progressbar io.Reader struct
Close the reader when it implements io.Closer
Read will read the data and add the number of bytes to the progressbar
type State struct { CurrentPercent float64 CurrentBytes float64 MaxBytes int64 SecondsSince float64 SecondsLeft float64 KBsPerSecond float64 }
State is the basic properties of the bar
type Theme struct { Saucer string SaucerHead string SaucerPadding string BarStart string BarEnd string }
Theme defines the elements of the bar
Path | Synopsis |
---|---|
examples |
Package progressbar imports 10 packages (graph) and is imported by 21 packages. Updated 2019-11-17. Refresh now. Tools for package owners.