pax_global_header 0000666 0000000 0000000 00000000064 14663127573 0014530 g ustar 00root root 0000000 0000000 52 comment=99ffa837971b7a12db44ff49c3de4c54dac257a0
mpb-8.8.3/ 0000775 0000000 0000000 00000000000 14663127573 0012326 5 ustar 00root root 0000000 0000000 mpb-8.8.3/.github/ 0000775 0000000 0000000 00000000000 14663127573 0013666 5 ustar 00root root 0000000 0000000 mpb-8.8.3/.github/workflows/ 0000775 0000000 0000000 00000000000 14663127573 0015723 5 ustar 00root root 0000000 0000000 mpb-8.8.3/.github/workflows/golangci-lint.yml 0000664 0000000 0000000 00000002003 14663127573 0021170 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@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache: false
- uses: golangci/golangci-lint-action@v6
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: 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.8.3/.github/workflows/test.yml 0000664 0000000 0000000 00000000756 14663127573 0017435 0 ustar 00root root 0000000 0000000 name: test
on:
push:
tags:
- v*
branches:
- master
- main
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@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- run: go test -race ./...
mpb-8.8.3/.gitignore 0000664 0000000 0000000 00000000173 14663127573 0014317 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.8.3/CONTRIBUTING 0000664 0000000 0000000 00000001201 14663127573 0014152 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.8.3/README.md 0000664 0000000 0000000 00000010102 14663127573 0013577 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{C: decor.DindentRight | decor.DextraSpace}),
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(decor.AverageETA(decor.ET_STYLE_GO), "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.8.3/UNLICENSE 0000664 0000000 0000000 00000002273 14663127573 0013602 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.8.3/_examples/ 0000775 0000000 0000000 00000000000 14663127573 0014303 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/.gitignore 0000664 0000000 0000000 00000000007 14663127573 0016270 0 ustar 00root root 0000000 0000000 go.sum
mpb-8.8.3/_examples/barExtender/ 0000775 0000000 0000000 00000000000 14663127573 0016546 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/barExtender/go.mod 0000664 0000000 0000000 00000000574 14663127573 0017662 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/barExtender
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/barExtender/main.go 0000664 0000000 0000000 00000003124 14663127573 0020021 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.8.3/_examples/barExtenderRev/ 0000775 0000000 0000000 00000000000 14663127573 0017223 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/barExtenderRev/go.mod 0000664 0000000 0000000 00000000577 14663127573 0020342 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/barExtenderRev
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/barExtenderRev/main.go 0000664 0000000 0000000 00000005215 14663127573 0020501 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.8.3/_examples/cancel/ 0000775 0000000 0000000 00000000000 14663127573 0015530 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/cancel/go.mod 0000664 0000000 0000000 00000000567 14663127573 0016646 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/cancel
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/cancel/main.go 0000664 0000000 0000000 00000002526 14663127573 0017010 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.8.3/_examples/complex/ 0000775 0000000 0000000 00000000000 14663127573 0015752 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/complex/go.mod 0000664 0000000 0000000 00000001000 14663127573 0017047 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/complex
go 1.17
require (
github.com/fatih/color v1.17.0
github.com/vbauerster/mpb/v8 v8.8.3
)
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.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/complex/main.go 0000664 0000000 0000000 00000004006 14663127573 0017225 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{C: decor.DindentRight | decor.DextraSpace}),
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{C: decor.DindentRight | decor.DextraSpace}),
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.8.3/_examples/decoratorsOnTop/ 0000775 0000000 0000000 00000000000 14663127573 0017430 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/decoratorsOnTop/go.mod 0000664 0000000 0000000 00000000600 14663127573 0020532 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/decoratorsOnTop
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/decoratorsOnTop/main.go 0000664 0000000 0000000 00000002040 14663127573 0020677 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.8.3/_examples/differentWidth/ 0000775 0000000 0000000 00000000000 14663127573 0017251 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/differentWidth/go.mod 0000664 0000000 0000000 00000000577 14663127573 0020370 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/differentWidth
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/differentWidth/main.go 0000664 0000000 0000000 00000002734 14663127573 0020532 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.8.3/_examples/dynTotal/ 0000775 0000000 0000000 00000000000 14663127573 0016101 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/dynTotal/go.mod 0000664 0000000 0000000 00000000571 14663127573 0017212 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/dynTotal
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/dynTotal/main.go 0000664 0000000 0000000 00000002057 14663127573 0017360 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.8.3/_examples/gomodtidyall 0000775 0000000 0000000 00000000214 14663127573 0016716 0 ustar 00root root 0000000 0000000 #!/bin/sh
set -e
for d in *; do
[ ! -d "$d" ] && continue
pushd "$d" >/dev/null 2>&1
go mod tidy
popd >/dev/null 2>&1
done
mpb-8.8.3/_examples/io/ 0000775 0000000 0000000 00000000000 14663127573 0014712 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/io/go.mod 0000664 0000000 0000000 00000000563 14663127573 0016024 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/io
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/io/main.go 0000664 0000000 0000000 00000001614 14663127573 0016167 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/rand"
"io"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
var total int64 = 64 * 1024 * 1024
r, w := io.Pipe()
go func() {
for i := 0; i < 1024; i++ {
_, _ = io.Copy(w, io.LimitReader(rand.Reader, 64*1024))
time.Sleep(time.Second / 10)
}
w.Close()
}()
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(r)
defer proxyReader.Close()
// copy from proxyReader, ignoring errors
_, _ = io.Copy(io.Discard, proxyReader)
p.Wait()
}
mpb-8.8.3/_examples/mexicanBar/ 0000775 0000000 0000000 00000000000 14663127573 0016354 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/mexicanBar/go.mod 0000664 0000000 0000000 00000000573 14663127573 0017467 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/mexicanBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/mexicanBar/main.go 0000664 0000000 0000000 00000002203 14663127573 0017624 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.8.3/_examples/multiBars/ 0000775 0000000 0000000 00000000000 14663127573 0016245 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/multiBars/go.mod 0000664 0000000 0000000 00000000572 14663127573 0017357 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/multiBars
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/multiBars/main.go 0000664 0000000 0000000 00000002601 14663127573 0017517 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.8.3/_examples/poplog/ 0000775 0000000 0000000 00000000000 14663127573 0015603 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/poplog/go.mod 0000664 0000000 0000000 00000000567 14663127573 0016721 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/poplog
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/poplog/main.go 0000664 0000000 0000000 00000002162 14663127573 0017057 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, 30), ""),
),
)
// 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.8.3/_examples/progressAsWriter/ 0000775 0000000 0000000 00000000000 14663127573 0017630 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/progressAsWriter/go.mod 0000664 0000000 0000000 00000000601 14663127573 0020733 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/progressAsWriter
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/progressAsWriter/main.go 0000664 0000000 0000000 00000003206 14663127573 0021104 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 bwg, qwg sync.WaitGroup
bwg.Add(numBars)
qwg.Add(1)
done := make(chan interface{})
p := mpb.New(mpb.WithWidth(64), mpb.WithShutdownNotifier(done), mpb.WithWaitGroup(&qwg))
log.SetOutput(p)
go func() {
defer qwg.Done()
for {
select {
case <-done:
// after done, underlying io.Writer returns mpb.DoneError
// so following isn't printed
log.Println("all done")
return
default:
log.Println("waiting for done")
time.Sleep(150 * time.Millisecond)
}
}
}()
nopBar := p.MustAdd(0, nil)
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 bwg.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")
}()
}
bwg.Wait()
log.Println("completing nop bar")
nopBar.EnableTriggerComplete()
p.Wait()
}
mpb-8.8.3/_examples/quietMode/ 0000775 0000000 0000000 00000000000 14663127573 0016237 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/quietMode/go.mod 0000664 0000000 0000000 00000000572 14663127573 0017351 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/quietMode
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/quietMode/main.go 0000664 0000000 0000000 00000003076 14663127573 0017520 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.8.3/_examples/remove/ 0000775 0000000 0000000 00000000000 14663127573 0015600 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/remove/go.mod 0000664 0000000 0000000 00000000567 14663127573 0016716 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/remove
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/remove/main.go 0000664 0000000 0000000 00000002521 14663127573 0017053 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.8.3/_examples/reverseBar/ 0000775 0000000 0000000 00000000000 14663127573 0016403 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/reverseBar/go.mod 0000664 0000000 0000000 00000000573 14663127573 0017516 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/reverseBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/reverseBar/main.go 0000664 0000000 0000000 00000003065 14663127573 0017662 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.8.3/_examples/singleBar/ 0000775 0000000 0000000 00000000000 14663127573 0016211 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/singleBar/go.mod 0000664 0000000 0000000 00000000572 14663127573 0017323 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/singleBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/singleBar/main.go 0000664 0000000 0000000 00000002000 14663127573 0017454 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{C: decor.DindentRight | decor.DextraSpace}),
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(decor.AverageETA(decor.ET_STYLE_GO), "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.8.3/_examples/spinTipBar/ 0000775 0000000 0000000 00000000000 14663127573 0016356 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/spinTipBar/go.mod 0000664 0000000 0000000 00000000573 14663127573 0017471 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinTipBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/spinTipBar/main.go 0000664 0000000 0000000 00000001313 14663127573 0017627 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.8.3/_examples/spinnerBar/ 0000775 0000000 0000000 00000000000 14663127573 0016406 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/spinnerBar/go.mod 0000664 0000000 0000000 00000000573 14663127573 0017521 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/spinnerBar/main.go 0000664 0000000 0000000 00000003235 14663127573 0017664 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.8.3/_examples/spinnerDecorator/ 0000775 0000000 0000000 00000000000 14663127573 0017624 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/spinnerDecorator/go.mod 0000664 0000000 0000000 00000000601 14663127573 0020727 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerDecorator
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/spinnerDecorator/main.go 0000664 0000000 0000000 00000002135 14663127573 0021100 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.8.3/_examples/stress/ 0000775 0000000 0000000 00000000000 14663127573 0015626 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/stress/go.mod 0000664 0000000 0000000 00000001021 14663127573 0016726 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.8.3
)
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.4 // indirect
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/stress/main.go 0000664 0000000 0000000 00000002767 14663127573 0017115 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 = 42
)
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.OnComplete(decor.Percentage(decor.WCSyncWidth), "done"),
),
mpb.AppendDecorators(
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 30, decor.WCSyncWidth), ""),
decor.EwmaSpeed(decor.SizeB1024(0), "", 30, decor.WCSyncSpace),
),
)
go func() {
defer wg.Done()
rng := rand.New(rand.NewSource(time.Now().UnixNano()))
max := 100 * time.Millisecond
for bar.IsRunning() {
start := time.Now()
time.Sleep(time.Duration(rng.Intn(10)+1) * max / 10)
bar.EwmaIncrement(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-8.8.3/_examples/suppressBar/ 0000775 0000000 0000000 00000000000 14663127573 0016614 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/suppressBar/go.mod 0000664 0000000 0000000 00000000574 14663127573 0017730 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/suppressBar
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/suppressBar/main.go 0000664 0000000 0000000 00000004041 14663127573 0020066 0 ustar 00root root 0000000 0000000 package main
import (
"errors"
"fmt"
"math"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"
)
func main() {
p := mpb.New()
total, numBars := 100, 3
err := new(errorWrapper)
timer := time.AfterFunc(2*time.Second, func() {
err.set(errors.New("timeout"), rand.Intn(numBars))
})
defer timer.Stop()
for i := 0; i < numBars; i++ {
msgCh := make(chan string, 1)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(newTitleDecorator(fmt.Sprintf("Bar#%d:", i), msgCh, 16)),
mpb.AppendDecorators(decor.Percentage(decor.WCSyncWidth)),
)
// simulating some work
barID := i
go func() {
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
if err.check(barID) {
msgCh <- fmt.Sprintf("%s at %d, retrying...", err.Error(), i)
err.reset()
i--
bar.SetRefill(int64(i))
continue
}
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
bar.Increment()
}
}()
}
p.Wait()
}
type errorWrapper struct {
sync.RWMutex
err error
barID int
}
func (ew *errorWrapper) Error() string {
ew.RLock()
defer ew.RUnlock()
return ew.err.Error()
}
func (ew *errorWrapper) check(barID int) bool {
ew.RLock()
defer ew.RUnlock()
return ew.err != nil && ew.barID == barID
}
func (ew *errorWrapper) set(err error, barID int) {
ew.Lock()
ew.err = err
ew.barID = barID
ew.Unlock()
}
func (ew *errorWrapper) reset() {
ew.Lock()
ew.err = nil
ew.Unlock()
}
type title struct {
decor.Decorator
name string
msgCh <-chan string
msg string
count int
limit int
}
func (d *title) Decor(stat decor.Statistics) (string, int) {
if d.count == 0 {
select {
case msg := <-d.msgCh:
d.count = d.limit
d.msg = msg
default:
return d.Decorator.Decor(stat)
}
}
d.count--
_, _ = d.Format("")
return fmt.Sprintf("%s %s", d.name, d.msg), math.MaxInt
}
func newTitleDecorator(name string, msgCh <-chan string, limit int) decor.Decorator {
return &title{
Decorator: decor.Name(name),
name: name,
msgCh: msgCh,
limit: limit,
}
}
mpb-8.8.3/_examples/tipOnComplete/ 0000775 0000000 0000000 00000000000 14663127573 0017065 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_examples/tipOnComplete/go.mod 0000664 0000000 0000000 00000000576 14663127573 0020203 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/tipOnComplete
go 1.17
require github.com/vbauerster/mpb/v8 v8.8.3
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.16 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.24.0 // indirect
)
mpb-8.8.3/_examples/tipOnComplete/main.go 0000664 0000000 0000000 00000001162 14663127573 0020340 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.8.3/_svg/ 0000775 0000000 0000000 00000000000 14663127573 0013264 5 ustar 00root root 0000000 0000000 mpb-8.8.3/_svg/godEMrCZmJkHYH1X9dN4Nm0U7.svg 0000664 0000000 0000000 00000202517 14663127573 0020100 0 ustar 00root root 0000000 0000000