Documentation
¶
Overview ¶
Package mpb is a library for rendering progress bars in terminal applications.
Example ¶
package main import ( "math/rand" "time" "github.com/vbauerster/mpb" "github.com/vbauerster/mpb/decor" ) func main() { p := mpb.New( // override default (80) width mpb.WithWidth(64), // override default "[=>-]" format mpb.WithFormat("╢▌▌░╟"), // override default 120ms refresh rate mpb.WithRefreshRate(180*time.Millisecond), ) total := 100 name := "Single Bar:" // adding a single bar bar := p.AddBar(int64(total), mpb.PrependDecorators( // display our name with one space on the right decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}), // replace ETA decorator with "done" message, OnComplete event decor.OnComplete( // ETA decorator with ewma age of 60, and width reservation of 4 decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}), "done", ), ), mpb.AppendDecorators(decor.Percentage()), ) // simulating some work max := 100 * time.Millisecond for i := 0; i < total; i++ { start := time.Now() time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) // ewma based decorators require work duration measurement bar.IncrBy(1, time.Since(start)) } // wait for our bar to complete and flush p.Wait() }
Output:
Index ¶
- type Bar
- func (b *Bar) Completed() bool
- func (b *Bar) Current() int64
- func (b *Bar) ID() int
- func (b *Bar) IncrBy(n int, wdd ...time.Duration)
- func (b *Bar) Increment()
- func (b *Bar) NumOfAppenders() int
- func (b *Bar) NumOfPrependers() int
- func (b *Bar) ProxyReader(r io.Reader) *Reader
- func (b *Bar) RefillBy(n int, r rune)
- func (b *Bar) RemoveAllAppenders()
- func (b *Bar) RemoveAllPrependers()
- func (b *Bar) SetTotal(total int64, final bool)
- func (b *Bar) Total() int64
- type BarOption
- func AppendDecorators(appenders ...decor.Decorator) BarOption
- func BarAutoIncrTotal(trigger, n int64) BarOption
- func BarClearOnComplete() BarOption
- func BarDynamicTotal() BarOption
- func BarID(id int) BarOption
- func BarPriority(priority int) BarOption
- func BarRemoveOnComplete() BarOption
- func BarReplaceOnComplete(runningBar *Bar) BarOption
- func BarTrim() BarOption
- func BarTrimLeft() BarOption
- func BarTrimRight() BarOption
- func PrependDecorators(prependers ...decor.Decorator) BarOption
- type Progress
- type ProgressOption
- func WithCancel(ch <-chan struct{}) ProgressOption
- func WithContext(ctx context.Context) ProgressOption
- func WithDebugOutput(w io.Writer) ProgressOption
- func WithFormat(format string) ProgressOption
- func WithInterceptors(interseptors ...func(io.Writer)) ProgressOption
- func WithOutput(w io.Writer) ProgressOption
- func WithRefreshRate(d time.Duration) ProgressOption
- func WithShutdownNotifier(ch chan struct{}) ProgressOption
- func WithWaitGroup(wg *sync.WaitGroup) ProgressOption
- func WithWidth(w int) ProgressOption
- type Reader
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar struct {
// contains filtered or unexported fields
}
Bar represents a progress Bar
func (*Bar) Completed ¶ added in v3.2.0
Completed reports whether the bar is in completed state.
Example ¶
package main import ( "math/rand" "time" "github.com/vbauerster/mpb" ) func main() { p := mpb.New() bar := p.AddBar(100) max := 100 * time.Millisecond for !bar.Completed() { time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10) bar.Increment() } p.Wait() }
Output:
func (*Bar) IncrBy ¶ added in v3.1.0
IncrBy increments progress bar by amount of n. wdd is optional work duration i.e. time.Since(start), which expected to be provided, if any ewma based decorator is used.
func (*Bar) Increment ¶ added in v3.0.3
func (b *Bar) Increment()
Increment is a shorthand for b.IncrBy(1).
func (*Bar) NumOfAppenders ¶
NumOfAppenders returns current number of append decorators.
func (*Bar) NumOfPrependers ¶
NumOfPrependers returns current number of prepend decorators.
func (*Bar) ProxyReader ¶
ProxyReader allows progress tracking against provided io.Reader.
Example ¶
package main import ( "io" "io/ioutil" "net/http" "github.com/vbauerster/mpb" "github.com/vbauerster/mpb/decor" ) func main() { p := mpb.New() // make http get request, ignoring errors resp, _ := http.Get("https://homebrew.bintray.com/bottles/libtiff-4.0.7.sierra.bottle.tar.gz") defer resp.Body.Close() // Assuming ContentLength > 0 bar := p.AddBar(resp.ContentLength, mpb.AppendDecorators( decor.CountersKibiByte("%6.1f / %6.1f"), ), ) // create proxy reader reader := bar.ProxyReader(resp.Body) // and copy from reader, ignoring errors io.Copy(ioutil.Discard, reader) p.Wait() }
Output:
func (*Bar) RemoveAllAppenders ¶
func (b *Bar) RemoveAllAppenders()
RemoveAllAppenders removes all append functions.
func (*Bar) RemoveAllPrependers ¶
func (b *Bar) RemoveAllPrependers()
RemoveAllPrependers removes all prepend functions.
type BarOption ¶
type BarOption func(*bState)
BarOption is a function option which changes the default behavior of a bar, if passed to p.AddBar(int64, ...BarOption)
func AppendDecorators ¶
AppendDecorators let you inject decorators to the bar's right side
func BarAutoIncrTotal ¶ added in v3.0.4
BarAutoIncrTotal auto increment total by n, when trigger percentage remained till bar completion. In other words: say you've set trigger = 10, then auto increment will start after bar reaches 90 %. Effective only if BarDynamicTotal option is set.
func BarClearOnComplete ¶ added in v3.3.0
func BarClearOnComplete() BarOption
BarClearOnComplete is a flag, if set will clear bar section on complete event. If you need to remove a whole bar line, refer to BarRemoveOnComplete.
func BarDynamicTotal ¶ added in v3.0.4
func BarDynamicTotal() BarOption
BarDynamicTotal is a flag, if set enables dynamic total behaviour. If provided total <= 0, it is set implicitly.
func BarPriority ¶ added in v3.3.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 BarRemoveOnComplete ¶ added in v3.3.0
func BarRemoveOnComplete() BarOption
BarRemoveOnComplete is a flag, if set whole bar line will be removed on complete event. If both BarRemoveOnComplete and BarClearOnComplete are set, first bar section gets cleared and then whole bar line gets removed completely.
func BarReplaceOnComplete ¶ added in v3.3.0
BarReplaceOnComplete is indicator for delayed bar start, after the `runningBar` is complete. To achieve bar replacement effect, `runningBar` should has its `BarRemoveOnComplete` option set.
func PrependDecorators ¶
PrependDecorators let you inject decorators to the bar's left side
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
Progress represents the container that renders Progress bars
func New ¶
func New(options ...ProgressOption) *Progress
New creates new Progress instance, which orchestrates bars rendering process. Accepts mpb.ProgressOption funcs for customization.
func (*Progress) Abort ¶ added in v3.3.0
Abort is only effective while bar progress is running, it means remove bar now without waiting for its completion. If bar is already completed, there is nothing to abort. If you need to remove bar after completion, use BarRemoveOnComplete BarOption.
func (*Progress) UpdateBarPriority ¶ added in v3.1.0
UpdateBarPriority provides a way to change bar's order position. Zero is highest priority, i.e. bar will be on top.
type ProgressOption ¶
type ProgressOption func(*pState)
ProgressOption is a function option which changes the default behavior of progress pool, if passed to mpb.New(...ProgressOption)
func WithCancel ¶
func WithCancel(ch <-chan struct{}) ProgressOption
WithCancel provide your cancel channel, which you plan to close at some point.
func WithContext ¶
func WithContext(ctx context.Context) ProgressOption
WithContext provided context will be used for cancellation purposes
func WithDebugOutput ¶ added in v3.3.0
func WithDebugOutput(w io.Writer) ProgressOption
WithDebugOutput sets debug output.
func WithFormat ¶
func WithFormat(format string) ProgressOption
WithFormat overrides default bar format "[=>-]"
func WithInterceptors ¶ added in v3.3.0
func WithInterceptors(interseptors ...func(io.Writer)) ProgressOption
WithInterceptors provides a way to write to the underlying progress pool's writer. Could be useful if you want to output something below the bars, while they're rendering.
func WithOutput ¶ added in v3.3.0
func WithOutput(w io.Writer) ProgressOption
WithOutput overrides default output os.Stdout
func WithRefreshRate ¶
func WithRefreshRate(d time.Duration) ProgressOption
WithRefreshRate overrides default 120ms refresh rate
func WithShutdownNotifier ¶
func WithShutdownNotifier(ch chan struct{}) ProgressOption
WithShutdownNotifier provided chanel will be closed, after all bars have been rendered.
func WithWaitGroup ¶ added in v3.0.3
func WithWaitGroup(wg *sync.WaitGroup) ProgressOption
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.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package decor contains common decorators used by "github.com/vbauerster/mpb" package.
|
Package decor contains common decorators used by "github.com/vbauerster/mpb" package. |
examples
|
|