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 ¶
- Constants
- Variables
- type FdWriter
- type MultiProgress
- func (m *MultiProgress) Add64Bar(name string, max int64) (*ProgressBar, error)
- func (m *MultiProgress) AddBar(name string, bar *ProgressBar) error
- func (m *MultiProgress) AddDefaultBar(name string, max int64, description ...string) (*ProgressBar, error)
- func (m *MultiProgress) BarAdd(name string, n int)
- func (m *MultiProgress) BarAdd64(name string, n int64)
- func (m *MultiProgress) BarChangeMax(name string, max int)
- func (m *MultiProgress) BarChangeMax64(name string, max int64)
- func (m *MultiProgress) BarDescribe(name string, desc string)
- func (m *MultiProgress) BarFinish(name string)
- func (m *MultiProgress) BarSet(name string, n int)
- func (m *MultiProgress) BarSet64(name string, n int64)
- func (m *MultiProgress) Listen()
- func (m *MultiProgress) SetRefreshInterval(t time.Duration)
- func (m *MultiProgress) Start()
- func (m *MultiProgress) Stop()
- type Option
- func OptionClearOnFinish() Option
- func OptionEnableColorCodes(colorCodes bool) Option
- func OptionFullWidth() Option
- func OptionOnCompletion(cmpl 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 ProgressBar
- func Default(max int64, description ...string) *ProgressBar
- func DefaultBytes(maxBytes int64, description ...string) *ProgressBar
- func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar
- func DefaultSilent(max int64, description ...string) *ProgressBar
- func New(max int) *ProgressBar
- func New64(max int64) *ProgressBar
- func NewOptions(max int, options ...Option) *ProgressBar
- func NewOptions64(max int64, options ...Option) *ProgressBar
- func (p *ProgressBar) Add(num int) error
- func (p *ProgressBar) Add64(num int64) error
- func (p *ProgressBar) ChangeMax(newMax int)
- func (p *ProgressBar) ChangeMax64(newMax int64)
- func (p *ProgressBar) Clear() error
- func (p *ProgressBar) Close() (err error)
- func (p *ProgressBar) Describe(description string)
- func (p *ProgressBar) Finish() error
- func (p *ProgressBar) GetMax() int
- func (p *ProgressBar) GetMax64() int64
- func (p *ProgressBar) IsFinished() bool
- func (p *ProgressBar) Read(b []byte) (n int, err error)
- func (p *ProgressBar) RenderBlank() error
- func (p *ProgressBar) Reset()
- func (p *ProgressBar) Set(num int) error
- func (p *ProgressBar) Set64(num int64) error
- func (p *ProgressBar) State() State
- func (p *ProgressBar) String() string
- func (p *ProgressBar) Write(b []byte) (n int, err error)
- type Reader
- type State
- type Theme
- type Writer
Examples ¶
Constants ¶
const ESC = 27
ESC is the ASCII code for escape character
Variables ¶
var ErrClosedPipe = errors.New("uiprogress: read/write on closed pipe")
ErrClosedPipe is the error returned when trying to writer is not listening
var Out = os.Stdout
var RefreshInterval = time.Millisecond * 50
Functions ¶
This section is empty.
Types ¶
type MultiProgress ¶
type MultiProgress struct { Out io.Writer RefreshInterval time.Duration // contains filtered or unexported fields }
func NewMultiProgress ¶
func NewMultiProgress() *MultiProgress
func (*MultiProgress) Add64Bar ¶
func (m *MultiProgress) Add64Bar(name string, max int64) (*ProgressBar, error)
func (*MultiProgress) AddBar ¶
func (m *MultiProgress) AddBar(name string, bar *ProgressBar) error
func (*MultiProgress) AddDefaultBar ¶
func (m *MultiProgress) AddDefaultBar(name string, max int64, description ...string) (*ProgressBar, error)
func (*MultiProgress) BarAdd ¶
func (m *MultiProgress) BarAdd(name string, n int)
func (*MultiProgress) BarAdd64 ¶
func (m *MultiProgress) BarAdd64(name string, n int64)
func (*MultiProgress) BarChangeMax ¶
func (m *MultiProgress) BarChangeMax(name string, max int)
func (*MultiProgress) BarChangeMax64 ¶
func (m *MultiProgress) BarChangeMax64(name string, max int64)
func (*MultiProgress) BarDescribe ¶ added in v4.0.5
func (m *MultiProgress) BarDescribe(name string, desc string)
func (*MultiProgress) BarFinish ¶ added in v4.0.5
func (m *MultiProgress) BarFinish(name string)
func (*MultiProgress) BarSet ¶
func (m *MultiProgress) BarSet(name string, n int)
func (*MultiProgress) BarSet64 ¶
func (m *MultiProgress) BarSet64(name string, n int64)
func (*MultiProgress) Listen ¶
func (m *MultiProgress) Listen()
func (*MultiProgress) SetRefreshInterval ¶
func (m *MultiProgress) SetRefreshInterval(t time.Duration)
func (*MultiProgress) Start ¶
func (m *MultiProgress) Start()
func (*MultiProgress) Stop ¶
func (m *MultiProgress) Stop()
type Option ¶
type Option func(p *ProgressBar)
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(cmpl func()) Option
OptionOnCompletion will invoke cmpl 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 interations 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 ProgressBar ¶
type ProgressBar struct {
// contains filtered or unexported fields
}
ProgressBar is a thread-safe, simple progress bar
Example ¶
bar := New(100) bar.Add(10)
Output: 10% |████ | [0s:0s]
Example (Basic) ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false)) bar.Reset() time.Sleep(1 * time.Second) bar.Add(10)
Output: 10% |█ | [1s:9s]
Example (Invisible) ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false), OptionSetVisibility(false)) bar.Reset() bar.RenderBlank() fmt.Println("hello, world") time.Sleep(1 * time.Second) bar.Add(10)
Output: hello, world
func Default ¶
func Default(max int64, description ...string) *ProgressBar
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 ¶
func DefaultBytes(maxBytes int64, description ...string) *ProgressBar
DefaultBytes provides a progressbar to measure byte throughput with recommended defaults. Set maxBytes to -1 to use as a spinner.
func DefaultBytesSilent ¶
func DefaultBytesSilent(maxBytes int64, description ...string) *ProgressBar
DefaultBytesSilent is the same as DefaultBytes, but does not output anywhere. String() can be used to get the output instead.
func DefaultSilent ¶
func DefaultSilent(max int64, description ...string) *ProgressBar
DefaultSilent is the same as Default, but does not output anywhere. String() can be used to get the output instead.
func New64 ¶
func New64(max int64) *ProgressBar
New64 returns a new ProgressBar with the specified maximum
func NewOptions ¶
func NewOptions(max int, options ...Option) *ProgressBar
NewOptions constructs a new instance of ProgressBar, with any options you specify
func NewOptions64 ¶
func NewOptions64(max int64, options ...Option) *ProgressBar
NewOptions64 constructs a new instance of ProgressBar, with any options you specify
func (*ProgressBar) Add ¶
func (p *ProgressBar) Add(num int) error
Add will add the specified amount to the progressbar
func (*ProgressBar) Add64 ¶
func (p *ProgressBar) Add64(num int64) error
Add64 will add the specified amount to the progressbar
func (*ProgressBar) ChangeMax ¶
func (p *ProgressBar) ChangeMax(newMax int)
ChangeMax takes in a int and changes the max value of the progress bar
func (*ProgressBar) ChangeMax64 ¶
func (p *ProgressBar) ChangeMax64(newMax int64)
ChangeMax64 is basically the same as ChangeMax, but takes in a int64 to avoid casting
func (*ProgressBar) Clear ¶
func (p *ProgressBar) Clear() error
Clear erases the progress bar from the current line
func (*ProgressBar) Close ¶
func (p *ProgressBar) Close() (err error)
func (*ProgressBar) Describe ¶
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 ¶
func (p *ProgressBar) Finish() error
Finish will fill the bar to full
Example ¶
bar := NewOptions(100, OptionSetWidth(10), OptionSetRenderBlankState(false)) bar.Finish()
Output: 100% |██████████|
func (*ProgressBar) GetMax64 ¶
func (p *ProgressBar) GetMax64() int64
GetMax64 returns the current max
func (*ProgressBar) IsFinished ¶
func (p *ProgressBar) IsFinished() bool
IsFinished returns true if progreess bar is completed
func (*ProgressBar) Read ¶
func (p *ProgressBar) Read(b []byte) (n int, err error)
Read implement io.Reader
func (*ProgressBar) RenderBlank ¶
func (p *ProgressBar) RenderBlank() error
RenderBlank renders the current bar state, you can use this to render a 0% state
func (*ProgressBar) Reset ¶
func (p *ProgressBar) Reset()
Reset will reset the clock that is used to calculate current time and the time left.
func (*ProgressBar) Set ¶
func (p *ProgressBar) Set(num int) error
Set wil set the bar to a current number
Example ¶
bar := New(100) bar.Set(10)
Output: 10% |████ | [0s:0s]
func (*ProgressBar) Set64 ¶
func (p *ProgressBar) Set64(num int64) error
Set64 wil set the bar to a current number
Example ¶
bar := New(100) bar.Set64(10)
Output: 10% |████ | [0s:0s]
func (*ProgressBar) String ¶
func (p *ProgressBar) String() string
String returns the current rendered version of the progress bar. It will never return an empty string while the progress bar is running.
type Reader ¶
Reader is the progressbar io.Reader struct
func NewReader ¶
func NewReader(r io.Reader, bar *ProgressBar) Reader
NewReader return a new Reader with a given progress bar.
type State ¶
type State struct { CurrentPercent float64 CurrentBytes float64 SecondsSince float64 SecondsLeft float64 KBsPerSecond float64 }
State is the basic properties of the bar
type Theme ¶
type Theme struct { Saucer string AltSaucerHead string SaucerHead string SaucerPadding string BarStart string BarEnd string }
Theme defines the elements of the bar
type Writer ¶
type Writer struct { // Out is the writer to write to Out io.Writer // RefreshInterval is the time the UI sould refresh RefreshInterval time.Duration // contains filtered or unexported fields }
Writer is a buffered the writer that updates the terminal. The contents of writer will be flushed on a timed interval or when Flush is called.
func (*Writer) Bypass ¶
Bypass creates an io.Writer which allows non-buffered output to be written to the underlying output
func (*Writer) Flush ¶
Flush writes to the out and resets the buffer. It should be called after the last call to Write to ensure that any data buffered in the Writer is written to output. Any incomplete escape sequence at the end is considered complete for formatting purposes. An error is returned if the contents of the buffer cannot be written to the underlying output stream
func (*Writer) Listen ¶
func (w *Writer) Listen()
Listen listens for updates to the writer's buffer and flushes to the out provided. It blocks the runtime.