progressbar: github.com/schollz/progressbar Index | Examples | Files | Directories

package progressbar

import "github.com/schollz/progressbar"

Index

Examples

Package Files

progressbar.go

type Option Uses

type Option func(p *ProgressBar)

Option is the type all options need to adhere to

func OptionClearOnFinish Uses

func OptionClearOnFinish() Option

OptionClearOnFinish will clear the bar once its finished

func OptionEnableColorCodes Uses

func OptionEnableColorCodes(colorCodes bool) Option

OptionEnableColorCodes enables or disables support for color codes using mitchellh/colorstring

func OptionOnCompletion Uses

func OptionOnCompletion(cmpl func()) Option

func OptionSetBytes Uses

func OptionSetBytes(maxBytes int) Option

OptionSetBytes will also print the bytes/second

func OptionSetBytes64 Uses

func OptionSetBytes64(maxBytes int64) Option

OptionSetBytes64 will also print the bytes/second

func OptionSetDescription Uses

func OptionSetDescription(description string) Option

OptionSetDescription sets the description of the bar to render in front of it

func OptionSetPredictTime Uses

func OptionSetPredictTime(predictTime bool) Option

OptionSetPredictTime will also attempt to predict the time remaining.

Code:

bar := NewOptions(100, OptionSetWidth(10), OptionSetPredictTime(false))
_ = bar.Add(10)

Output:

10% |█         |  [10:100]

func OptionSetRenderBlankState Uses

func OptionSetRenderBlankState(r bool) Option

OptionSetRenderBlankState sets whether or not to render a 0% bar on construction

func OptionSetTheme Uses

func OptionSetTheme(t Theme) Option

OptionSetTheme sets the elements the bar is constructed of

func OptionSetWidth Uses

func OptionSetWidth(s int) Option

OptionSetWidth sets the width of the bar

func OptionSetWriter Uses

func OptionSetWriter(w io.Writer) Option

OptionSetWriter sets the output writer (defaults to os.StdOut)

func OptionShowCount Uses

func OptionShowCount() Option

OptionShowCount will also print current count out of total

func OptionShowIts Uses

func OptionShowIts() Option

OptionShowIts will also print the iterations/second

func OptionThrottle Uses

func OptionThrottle(duration time.Duration) Option

OptionThrottle will wait the specified duration before updating again. The default duration is 0 seconds.

type ProgressBar Uses

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 Uses

func New(max int) *ProgressBar

New returns a new ProgressBar with the specified maximum

func New64 Uses

func New64(max int64) *ProgressBar

New64 returns a new ProgressBar with the specified maximum

func NewOptions Uses

func NewOptions(max int, options ...Option) *ProgressBar

NewOptions constructs a new instance of ProgressBar, with any options you specify

func NewOptions64 Uses

func NewOptions64(max int64, options ...Option) *ProgressBar

NewOptions64 constructs a new instance of ProgressBar, with any options you specify

func (*ProgressBar) Add Uses

func (p *ProgressBar) Add(num int) error

Add will add the specified amount to the progressbar

func (*ProgressBar) Add64 Uses

func (p *ProgressBar) Add64(num int64) error

Add64 will add the specified amount to the progressbar

func (*ProgressBar) ChangeMax Uses

func (p *ProgressBar) ChangeMax(newMax int)

ChangeMax takes in a int and changes the max value of the progress bar

func (*ProgressBar) ChangeMax64 Uses

func (p *ProgressBar) ChangeMax64(newMax int64)

ChangeMax64 is basically the same as ChangeMax, but takes in a int64 to avoid casting

func (*ProgressBar) Clear Uses

func (p *ProgressBar) Clear() error

Clear erases the progress bar from the current line

func (*ProgressBar) Describe Uses

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 (*ProgressBar) Finish Uses

func (p *ProgressBar) Finish() error

Finish will fill the bar to full

func (*ProgressBar) GetMax Uses

func (p *ProgressBar) GetMax() int

Get the max of a bar

func (*ProgressBar) GetMax64 Uses

func (p *ProgressBar) GetMax64() int64

Same as GetMax, but returns int64

func (*ProgressBar) Read Uses

func (p *ProgressBar) Read(b []byte) (n int, err error)

Read implement io.Reader

func (*ProgressBar) RenderBlank Uses

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 (*ProgressBar) Reset Uses

func (p *ProgressBar) Reset()

Reset will reset the clock that is used to calculate current time and the time left.

func (*ProgressBar) State Uses

func (p *ProgressBar) State() State

State returns the current state

func (*ProgressBar) Write Uses

func (p *ProgressBar) Write(b []byte) (n int, err error)

Write implement io.Writer

type Reader Uses

type Reader struct {
    io.Reader
    // contains filtered or unexported fields
}

Reader is the progressbar io.Reader struct

func (*Reader) Close Uses

func (r *Reader) Close() (err error)

Close the reader when it implements io.Closer

func (*Reader) Read Uses

func (r *Reader) Read(p []byte) (n int, err error)

Read will read the data and add the number of bytes to the progressbar

type State Uses

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 Uses

type Theme struct {
    Saucer        string
    SaucerHead    string
    SaucerPadding string
    BarStart      string
    BarEnd        string
}

Theme defines the elements of the bar

Directories

PathSynopsis
examples

Package progressbar imports 10 packages (graph) and is imported by 21 packages. Updated 2019-11-17. Refresh now. Tools for package owners.