pax_global_header 0000666 0000000 0000000 00000000064 14473125130 0014512 g ustar 00root root 0000000 0000000 52 comment=9fd271cd98a7a2024bfd5f277fe00a03fc1a74e5
mpb-8.6.1/ 0000775 0000000 0000000 00000000000 14473125130 0012304 5 ustar 00root root 0000000 0000000 mpb-8.6.1/.github/ 0000775 0000000 0000000 00000000000 14473125130 0013644 5 ustar 00root root 0000000 0000000 mpb-8.6.1/.github/workflows/ 0000775 0000000 0000000 00000000000 14473125130 0015701 5 ustar 00root root 0000000 0000000 mpb-8.6.1/.github/workflows/golangci-lint.yml 0000664 0000000 0000000 00000002150 14473125130 0021151 0 ustar 00root root 0000000 0000000 name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
- main
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
golangci:
strategy:
matrix:
go-version: ['stable']
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
cache: false
- uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
# Optional: working directory, useful for monorepos
# working-directory: somedir
# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true
mpb-8.6.1/.github/workflows/test.yml 0000664 0000000 0000000 00000000754 14473125130 0017411 0 ustar 00root root 0000000 0000000 name: test
on:
push:
tags:
- v*
branches:
- master
- v*
pull_request:
permissions:
contents: read
pull-requests: read
jobs:
test:
strategy:
matrix:
go-version: ['stable', 'oldstable']
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- run: go test -race ./...
mpb-8.6.1/.gitignore 0000664 0000000 0000000 00000000173 14473125130 0014275 0 ustar 00root root 0000000 0000000 # Test binary, build with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
mpb-8.6.1/CONTRIBUTING 0000664 0000000 0000000 00000001201 14473125130 0014130 0 ustar 00root root 0000000 0000000 When contributing your first changes, please include an empty commit for
copyright waiver using the following message (replace 'John Doe' with
your name or nickname):
John Doe Copyright Waiver
I dedicate any and all copyright interest in this software to the
public domain. I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors. I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.
The command to create an empty commit from the command-line is:
git commit --allow-empty
mpb-8.6.1/README.md 0000664 0000000 0000000 00000010156 14473125130 0013566 0 ustar 00root root 0000000 0000000 # Multi Progress Bar
[](https://pkg.go.dev/github.com/vbauerster/mpb/v8)
[](https://github.com/vbauerster/mpb/actions/workflows/test.yml)
[](https://github.com/vbauerster/mpb/actions/workflows/golangci-lint.yml)
**mpb** is a Go lib for rendering progress bars in terminal applications.
## Features
- **Multiple Bars**: Multiple progress bars are supported
- **Dynamic Total**: Set total while bar is running
- **Dynamic Add/Remove**: Dynamically add or remove bars
- **Cancellation**: Cancel whole rendering process
- **Predefined Decorators**: Elapsed time, [ewma](https://github.com/VividCortex/ewma) based ETA, Percentage, Bytes counter
- **Decorator's width sync**: Synchronized decorator's width among multiple bars
## Usage
#### [Rendering single bar](_examples/singleBar/main.go)
```go
package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(64))
total := 100
name := "Single Bar:"
// create a single bar, which will inherit container's width
bar := p.New(int64(total),
// BarFillerBuilder with custom style
mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟"),
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(
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
),
),
mpb.AppendDecorators(decor.Percentage()),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
```
#### [Rendering multiple bars](_examples/multiBars/main.go)
```go
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
```
#### [Dynamic total](_examples/dynTotal/main.go)

#### [Complex example](_examples/complex/main.go)

#### [Bytes counters](_examples/io/main.go)

mpb-8.6.1/UNLICENSE 0000664 0000000 0000000 00000002273 14473125130 0013560 0 ustar 00root root 0000000 0000000 This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to
mpb-8.6.1/_examples/ 0000775 0000000 0000000 00000000000 14473125130 0014261 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/.gitignore 0000664 0000000 0000000 00000000007 14473125130 0016246 0 ustar 00root root 0000000 0000000 go.sum
mpb-8.6.1/_examples/barExtender/ 0000775 0000000 0000000 00000000000 14473125130 0016524 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/barExtender/go.mod 0000664 0000000 0000000 00000000574 14473125130 0017640 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/barExtender
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/barExtender/main.go 0000664 0000000 0000000 00000003124 14473125130 0017777 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
efn := func(w io.Writer, s decor.Statistics) (err error) {
if s.Completed {
_, err = fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID)
}
return err
}
bar := p.AddBar(int64(total),
mpb.BarExtender(mpb.BarFillerFunc(efn), false),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/barExtenderRev/ 0000775 0000000 0000000 00000000000 14473125130 0017201 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/barExtenderRev/go.mod 0000664 0000000 0000000 00000000577 14473125130 0020320 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/barExtenderRev
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/barExtenderRev/main.go 0000664 0000000 0000000 00000005215 14473125130 0020457 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
"math/rand"
"sync/atomic"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
var curTask uint32
var doneTasks uint32
type task struct {
id uint32
total int64
bar *mpb.Bar
}
func main() {
numTasks := 4
var total int64
var filler mpb.BarFiller
tasks := make([]*task, numTasks)
for i := 0; i < numTasks; i++ {
task := &task{
id: uint32(i),
total: rand.Int63n(666) + 100,
}
total += task.total
filler = middleware(filler, task.id)
tasks[i] = task
}
filler = newLineMiddleware(filler)
p := mpb.New()
for i := 0; i < numTasks; i++ {
bar := p.AddBar(tasks[i].total,
mpb.BarExtender(filler, true), // all bars share same extender filler
mpb.BarFuncOptional(func() mpb.BarOption {
return mpb.BarQueueAfter(tasks[i-1].bar)
}, i != 0),
mpb.PrependDecorators(
decor.Name("current:", decor.WCSyncWidthR),
),
mpb.AppendDecorators(
decor.Percentage(decor.WCSyncWidth),
),
)
tasks[i].bar = bar
}
tb := p.AddBar(0,
mpb.PrependDecorators(
decor.Any(func(st decor.Statistics) string {
return fmt.Sprintf("TOTAL(%d/%d)", atomic.LoadUint32(&doneTasks), len(tasks))
}, decor.WCSyncWidthR),
),
mpb.AppendDecorators(
decor.Percentage(decor.WCSyncWidth),
),
)
tb.SetTotal(total, false)
for _, t := range tasks {
atomic.StoreUint32(&curTask, t.id)
complete(t.bar, tb)
atomic.AddUint32(&doneTasks, 1)
}
tb.EnableTriggerComplete()
p.Wait()
}
func middleware(base mpb.BarFiller, id uint32) mpb.BarFiller {
var done bool
fn := func(w io.Writer, st decor.Statistics) error {
if !done {
if atomic.LoadUint32(&curTask) != id {
_, err := fmt.Fprintf(w, " Taksk %02d\n", id)
return err
}
if !st.Completed {
_, err := fmt.Fprintf(w, "=> Taksk %02d\n", id)
return err
}
done = true
}
_, err := fmt.Fprintf(w, " Taksk %02d: Done!\n", id)
return err
}
if base == nil {
return mpb.BarFillerFunc(fn)
}
return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
err := fn(w, st)
if err != nil {
return err
}
return base.Fill(w, st)
})
}
func newLineMiddleware(base mpb.BarFiller) mpb.BarFiller {
return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
_, err := fmt.Fprintln(w)
if err != nil {
return err
}
return base.Fill(w, st)
})
}
func complete(bar, totalBar *mpb.Bar) {
max := 100 * time.Millisecond
for !bar.Completed() {
n := rand.Int63n(10) + 1
incrementBars(n, bar, totalBar)
time.Sleep(time.Duration(n) * max / 10)
}
bar.Wait()
}
func incrementBars(n int64, bb ...*mpb.Bar) {
for _, b := range bb {
b.IncrInt64(n)
}
}
mpb-8.6.1/_examples/cancel/ 0000775 0000000 0000000 00000000000 14473125130 0015506 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/cancel/go.mod 0000664 0000000 0000000 00000000567 14473125130 0016624 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/cancel
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/cancel/main.go 0000664 0000000 0000000 00000002526 14473125130 0016766 0 ustar 00root root 0000000 0000000 package main
import (
"context"
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.NewWithContext(ctx, mpb.WithWaitGroup(&wg))
total := 300
numBars := 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%02d: ", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
decor.Name(name, decor.WCSyncWidthR),
decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth),
),
mpb.AppendDecorators(
// note that OnComplete will not be fired, because of cancel
decor.OnComplete(decor.Percentage(decor.WC{W: 5}), "done"),
),
)
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for bar.IsRunning() {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/complex/ 0000775 0000000 0000000 00000000000 14473125130 0015730 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/complex/go.mod 0000664 0000000 0000000 00000001000 14473125130 0017025 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/complex
go 1.17
require (
github.com/fatih/color v1.15.0
github.com/vbauerster/mpb/v8 v8.6.1
)
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/complex/main.go 0000664 0000000 0000000 00000004000 14473125130 0017175 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"time"
"github.com/fatih/color"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
numBars := 4
// to support color in Windows following both options are required
p := mpb.New(
mpb.WithOutput(color.Output),
mpb.WithAutoRefresh(),
)
red, green := color.New(color.FgRed), color.New(color.FgGreen)
for i := 0; i < numBars; i++ {
task := fmt.Sprintf("Task#%02d:", i)
queue := make([]*mpb.Bar, 2)
queue[0] = p.AddBar(rand.Int63n(201)+100,
mpb.PrependDecorators(
decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
decor.Name("downloading", decor.WCSyncSpaceR),
decor.CountersNoUnit("%d / %d", decor.WCSyncWidth),
),
mpb.AppendDecorators(
decor.OnComplete(decor.Percentage(decor.WC{W: 5}), "done"),
),
)
queue[1] = p.AddBar(rand.Int63n(101)+100,
mpb.BarQueueAfter(queue[0]), // this bar is queued
mpb.BarFillerClearOnComplete(),
mpb.PrependDecorators(
decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
decor.OnCompleteMeta(
decor.OnComplete(
decor.Meta(decor.Name("installing", decor.WCSyncSpaceR), toMetaFunc(red)),
"done!",
),
toMetaFunc(green),
),
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_MMSS, 0, decor.WCSyncWidth), ""),
),
mpb.AppendDecorators(
decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
),
)
go func() {
for _, b := range queue {
complete(b)
}
}()
}
p.Wait()
}
func complete(bar *mpb.Bar) {
max := 100 * time.Millisecond
for !bar.Completed() {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrInt64(rand.Int63n(5)+1, time.Since(start))
}
}
func toMetaFunc(c *color.Color) func(string) string {
return func(s string) string {
return c.Sprint(s)
}
}
mpb-8.6.1/_examples/decoratorsOnTop/ 0000775 0000000 0000000 00000000000 14473125130 0017406 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/decoratorsOnTop/go.mod 0000664 0000000 0000000 00000000600 14473125130 0020510 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/decoratorsOnTop
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/decoratorsOnTop/main.go 0000664 0000000 0000000 00000002040 14473125130 0020655 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
p := mpb.New()
total := 100
bar := p.New(int64(total),
mpb.NopStyle(), // make main bar style nop, so there are just decorators
mpb.BarExtender(extended(mpb.BarStyle().Build()), false), // extend wtih normal bar on the next line
mpb.PrependDecorators(
decor.Name("Percentage: "),
decor.NewPercentage("%d"),
),
mpb.AppendDecorators(
decor.Name("ETA: "),
decor.OnComplete(
decor.AverageETA(decor.ET_STYLE_GO), "done",
),
),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
func extended(base mpb.BarFiller) mpb.BarFiller {
return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
err := base.Fill(w, st)
if err != nil {
return err
}
_, err = io.WriteString(w, "\n")
return err
})
}
mpb-8.6.1/_examples/differentWidth/ 0000775 0000000 0000000 00000000000 14473125130 0017227 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/differentWidth/go.mod 0000664 0000000 0000000 00000000577 14473125130 0020346 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/differentWidth
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/differentWidth/main.go 0000664 0000000 0000000 00000002734 14473125130 0020510 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(
mpb.WithWaitGroup(&wg),
mpb.WithWidth(60),
)
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
// set BarWidth 40 for bar 1 and 2
mpb.BarOptional(mpb.BarWidth(40), i > 0),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/dynTotal/ 0000775 0000000 0000000 00000000000 14473125130 0016057 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/dynTotal/go.mod 0000664 0000000 0000000 00000000571 14473125130 0017170 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/dynTotal
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/dynTotal/main.go 0000664 0000000 0000000 00000002057 14473125130 0017336 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
p := mpb.New(mpb.WithWidth(64))
// new bar with 'trigger complete event' disabled, because total is zero
bar := p.AddBar(0,
mpb.PrependDecorators(decor.Counters(decor.SizeB1024(0), "% .1f / % .1f")),
mpb.AppendDecorators(decor.Percentage()),
)
maxSleep := 100 * time.Millisecond
read := makeStream(200)
for {
n, err := read()
if err == io.EOF {
// triggering complete event now
bar.SetTotal(-1, true)
break
}
// increment methods won't trigger complete event because bar was constructed with total = 0
bar.IncrBy(n)
// following call is not required, it's called to show some progress instead of an empty bar
bar.SetTotal(bar.Current()+2048, false)
time.Sleep(time.Duration(rand.Intn(10)+1) * maxSleep / 10)
}
p.Wait()
}
func makeStream(limit int) func() (int, error) {
return func() (int, error) {
if limit <= 0 {
return 0, io.EOF
}
limit--
return rand.Intn(1024) + 1, nil
}
}
mpb-8.6.1/_examples/gomodtidyall.sh 0000775 0000000 0000000 00000000205 14473125130 0017305 0 ustar 00root root 0000000 0000000 #!/bin/sh
for d in *; do
[ ! -d "$d" ] && continue
pushd "$d" >/dev/null 2>&1
go mod tidy
popd >/dev/null 2>&1
done
mpb-8.6.1/_examples/io/ 0000775 0000000 0000000 00000000000 14473125130 0014670 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/io/go.mod 0000664 0000000 0000000 00000000563 14473125130 0016002 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/io
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/io/main.go 0000664 0000000 0000000 00000001441 14473125130 0016143 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/rand"
"io"
"io/ioutil"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var total int64 = 1024 * 1024 * 500
reader := io.LimitReader(rand.Reader, total)
p := mpb.New(
mpb.WithWidth(60),
mpb.WithRefreshRate(180*time.Millisecond),
)
bar := p.New(total,
mpb.BarStyle().Rbound("|"),
mpb.PrependDecorators(
decor.Counters(decor.SizeB1024(0), "% .2f / % .2f"),
),
mpb.AppendDecorators(
decor.EwmaETA(decor.ET_STYLE_GO, 30),
decor.Name(" ] "),
decor.EwmaSpeed(decor.SizeB1024(0), "% .2f", 30),
),
)
// create proxy reader
proxyReader := bar.ProxyReader(reader)
defer proxyReader.Close()
// copy from proxyReader, ignoring errors
_, _ = io.Copy(ioutil.Discard, proxyReader)
p.Wait()
}
mpb-8.6.1/_examples/mexicanBar/ 0000775 0000000 0000000 00000000000 14473125130 0016332 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/mexicanBar/go.mod 0000664 0000000 0000000 00000000573 14473125130 0017445 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/mexicanBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/mexicanBar/main.go 0000664 0000000 0000000 00000002203 14473125130 0017602 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(80))
total := 100
name := "Complex Filler:"
bs := mpb.BarStyle()
bs = bs.LboundMeta(func(s string) string {
return "\033[34m" + s + "\033[0m" // blue
})
bs = bs.Filler("_").FillerMeta(func(s string) string {
return "\033[36m" + s + "\033[0m" // cyan
})
bs = bs.Tip("⛵").TipMeta(func(s string) string {
return "\033[31m" + s + "\033[0m" // red
})
bs = bs.TipOnComplete() // leave tip on complete
bs = bs.Padding("_").PaddingMeta(func(s string) string {
return "\033[36m" + s + "\033[0m" // cyan
})
bs = bs.RboundMeta(func(s string) string {
return "\033[34m" + s + "\033[0m" // blue
})
bar := p.New(int64(total), bs,
mpb.PrependDecorators(decor.Name(name)),
mpb.AppendDecorators(decor.Percentage()),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete
p.Wait()
}
mpb-8.6.1/_examples/multiBars/ 0000775 0000000 0000000 00000000000 14473125130 0016223 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/multiBars/go.mod 0000664 0000000 0000000 00000000572 14473125130 0017335 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/multiBars
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/multiBars/main.go 0000664 0000000 0000000 00000002601 14473125130 0017475 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/poplog/ 0000775 0000000 0000000 00000000000 14473125130 0015561 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/poplog/go.mod 0000664 0000000 0000000 00000000567 14473125130 0016677 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/poplog
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/poplog/main.go 0000664 0000000 0000000 00000002162 14473125130 0017035 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
p := mpb.New(mpb.PopCompletedMode())
total, numBars := 100, 4
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.BarFillerOnComplete(fmt.Sprintf("%s has been completed", name)),
mpb.BarFillerTrim(),
mpb.PrependDecorators(
decor.OnComplete(decor.Name(name), ""),
decor.OnComplete(decor.NewPercentage(" % d "), ""),
),
mpb.AppendDecorators(
decor.OnComplete(decor.Name(" "), ""),
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 60), ""),
),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}
p.Wait()
}
mpb-8.6.1/_examples/progressAsWriter/ 0000775 0000000 0000000 00000000000 14473125130 0017606 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/progressAsWriter/go.mod 0000664 0000000 0000000 00000000601 14473125130 0020711 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/progressAsWriter
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/progressAsWriter/main.go 0000664 0000000 0000000 00000003102 14473125130 0021055 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"log"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
total, numBars := 100, 2
var wg sync.WaitGroup
wg.Add(numBars)
done := make(chan interface{})
p := mpb.New(
mpb.WithWidth(64),
mpb.WithWaitGroup(&wg),
mpb.WithShutdownNotifier(done),
)
log.SetOutput(p)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
decor.Name(name),
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
decor.OnComplete(
decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
log.Println(name, "done")
}()
}
var qwg sync.WaitGroup
qwg.Add(1)
go func() {
quit:
for {
select {
case <-done:
// after done, underlying io.Writer returns mpb.DoneError
// so following isn't printed
log.Println("all done")
break quit
default:
log.Println("waiting for done")
time.Sleep(100 * time.Millisecond)
}
}
qwg.Done()
}()
p.Wait()
qwg.Wait()
}
mpb-8.6.1/_examples/quietMode/ 0000775 0000000 0000000 00000000000 14473125130 0016215 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/quietMode/go.mod 0000664 0000000 0000000 00000000572 14473125130 0017327 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/quietMode
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/quietMode/main.go 0000664 0000000 0000000 00000003076 14473125130 0017476 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"io"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
var quietMode bool
func init() {
flag.BoolVar(&quietMode, "q", false, "quiet mode")
}
func main() {
flag.Parse()
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(
mpb.WithWaitGroup(&wg),
mpb.ContainerOptional(mpb.WithOutput(io.Discard), quietMode),
)
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
fmt.Println("done")
}
mpb-8.6.1/_examples/remove/ 0000775 0000000 0000000 00000000000 14473125130 0015556 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/remove/go.mod 0000664 0000000 0000000 00000000567 14473125130 0016674 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/remove
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/remove/main.go 0000664 0000000 0000000 00000002521 14473125130 0017031 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total := 100
numBars := 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.BarID(i),
mpb.BarOptional(mpb.BarRemoveOnComplete(), i == 0),
mpb.PrependDecorators(
decor.Name(name),
),
mpb.AppendDecorators(
decor.Any(func(s decor.Statistics) string {
return fmt.Sprintf("completed: %v", s.Completed)
}, decor.WCSyncSpaceR),
decor.Any(func(s decor.Statistics) string {
return fmt.Sprintf("aborted: %v", s.Aborted)
}, decor.WCSyncSpaceR),
decor.OnComplete(decor.NewPercentage("%d", decor.WCSyncSpace), "done"),
decor.OnAbort(decor.NewPercentage("%d", decor.WCSyncSpace), "ohno"),
),
)
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; bar.IsRunning(); i++ {
if bar.ID() == 2 && i >= 42 {
go bar.Abort(false)
}
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
bar.Increment()
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/reverseBar/ 0000775 0000000 0000000 00000000000 14473125130 0016361 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/reverseBar/go.mod 0000664 0000000 0000000 00000000573 14473125130 0017474 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/reverseBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/reverseBar/main.go 0000664 0000000 0000000 00000003065 14473125130 0017640 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
total, numBars := 100, 3
wg.Add(numBars)
condFillerBuilder := func(cond bool) mpb.BarFillerBuilder {
if cond { // reverse Bar on cond
return mpb.BarStyle().Tip("<").Reverse()
}
return mpb.BarStyle()
}
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.New(int64(total),
condFillerBuilder(i == 1),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncSpace),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/singleBar/ 0000775 0000000 0000000 00000000000 14473125130 0016167 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/singleBar/go.mod 0000664 0000000 0000000 00000000572 14473125130 0017301 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/singleBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/singleBar/main.go 0000664 0000000 0000000 00000002027 14473125130 0017443 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(64))
total := 100
name := "Single Bar:"
// create a single bar, which will inherit container's width
bar := p.New(int64(total),
// BarFillerBuilder with custom style
mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟"),
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(
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
),
),
mpb.AppendDecorators(decor.Percentage()),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/spinTipBar/ 0000775 0000000 0000000 00000000000 14473125130 0016334 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/spinTipBar/go.mod 0000664 0000000 0000000 00000000573 14473125130 0017447 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinTipBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/spinTipBar/main.go 0000664 0000000 0000000 00000001313 14473125130 0017605 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(80))
total := 100
name := "Single Bar:"
bar := p.New(int64(total),
mpb.BarStyle().Tip(`-`, `\`, `|`, `/`).TipMeta(func(s string) string {
return "\033[31m" + s + "\033[0m" // red
}),
mpb.PrependDecorators(decor.Name(name)),
mpb.AppendDecorators(decor.Percentage()),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/spinnerBar/ 0000775 0000000 0000000 00000000000 14473125130 0016364 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/spinnerBar/go.mod 0000664 0000000 0000000 00000000573 14473125130 0017477 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/spinnerBar/main.go 0000664 0000000 0000000 00000003235 14473125130 0017642 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(
mpb.WithWaitGroup(&wg),
mpb.WithWidth(16),
)
total, numBars := 101, 3
wg.Add(numBars)
condFillerBuilder := func(cond bool) mpb.BarFillerBuilder {
if cond {
s := mpb.SpinnerStyle("∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙")
return s.Meta(func(s string) string {
return "\033[31m" + s + "\033[0m" // red
})
}
return mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟")
}
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.New(int64(total),
condFillerBuilder(i != 0),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
),
mpb.AppendDecorators(
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 30
decor.EwmaETA(decor.ET_STYLE_GO, 30), "done",
),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
// start variable is solely for EWMA calculation
// EWMA's unit of measure is an iteration's duration
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
// we need to call EwmaIncrement to fulfill ewma decorator's contract
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/spinnerDecorator/ 0000775 0000000 0000000 00000000000 14473125130 0017602 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/spinnerDecorator/go.mod 0000664 0000000 0000000 00000000601 14473125130 0020705 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerDecorator
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/spinnerDecorator/main.go 0000664 0000000 0000000 00000002135 14473125130 0021056 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithWidth(64))
total, numBars := 100, 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
// simple name decorator
decor.Name(name),
decor.OnComplete(
// spinner decorator with default style
decor.Spinner(nil, decor.WCSyncSpace), "done",
),
),
mpb.AppendDecorators(
// decor.DSyncWidth bit enables column width synchronization
decor.Percentage(decor.WCSyncWidth),
),
)
// simulating some work
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
bar.Increment()
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/stress/ 0000775 0000000 0000000 00000000000 14473125130 0015604 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/stress/go.mod 0000664 0000000 0000000 00000001021 14473125130 0016704 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/stress
go 1.17
require (
github.com/pkg/profile v1.7.0
github.com/vbauerster/mpb/v8 v8.6.1
)
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/felixge/fgprof v0.9.3 // indirect
github.com/google/pprof v0.0.0-20230821062121-407c9e7a662f // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/stress/main.go 0000664 0000000 0000000 00000002566 14473125130 0017070 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"math/rand"
"os"
"sync"
"time"
"github.com/pkg/profile"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
const (
totalBars = 32
)
var proftype = flag.String("prof", "", "profile type (cpu, mem)")
func main() {
flag.Parse()
switch *proftype {
case "cpu":
defer profile.Start(profile.CPUProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
case "mem":
defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
}
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg), mpb.WithDebugOutput(os.Stderr))
wg.Add(totalBars)
for i := 0; i < totalBars; i++ {
name := fmt.Sprintf("Bar#%02d: ", i)
total := rand.Intn(320) + 10
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
decor.Name(name, decor.WCSyncWidthR),
decor.Elapsed(decor.ET_STYLE_GO, decor.WCSyncWidth),
),
mpb.AppendDecorators(
decor.OnComplete(
decor.Percentage(decor.WC{W: 5}), "done",
),
),
)
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for !bar.Completed() {
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
bar.Increment()
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.6.1/_examples/suppressBar/ 0000775 0000000 0000000 00000000000 14473125130 0016572 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/suppressBar/go.mod 0000664 0000000 0000000 00000000565 14473125130 0017706 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/suppressBar
go 1.17
require (
github.com/mattn/go-runewidth v0.0.15
github.com/vbauerster/mpb/v8 v8.6.1
)
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/suppressBar/main.go 0000664 0000000 0000000 00000004507 14473125130 0020053 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"fmt"
"io"
"math/rand"
"sync"
"time"
"github.com/mattn/go-runewidth"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
p := mpb.New()
total := 100
msgCh := make(chan string)
resumeCh := make(chan struct{})
nextCh := make(chan struct{}, 1)
ew := &errorWrapper{}
timer := time.AfterFunc(2*time.Second, func() {
ew.reset(errors.New("timeout"))
})
defer timer.Stop()
bar := p.AddBar(int64(total),
mpb.BarFillerMiddleware(func(base mpb.BarFiller) mpb.BarFiller {
var msg *string
var times int
return mpb.BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
if msg == nil {
select {
case m := <-msgCh:
msg = &m
times = 10
nextCh <- struct{}{}
default:
}
return base.Fill(w, st)
}
switch {
case times == 0, st.Completed, st.Aborted:
defer func() {
msg = nil
}()
resumeCh <- struct{}{}
default:
times--
}
_, err := io.WriteString(w, runewidth.Truncate(*msg, st.AvailableWidth, "…"))
nextCh <- struct{}{}
return err
})
}),
mpb.PrependDecorators(decor.Name("my bar:")),
mpb.AppendDecorators(newCustomPercentage(nextCh)),
)
// simulating some work
go func() {
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
if ew.isErr() {
msgCh <- fmt.Sprintf("%s at %d, retrying...", ew.Error(), i)
i--
bar.SetRefill(int64(i))
ew.reset(nil)
<-resumeCh
continue
}
bar.Increment()
}
}()
p.Wait()
}
type errorWrapper struct {
sync.RWMutex
err error
}
func (ew *errorWrapper) Error() string {
ew.RLock()
defer ew.RUnlock()
return ew.err.Error()
}
func (ew *errorWrapper) isErr() bool {
ew.RLock()
defer ew.RUnlock()
return ew.err != nil
}
func (ew *errorWrapper) reset(err error) {
ew.Lock()
ew.err = err
ew.Unlock()
}
type percentage struct {
decor.Decorator
suspend <-chan struct{}
}
func (d percentage) Decor(s decor.Statistics) (string, int) {
select {
case <-d.suspend:
return d.Format("")
default:
return d.Decorator.Decor(s)
}
}
func newCustomPercentage(nextCh <-chan struct{}) decor.Decorator {
return percentage{
Decorator: decor.Percentage(),
suspend: nextCh,
}
}
mpb-8.6.1/_examples/tipOnComplete/ 0000775 0000000 0000000 00000000000 14473125130 0017043 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_examples/tipOnComplete/go.mod 0000664 0000000 0000000 00000000576 14473125130 0020161 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/tipOnComplete
go 1.17
require github.com/vbauerster/mpb/v8 v8.6.1
require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.11.0 // indirect
)
mpb-8.6.1/_examples/tipOnComplete/main.go 0000664 0000000 0000000 00000001162 14473125130 0020316 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(80))
total := 100
name := "Single Bar:"
bar := p.New(int64(total),
mpb.BarStyle().TipOnComplete(),
mpb.PrependDecorators(decor.Name(name)),
mpb.AppendDecorators(decor.Percentage()),
)
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
mpb-8.6.1/_svg/ 0000775 0000000 0000000 00000000000 14473125130 0013242 5 ustar 00root root 0000000 0000000 mpb-8.6.1/_svg/godEMrCZmJkHYH1X9dN4Nm0U7.svg 0000664 0000000 0000000 00000202517 14473125130 0020056 0 ustar 00root root 0000000 0000000