Documentation ¶
Index ¶
- Constants
- Variables
- type Bar
- func (b *Bar) Abort(drop bool)
- func (b *Bar) Completed() bool
- func (b *Bar) Current() int64
- func (b *Bar) DecoratorAverageAdjust(start time.Time)
- func (b *Bar) DecoratorEwmaUpdate(dur time.Duration)
- func (b *Bar) GetContainer() *Progress
- func (b *Bar) ID() int
- func (b *Bar) IncrBy(n int)
- func (b *Bar) IncrInt64(n int64)
- func (b *Bar) Increment()
- func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser
- func (b *Bar) SetCurrent(current int64)
- func (b *Bar) SetPriority(priority int)
- func (b *Bar) SetRefill(amount int64)
- func (b *Bar) SetTotal(total int64, complete bool)
- func (b *Bar) TraverseDecorators(cb func(decor.Decorator))
- type BarFiller
- type BarFillerFunc
- type BarOption
- func AppendDecorators(decorators ...decor.Decorator) BarOption
- func BarExtender(filler BarFiller) BarOption
- func BarFillerClearOnComplete() BarOption
- func BarFillerMiddleware(middle func(BarFiller) BarFiller) BarOption
- func BarFillerOnComplete(message string) BarOption
- func BarID(id int) BarOption
- func BarNoPop() BarOption
- func BarOptOn(option BarOption, condition func() bool) BarOption
- func BarPriority(priority int) BarOption
- func BarQueueAfter(runningBar *Bar) BarOption
- func BarRemoveOnComplete() BarOption
- func BarReverse() BarOption
- func BarStyle(style string) BarOption
- func BarWidth(width int) BarOption
- func MakeFillerTypeSpecificBarOption(typeChecker func(BarFiller) (interface{}, bool), cb func(interface{})) BarOption
- func PrependDecorators(decorators ...decor.Decorator) BarOption
- func SpinnerStyle(frames []string) BarOption
- func TrimSpace() BarOption
- type ContainerOption
- func ContainerOptOn(option ContainerOption, condition func() bool) ContainerOption
- func PopCompletedMode() ContainerOption
- func WithDebugOutput(w io.Writer) ContainerOption
- func WithManualRefresh(ch <-chan time.Time) ContainerOption
- func WithOutput(w io.Writer) ContainerOption
- func WithRefreshRate(d time.Duration) ContainerOption
- func WithRenderDelay(ch <-chan struct{}) ContainerOption
- func WithShutdownNotifier(ch chan struct{}) ContainerOption
- func WithWaitGroup(wg *sync.WaitGroup) ContainerOption
- func WithWidth(width int) ContainerOption
- type LogFiller
- type Progress
- func (p *Progress) Add(total int64, filler BarFiller, options ...BarOption) *Bar
- func (p *Progress) AddBar(total int64, options ...BarOption) *Bar
- func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar
- func (p *Progress) BarCount() int
- func (p *Progress) Log(message string) *Progress
- func (p *Progress) LogWithPriority(message string, priority int) *Progress
- func (p *Progress) NewLine() *Progress
- func (p *Progress) NewLineWithPriority(priority int) *Progress
- func (p *Progress) UpdateBarPriority(b *Bar, priority int)
- func (p *Progress) Wait()
- type SpinnerAlignment
Constants ¶
const DefaultBarStyle string = "[=>-]<+"
DefaultBarStyle is a string containing 7 runes. Each rune is a building block of a progress bar.
'1st rune' stands for left boundary rune '2nd rune' stands for fill rune '3rd rune' stands for tip rune '4th rune' stands for space rune '5th rune' stands for right boundary rune '6th rune' stands for reverse tip rune '7th rune' stands for refill rune
Variables ¶
var DefaultSpinnerStyle = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
DefaultSpinnerStyle is a slice of strings, which makes a spinner.
Functions ¶
This section is empty.
Types ¶
type Bar ¶ added in v1.22.0
type Bar struct {
// contains filtered or unexported fields
}
Bar represents a progress Bar.
func (*Bar) Abort ¶ added in v1.22.0
Abort interrupts bar's running goroutine. Call this, if you'd like to stop/remove bar before completion event. It has no effect after completion event. If drop is true bar will be removed as well.
func (*Bar) Current ¶ added in v1.22.0
Current returns bar's current number, in other words sum of all increments.
func (*Bar) DecoratorAverageAdjust ¶ added in v1.22.0
DecoratorAverageAdjust adjusts all average based decorators. Call if you need to adjust start time of all average based decorators or after progress resume.
func (*Bar) DecoratorEwmaUpdate ¶ added in v1.22.0
DecoratorEwmaUpdate updates all EWMA based decorators. Should be called on each iteration, because EWMA's unit of measure is an iteration's duration. Panics if called before *Bar.Incr... family methods.
func (*Bar) GetContainer ¶ added in v1.22.0
GetContainer returns the parent Progress
func (*Bar) Increment ¶ added in v1.22.0
func (b *Bar) Increment()
Increment is a shorthand for b.IncrInt64(1).
func (*Bar) ProxyReader ¶ added in v1.22.0
func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser
ProxyReader wraps r with metrics required for progress tracking. Panics if r is nil.
func (*Bar) SetCurrent ¶ added in v1.22.0
SetCurrent sets progress' current to an arbitrary value. Setting a negative value will cause a panic.
func (*Bar) SetPriority ¶ added in v1.22.0
SetPriority changes bar's order among multiple bars. Zero is highest priority, i.e. bar will be on top. If you don't need to set priority dynamically, better use BarPriority option.
func (*Bar) SetRefill ¶ added in v1.22.0
SetRefill fills bar with refill rune up to amount argument. Given default bar style is "[=>-]<+", refill rune is '+'. To set bar style use mpb.BarStyle(string) BarOption.
func (*Bar) SetTotal ¶ added in v1.22.0
SetTotal sets total dynamically. If total is less than or equal to zero it takes progress' current value. A complete flag enables or disables complete event on `current >= total`.
func (*Bar) TraverseDecorators ¶ added in v1.22.0
TraverseDecorators traverses all available decorators and calls cb func on each.
type BarFiller ¶ added in v1.22.0
type BarFiller interface {
Fill(w io.Writer, reqWidth int, stat decor.Statistics)
}
BarFiller interface. Bar (without decorators) renders itself by calling BarFiller's Fill method.
`reqWidth` is requested width, which is set via: func WithWidth(width int) ContainerOption func BarWidth(width int) BarOption
Default implementations can be obtained via:
func NewBarFiller(style string, reverse bool) BarFiller func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller
func NewBarFiller ¶ added in v1.22.0
NewBarFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
func NewSpinnerFiller ¶ added in v1.22.0
func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller
NewSpinnerFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
type BarFillerFunc ¶ added in v1.22.0
type BarFillerFunc func(w io.Writer, reqWidth int, stat decor.Statistics)
BarFillerFunc is function type adapter to convert function into BarFiller.
func (BarFillerFunc) Fill ¶ added in v1.22.0
func (f BarFillerFunc) Fill(w io.Writer, reqWidth int, stat decor.Statistics)
type BarOption ¶ added in v1.22.0
type BarOption func(*bState)
BarOption is a function option which changes the default behavior of a bar.
func AppendDecorators ¶ added in v1.22.0
AppendDecorators let you inject decorators to the bar's right side.
func BarExtender ¶ added in v1.22.0
BarExtender is an option to extend bar to the next new line, with arbitrary output.
func BarFillerClearOnComplete ¶ added in v1.22.0
func BarFillerClearOnComplete() BarOption
BarFillerClearOnComplete clears bar's filler on complete event. It's shortcut for BarFillerOnComplete("").
func BarFillerMiddleware ¶ added in v1.22.0
BarFillerMiddleware provides a way to augment default BarFiller.
func BarFillerOnComplete ¶ added in v1.22.0
BarFillerOnComplete replaces bar's filler with message, on complete event.
func BarNoPop ¶ added in v1.22.0
func BarNoPop() BarOption
BarNoPop disables bar pop out of container. Effective when PopCompletedMode of container is enabled.
func BarPriority ¶ added in v1.22.0
BarPriority sets bar's priority. Zero is highest priority, i.e. bar will be on top. If `BarReplaceOnComplete` option is supplied, this option is ignored.
func BarQueueAfter ¶ added in v1.22.0
BarQueueAfter queues this (being constructed) bar to relplace runningBar after it has been completed.
func BarRemoveOnComplete ¶ added in v1.22.0
func BarRemoveOnComplete() BarOption
BarRemoveOnComplete removes both bar's filler and its decorators on complete event.
func BarReverse ¶ added in v1.22.0
func BarReverse() BarOption
BarReverse reverse mode, bar will progress from right to left.
func BarStyle ¶ added in v1.22.0
BarStyle overrides mpb.DefaultBarStyle which is "[=>-]<+". It's ok to pass string containing just 5 runes, for example "╢▌▌░╟", if you don't need to override '<' (reverse tip) and '+' (refill rune).
func MakeFillerTypeSpecificBarOption ¶ added in v1.22.0
func MakeFillerTypeSpecificBarOption( typeChecker func(BarFiller) (interface{}, bool), cb func(interface{}), ) BarOption
MakeFillerTypeSpecificBarOption makes BarOption specific to Filler's actual type. If you implement your own Filler, so most probably you'll need this. See BarStyle or SpinnerStyle for example.
func PrependDecorators ¶ added in v1.22.0
PrependDecorators let you inject decorators to the bar's left side.
func SpinnerStyle ¶ added in v1.22.0
SpinnerStyle sets custom spinner style. Effective when Filler type is spinner.
type ContainerOption ¶ added in v1.22.0
type ContainerOption func(*pState)
ContainerOption is a function option which changes the default behavior of progress container, if passed to mpb.New(...ContainerOption).
func ContainerOptOn ¶ added in v1.22.0
func ContainerOptOn(option ContainerOption, condition func() bool) ContainerOption
ContainerOptOn returns option when condition evaluates to true.
func PopCompletedMode ¶ added in v1.22.0
func PopCompletedMode() ContainerOption
PopCompletedMode will pop and stop rendering completed bars.
func WithDebugOutput ¶ added in v1.22.0
func WithDebugOutput(w io.Writer) ContainerOption
WithDebugOutput sets debug output.
func WithManualRefresh ¶ added in v1.22.0
func WithManualRefresh(ch <-chan time.Time) ContainerOption
WithManualRefresh disables internal auto refresh time.Ticker. Refresh will occur upon receive value from provided ch.
func WithOutput ¶ added in v1.22.0
func WithOutput(w io.Writer) ContainerOption
WithOutput overrides default os.Stdout output. Setting it to nil will effectively disable auto refresh rate and discard any output, useful if you want to disable progress bars with little overhead.
func WithRefreshRate ¶ added in v1.22.0
func WithRefreshRate(d time.Duration) ContainerOption
WithRefreshRate overrides default 120ms refresh rate.
func WithRenderDelay ¶ added in v1.22.0
func WithRenderDelay(ch <-chan struct{}) ContainerOption
WithRenderDelay delays rendering. By default rendering starts as soon as bar is added, with this option it's possible to delay rendering process by keeping provided chan unclosed. In other words rendering will start as soon as provided chan is closed.
func WithShutdownNotifier ¶ added in v1.22.0
func WithShutdownNotifier(ch chan struct{}) ContainerOption
WithShutdownNotifier provided chanel will be closed, after all bars have been rendered.
func WithWaitGroup ¶ added in v1.22.0
func WithWaitGroup(wg *sync.WaitGroup) ContainerOption
WithWaitGroup provides means to have a single joint point. If *sync.WaitGroup is provided, you can safely call just p.Wait() without calling Wait() on provided *sync.WaitGroup. Makes sense when there are more than one bar to render.
func WithWidth ¶ added in v1.22.0
func WithWidth(width int) ContainerOption
WithWidth sets container width. If not set underlying bars will occupy whole term width.
type LogFiller ¶ added in v1.22.0
type LogFiller struct {
Message string
}
func MultiBarLog ¶ added in v1.22.0
type Progress ¶ added in v1.22.0
type Progress struct {
// contains filtered or unexported fields
}
Progress represents the container that renders Progress bars
func New ¶
func New(options ...ContainerOption) *Progress
New creates new Progress container instance. It's not possible to reuse instance after *Progress.Wait() method has been called.
func NewWithContext ¶ added in v1.22.0
func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress
NewWithContext creates new Progress container instance with provided context. It's not possible to reuse instance after *Progress.Wait() method has been called.
func (*Progress) Add ¶ added in v1.22.0
Add creates a bar which renders itself by provided filler. Set total to 0, if you plan to update it later. Panics if *Progress instance is done, i.e. called after *Progress.Wait().
func (*Progress) AddBar ¶ added in v1.22.0
AddBar creates a new progress bar and adds it to the rendering queue.
func (*Progress) AddSpinner ¶ added in v1.22.0
func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options ...BarOption) *Bar
AddSpinner creates a new spinner bar and adds it to the rendering queue.
func (*Progress) LogWithPriority ¶ added in v1.22.0
LogWithPriority logs a message with a priority. The higher the priority, the higher the message will be.
func (*Progress) NewLineWithPriority ¶ added in v1.22.0
NewLineWithPriority logs a new empty line in a running progressbar with a specific priority
func (*Progress) UpdateBarPriority ¶ added in v1.22.0
UpdateBarPriority same as *Bar.SetPriority(int).
type SpinnerAlignment ¶ added in v1.22.0
type SpinnerAlignment int
SpinnerAlignment enum.
const ( SpinnerOnLeft SpinnerAlignment = iota SpinnerOnMiddle SpinnerOnRight )
SpinnerAlignment kinds.