Documentation ¶
Overview ¶
Example (XOutOfY) ¶
bar := NewOptions(100, OptionSetPredictTime(true)) for i := 0; i < 100; i++ { bar.Add(1) time.Sleep(1 * time.Millisecond) }
Output:
Index ¶
- func TerminalWidth() int
- type Bar
- func (p *Bar) Add(num int) error
- func (p *Bar) Add64(num int64) error
- func (p *Bar) ChangeMax(newMax int)
- func (p *Bar) ChangeMax64(newMax int64)
- func (p *Bar) Clear() error
- func (p *Bar) Describe(description string)
- func (p *Bar) Finish() error
- func (p *Bar) GetMax() int
- func (p *Bar) GetMax64() int64
- func (p *Bar) IsFinished() bool
- func (p *Bar) Read(b []byte) (n int, err error)
- func (p *Bar) RenderBlank() error
- func (p *Bar) Reset()
- func (p *Bar) Set(num int) error
- func (p *Bar) Set64(num int64) error
- func (p *Bar) State() State
- func (p *Bar) Write(b []byte) (n int, err error)
- type Option
- func OptionClearOnFinish() Option
- func OptionEnableColorCodes(colorCodes bool) Option
- func OptionFullWidth() Option
- func OptionOnCompletion(completion func()) Option
- func OptionSetDescription(description string) Option
- func OptionSetItsString(iterationString string) Option
- func OptionSetPredictTime(predictTime bool) Option
- func OptionSetRenderBlankState(r bool) Option
- func OptionSetTheme(t Theme) Option
- func OptionSetVisibility(visibility bool) Option
- func OptionSetWidth(s int) Option
- func OptionSetWriter(w io.Writer) Option
- func OptionShowBytes(val bool) Option
- func OptionShowCount() Option
- func OptionShowIts() Option
- func OptionSpinnerType(spinnerType int) Option
- func OptionThrottle(duration time.Duration) Option
- func OptionUseANSICodes(val bool) Option
- type Reader
- type State
- type Theme
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TerminalWidth ¶
func TerminalWidth() int
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar is a thread-safe, simple progress bar
func Default ¶
Default provides a progressbar with recommended defaults. Set max to -1 to use as a spinner.
Example ¶
bar := Default(100) for i := 0; i < 50; i++ { bar.Add(1) time.Sleep(10 * time.Millisecond) }
Output:
func DefaultBytes ¶
DefaultBytes provides a progressbar to measure byte throughput with recommended defaults. Set maxBytes to -1 to use as a spinner.
func NewOptions ¶
NewOptions constructs a new instance of Bar, with any options you specify
func NewOptions64 ¶
NewOptions64 constructs a new instance of Bar, with any options you specify
func (*Bar) ChangeMax64 ¶
ChangeMax64 is basically the same as ChangeMax, but takes in a int64 to avoid casting
func (*Bar) Describe ¶
Describe will change the description shown before the progress, which can be changed on the fly (as for a slow running process).
func (*Bar) IsFinished ¶
IsFinished returns true if progreess bar is completed
func (*Bar) RenderBlank ¶
RenderBlank renders the current bar state, you can use this to render a 0% state
type Option ¶
type Option func(p *Bar)
Option is the type all options need to adhere to
func OptionClearOnFinish ¶
func OptionClearOnFinish() Option
OptionClearOnFinish will clear the bar once its finished
Example ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false), OptionClearOnFinish()) bar.Reset() bar.Finish() fmt.Println("Finished")
Output: Finished
func OptionEnableColorCodes ¶
OptionEnableColorCodes enables or disables support for color codes using mitchellh/colorstring
func OptionOnCompletion ¶
func OptionOnCompletion(completion func()) Option
OptionOnCompletion will invoke completion function once its finished
func OptionSetDescription ¶
OptionSetDescription sets the description of the bar to render in front of it
func OptionSetItsString ¶
OptionSetItsString sets what's displayed for interactions a second. The default is "it" which would display: "it/s"
func OptionSetPredictTime ¶
OptionSetPredictTime will also attempt to predict the time remaining.
Example ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetPredictTime(false)) _ = bar.Add(10)
Output: 10% |█ |
func OptionSetRenderBlankState ¶
OptionSetRenderBlankState sets whether or not to render a 0% bar on construction
Example ¶
NewOptions(10, OptionSetWidth(10), OptionSetRenderBlankState(true))
Output: 0% | | [0s:0s]
func OptionSetTheme ¶
OptionSetTheme sets the elements the bar is constructed of
func OptionSetVisibility ¶
OptionSetVisibility sets the visibility
func OptionSetWriter ¶
OptionSetWriter sets the output writer (defaults to os.StdOut)
func OptionShowBytes ¶
OptionShowBytes will update the progress bar configuration settings to display/hide kBytes/Sec
func OptionShowCount ¶
func OptionShowCount() Option
OptionShowCount will also print current count out of total
func OptionShowIts ¶
func OptionShowIts() Option
OptionShowIts will also print the iterations/second
Example ¶
bar := NewOptions(100, OptionSetWidth(10), OptionShowIts(), OptionSetPredictTime(false)) bar.Reset() time.Sleep(1 * time.Second) bar.Add(10)
Output: 10% |█ | (10 it/s)
Example (Count) ¶
bar := NewOptions(100, OptionSetWidth(10), OptionShowIts(), OptionShowCount()) bar.Reset() time.Sleep(1 * time.Second) bar.Add(10)
Output: 10% |█ | (10/100, 10 it/s) [1s:9s]
func OptionSpinnerType ¶
OptionSpinnerType sets the type of spinner used for indeterminate bars
func OptionThrottle ¶
OptionThrottle will wait the specified duration before updating again. The default duration is 0 seconds.
Example ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false), OptionThrottle(100*time.Millisecond)) bar.Reset() bar.Add(5) time.Sleep(150 * time.Millisecond) bar.Add(5) bar.Add(10)
Output: 10% |█ | [0s:1s]
func OptionUseANSICodes ¶
OptionUseANSICodes will use more optimized terminal i/o.
Only useful in environments with support for ANSI escape sequences.
type Reader ¶
Reader is the progressbar io.Reader struct