pax_global_header 0000666 0000000 0000000 00000000064 14172722005 0014512 g ustar 00root root 0000000 0000000 52 comment=fbeaf867830cc088065f0014763f0c3cc974287c
mpb-7.3.2/ 0000775 0000000 0000000 00000000000 14172722005 0012301 5 ustar 00root root 0000000 0000000 mpb-7.3.2/.github/ 0000775 0000000 0000000 00000000000 14172722005 0013641 5 ustar 00root root 0000000 0000000 mpb-7.3.2/.github/workflows/ 0000775 0000000 0000000 00000000000 14172722005 0015676 5 ustar 00root root 0000000 0000000 mpb-7.3.2/.github/workflows/test.yml 0000664 0000000 0000000 00000001552 14172722005 0017403 0 ustar 00root root 0000000 0000000 name: Test
on: [push, pull_request]
jobs:
test:
strategy:
matrix:
go-version: [1.16, 1.17]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
%LocalAppData%\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test
run: go test -race ./...
mpb-7.3.2/.gitignore 0000664 0000000 0000000 00000000173 14172722005 0014272 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-7.3.2/README.md 0000664 0000000 0000000 00000010141 14172722005 0013555 0 ustar 00root root 0000000 0000000 # Multi Progress Bar
[](https://pkg.go.dev/github.com/vbauerster/mpb/v7)
[](https://github.com/vbauerster/mpb/actions/workflows/test.yml)
[](https://www.paypal.me/vbauerster)
**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/v7"
"github.com/vbauerster/mpb/v7/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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60, 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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(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-7.3.2/UNLICENSE 0000664 0000000 0000000 00000002273 14172722005 0013555 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-7.3.2/_examples/ 0000775 0000000 0000000 00000000000 14172722005 0014256 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/.gitignore 0000664 0000000 0000000 00000000007 14172722005 0016243 0 ustar 00root root 0000000 0000000 go.sum
mpb-7.3.2/_examples/barExtender/ 0000775 0000000 0000000 00000000000 14172722005 0016521 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/barExtender/go.mod 0000664 0000000 0000000 00000000155 14172722005 0017630 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/barExtender
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/barExtender/main.go 0000664 0000000 0000000 00000003116 14172722005 0017775 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"io"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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, _ int, s decor.Statistics) {
if s.Completed {
fmt.Fprintf(w, "Bar id: %d has been completed\n", s.ID)
}
}
bar := p.AddBar(int64(total), mpb.BarExtender(mpb.BarFillerFunc(efn)),
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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// since EWMA based decorator is used, DecoratorEwmaUpdate should be called
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-7.3.2/_examples/cancel/ 0000775 0000000 0000000 00000000000 14172722005 0015503 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/cancel/go.mod 0000664 0000000 0000000 00000000150 14172722005 0016605 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/cancel
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/cancel/main.go 0000664 0000000 0000000 00000002540 14172722005 0016757 0 ustar 00root root 0000000 0000000 package main
import (
"context"
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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#%d:", i)
bar := p.AddBar(int64(total),
mpb.PrependDecorators(
decor.Name(name),
decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WCSyncSpace),
),
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.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(rng.Intn(10)+1) * max / 10)
bar.Increment()
// since EWMA based decorator is used, DecoratorEwmaUpdate should be called
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-7.3.2/_examples/complex/ 0000775 0000000 0000000 00000000000 14172722005 0015725 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/complex/go.mod 0000664 0000000 0000000 00000000151 14172722005 0017030 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/complex
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/complex/main.go 0000664 0000000 0000000 00000004422 14172722005 0017202 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
doneWg := new(sync.WaitGroup)
// passed doneWg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(doneWg))
numBars := 4
var bars []*mpb.Bar
var downloadWgg []*sync.WaitGroup
for i := 0; i < numBars; i++ {
wg := new(sync.WaitGroup)
wg.Add(1)
downloadWgg = append(downloadWgg, wg)
task := fmt.Sprintf("Task#%02d:", i)
job := "downloading"
b := p.AddBar(rand.Int63n(201)+100,
mpb.PrependDecorators(
decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
decor.Name(job, decor.WCSyncSpaceR),
decor.CountersNoUnit("%d / %d", decor.WCSyncWidth),
),
mpb.AppendDecorators(decor.Percentage(decor.WC{W: 5})),
)
go newTask(wg, b, i+1)
bars = append(bars, b)
}
for i := 0; i < numBars; i++ {
doneWg.Add(1)
i := i
go func() {
task := fmt.Sprintf("Task#%02d:", i)
// ANSI escape sequences are not supported on Windows OS
job := "\x1b[31;1;4mつのだ☆HIRO\x1b[0m"
// preparing delayed bars
b := p.AddBar(rand.Int63n(101)+100,
mpb.BarQueueAfter(bars[i]),
mpb.BarFillerClearOnComplete(),
mpb.PrependDecorators(
decor.Name(task, decor.WC{W: len(task) + 1, C: decor.DidentRight}),
decor.OnComplete(decor.Name(job, decor.WCSyncSpaceR), "done!"),
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_MMSS, 0, decor.WCSyncWidth), ""),
),
mpb.AppendDecorators(
decor.OnComplete(decor.Percentage(decor.WC{W: 5}), ""),
),
)
// waiting for download to complete, before starting install job
downloadWgg[i].Wait()
go newTask(doneWg, b, numBars-i)
}()
}
// wait for passed doneWg and for all bars to complete and flush
p.Wait()
}
func newTask(wg *sync.WaitGroup, bar *mpb.Bar, incrBy int) {
defer wg.Done()
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)
bar.IncrBy(incrBy)
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}
mpb-7.3.2/_examples/decoratorsOnTop/ 0000775 0000000 0000000 00000000000 14172722005 0017403 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/decoratorsOnTop/go.mod 0000664 0000000 0000000 00000000161 14172722005 0020507 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/decoratorsOnTop
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/decoratorsOnTop/main.go 0000664 0000000 0000000 00000002007 14172722005 0020655 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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())), // 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(builder mpb.BarFillerBuilder) mpb.BarFiller {
filler := builder.Build()
return mpb.BarFillerFunc(func(w io.Writer, reqWidth int, st decor.Statistics) {
filler.Fill(w, reqWidth, st)
w.Write([]byte("\n"))
})
}
mpb-7.3.2/_examples/differentWidth/ 0000775 0000000 0000000 00000000000 14172722005 0017224 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/differentWidth/go.mod 0000664 0000000 0000000 00000000160 14172722005 0020327 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/differentWidth
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/differentWidth/main.go 0000664 0000000 0000000 00000002774 14172722005 0020511 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-7.3.2/_examples/dynTotal/ 0000775 0000000 0000000 00000000000 14172722005 0016054 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/dynTotal/go.mod 0000664 0000000 0000000 00000000152 14172722005 0017160 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/dynTotal
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/dynTotal/main.go 0000664 0000000 0000000 00000002164 14172722005 0017332 0 ustar 00root root 0000000 0000000 package main
import (
"io"
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
p := mpb.New(mpb.WithWidth(64))
var total int64
// new bar with 'trigger complete event' disabled, because total is zero
bar := p.AddBar(total,
mpb.PrependDecorators(decor.Counters(decor.UnitKiB, "% .1f / % .1f")),
mpb.AppendDecorators(decor.Percentage()),
)
maxSleep := 100 * time.Millisecond
read := makeStream(200)
for {
n, err := read()
total += int64(n)
if err == io.EOF {
break
}
// while total is unknown,
// set it to a positive number which is greater than current total,
// to make sure no complete event is triggered by next IncrBy call.
bar.SetTotal(total+2048, false)
bar.IncrBy(n)
time.Sleep(time.Duration(rand.Intn(10)+1) * maxSleep / 10)
}
// force bar complete event, note true flag
bar.SetTotal(total, true)
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-7.3.2/_examples/io/ 0000775 0000000 0000000 00000000000 14172722005 0014665 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/io/go.mod 0000664 0000000 0000000 00000000144 14172722005 0015772 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/io
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/io/main.go 0000664 0000000 0000000 00000001411 14172722005 0016135 0 ustar 00root root 0000000 0000000 package main
import (
"crypto/rand"
"io"
"io/ioutil"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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.CountersKibiByte("% .2f / % .2f"),
),
mpb.AppendDecorators(
decor.EwmaETA(decor.ET_STYLE_GO, 90),
decor.Name(" ] "),
decor.EwmaSpeed(decor.UnitKiB, "% .2f", 60),
),
)
// create proxy reader
proxyReader := bar.ProxyReader(reader)
defer proxyReader.Close()
// copy from proxyReader, ignoring errors
io.Copy(ioutil.Discard, proxyReader)
p.Wait()
}
mpb-7.3.2/_examples/merge/ 0000775 0000000 0000000 00000000000 14172722005 0015355 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/merge/go.mod 0000664 0000000 0000000 00000000147 14172722005 0016465 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/merge
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/merge/main.go 0000664 0000000 0000000 00000003525 14172722005 0016635 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"strings"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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++ {
var pdecorators mpb.BarOption
if i == 0 {
pdecorators = mpb.PrependDecorators(
decor.Merge(
decor.OnComplete(
newVariadicSpinner(decor.WCSyncSpace),
"done",
),
decor.WCSyncSpace, // Placeholder
decor.WCSyncSpace, // Placeholder
),
)
} else {
pdecorators = mpb.PrependDecorators(
decor.CountersNoUnit("% .1d / % .1d", decor.WCSyncSpace),
decor.OnComplete(decor.Spinner(nil, decor.WCSyncSpace), "done"),
decor.OnComplete(decor.Spinner(nil, decor.WCSyncSpace), "done"),
)
}
bar := p.AddBar(int64(total),
pdecorators,
mpb.AppendDecorators(
decor.OnComplete(decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
func newVariadicSpinner(wc decor.WC) decor.Decorator {
spinner := decor.Spinner(nil)
fn := func(s decor.Statistics) string {
return strings.Repeat(spinner.Decor(s), int(s.Current/3))
}
return decor.Any(fn, wc)
}
mpb-7.3.2/_examples/mexicanBar/ 0000775 0000000 0000000 00000000000 14172722005 0016327 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/mexicanBar/go.mod 0000664 0000000 0000000 00000000154 14172722005 0017435 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/mexicanBar
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/mexicanBar/main.go 0000664 0000000 0000000 00000001336 14172722005 0017605 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func main() {
// initialize progress container, with custom width
p := mpb.New(mpb.WithWidth(80))
total := 100
name := "Complex Filler:"
bs := mpb.BarStyle()
bs.Lbound("[\u001b[36;1m")
bs.Filler("_")
bs.Tip("\u001b[0m⛵\u001b[36;1m")
bs.Padding("_")
bs.Rbound("\u001b[0m]")
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-7.3.2/_examples/multiBars/ 0000775 0000000 0000000 00000000000 14172722005 0016220 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/multiBars/go.mod 0000664 0000000 0000000 00000000153 14172722005 0017325 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/multiBars
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/multiBars/main.go 0000664 0000000 0000000 00000002641 14172722005 0017476 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60, 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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
mpb-7.3.2/_examples/panic/ 0000775 0000000 0000000 00000000000 14172722005 0015350 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/panic/go.mod 0000664 0000000 0000000 00000000147 14172722005 0016460 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/panic
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/panic/main.go 0000664 0000000 0000000 00000001660 14172722005 0016626 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"os"
"strings"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(
mpb.WithWaitGroup(&wg),
mpb.WithDebugOutput(os.Stderr),
)
wantPanic := strings.Repeat("Panic ", 64)
numBars := 3
wg.Add(numBars)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("b#%02d:", i)
bar := p.AddBar(100, mpb.BarID(i), mpb.PrependDecorators(panicDecorator(name, wantPanic)))
go func() {
defer wg.Done()
for i := 0; i < 100; i++ {
time.Sleep(50 * time.Millisecond)
bar.Increment()
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
func panicDecorator(name, panicMsg string) decor.Decorator {
return decor.Any(func(st decor.Statistics) string {
if st.ID == 1 && st.Current >= 42 {
panic(panicMsg)
}
return name
})
}
mpb-7.3.2/_examples/poplog/ 0000775 0000000 0000000 00000000000 14172722005 0015556 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/poplog/go.mod 0000664 0000000 0000000 00000000150 14172722005 0016660 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/poplog
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/poplog/main.go 0000664 0000000 0000000 00000002223 14172722005 0017030 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func main() {
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
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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}
p.Wait()
}
mpb-7.3.2/_examples/quietMode/ 0000775 0000000 0000000 00000000000 14172722005 0016212 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/quietMode/go.mod 0000664 0000000 0000000 00000000153 14172722005 0017317 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/quietMode
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/quietMode/main.go 0000664 0000000 0000000 00000003476 14172722005 0017477 0 ustar 00root root 0000000 0000000 package main
import (
"flag"
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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(
// setting to nil will:
// set output to ioutil.Discard and disable refresh rate cycle, in
// order not to consume much CPU. Hovewer a single refresh still will
// be triggered on bar complete event, per each bar.
mpb.WithOutput(nil),
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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
fmt.Println("done")
}
mpb-7.3.2/_examples/remove/ 0000775 0000000 0000000 00000000000 14172722005 0015553 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/remove/go.mod 0000664 0000000 0000000 00000000150 14172722005 0016655 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/remove
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/remove/main.go 0000664 0000000 0000000 00000002517 14172722005 0017033 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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.Completed(); i++ {
if bar.ID() == 2 && i >= 42 {
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-7.3.2/_examples/reverseBar/ 0000775 0000000 0000000 00000000000 14172722005 0016356 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/reverseBar/go.mod 0000664 0000000 0000000 00000000154 14172722005 0017464 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/reverseBar
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/reverseBar/main.go 0000664 0000000 0000000 00000003205 14172722005 0017631 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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.New(int64(total), condBuilder(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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
func condBuilder(cond bool) mpb.BarFillerBuilder {
return mpb.BarFillerBuilderFunc(func() mpb.BarFiller {
bs := mpb.BarStyle()
if cond {
// reverse Bar on cond
bs = bs.Tip("<").Reverse()
}
return bs.Build()
})
}
mpb-7.3.2/_examples/singleBar/ 0000775 0000000 0000000 00000000000 14172722005 0016164 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/singleBar/go.mod 0000664 0000000 0000000 00000000153 14172722005 0017271 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/singleBar
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/singleBar/main.go 0000664 0000000 0000000 00000002027 14172722005 0017440 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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-7.3.2/_examples/spinTipBar/ 0000775 0000000 0000000 00000000000 14172722005 0016331 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/spinTipBar/go.mod 0000664 0000000 0000000 00000000154 14172722005 0017437 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinTipBar
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/spinTipBar/main.go 0000664 0000000 0000000 00000001172 14172722005 0017605 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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(`-`, `\`, `|`, `/`),
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-7.3.2/_examples/spinnerBar/ 0000775 0000000 0000000 00000000000 14172722005 0016361 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/spinnerBar/go.mod 0000664 0000000 0000000 00000000154 14172722005 0017467 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerBar
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/spinnerBar/main.go 0000664 0000000 0000000 00000003326 14172722005 0017640 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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)
for i := 0; i < numBars; i++ {
name := fmt.Sprintf("Bar#%d:", i)
bar := p.New(int64(total), condBuilder(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 60
decor.EwmaETA(decor.ET_STYLE_GO, 60), "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)
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}
// wait for passed wg and for all bars to complete and flush
p.Wait()
}
func condBuilder(cond bool) mpb.BarFillerBuilder {
return mpb.BarFillerBuilderFunc(func() mpb.BarFiller {
if cond {
// spinner Bar on cond
frames := []string{"∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"}
return mpb.SpinnerStyle(frames...).Build()
}
return mpb.BarStyle().Lbound("╢").Filler("▌").Tip("▌").Padding("░").Rbound("╟").Build()
})
}
mpb-7.3.2/_examples/spinnerDecorator/ 0000775 0000000 0000000 00000000000 14172722005 0017577 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/spinnerDecorator/go.mod 0000664 0000000 0000000 00000000162 14172722005 0020704 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/spinnerDecorator
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/spinnerDecorator/main.go 0000664 0000000 0000000 00000002135 14172722005 0021053 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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-7.3.2/_examples/stress/ 0000775 0000000 0000000 00000000000 14172722005 0015601 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/stress/go.mod 0000664 0000000 0000000 00000000150 14172722005 0016703 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/stress
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/stress/main.go 0000664 0000000 0000000 00000001722 14172722005 0017056 0 ustar 00root root 0000000 0000000 package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/decor"
)
const (
totalBars = 32
)
func main() {
var wg sync.WaitGroup
// passed wg will be accounted at p.Wait() call
p := mpb.New(mpb.WithWaitGroup(&wg))
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.Elapsed(decor.ET_STYLE_GO, decor.WCSyncSpace),
),
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-7.3.2/_examples/suppressBar/ 0000775 0000000 0000000 00000000000 14172722005 0016567 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/suppressBar/go.mod 0000664 0000000 0000000 00000000231 14172722005 0017671 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/suppressBar
go 1.14
require (
github.com/mattn/go-runewidth v0.0.13
github.com/vbauerster/mpb/v7 v7.3.2
)
mpb-7.3.2/_examples/suppressBar/main.go 0000664 0000000 0000000 00000004113 14172722005 0020041 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/v7"
"github.com/vbauerster/mpb/v7/decor"
)
func main() {
p := mpb.New()
total := 100
msgCh := make(chan string)
resumeCh := make(chan struct{})
nextCh := make(chan struct{}, 1)
bar := p.AddBar(int64(total),
mpb.BarFillerMiddleware(func(base mpb.BarFiller) mpb.BarFiller {
var msg *string
return mpb.BarFillerFunc(func(w io.Writer, reqWidth int, st decor.Statistics) {
select {
case m := <-msgCh:
defer func() {
msg = &m
}()
nextCh <- struct{}{}
case <-resumeCh:
msg = nil
default:
}
if msg != nil {
io.WriteString(w, runewidth.Truncate(*msg, st.AvailableWidth, "…"))
nextCh <- struct{}{}
} else {
base.Fill(w, reqWidth, st)
}
})
}),
mpb.PrependDecorators(decor.Name("my bar:")),
mpb.AppendDecorators(newCustomPercentage(nextCh)),
)
ew := &errorWrapper{}
time.AfterFunc(2*time.Second, func() {
ew.reset(errors.New("timeout"))
})
// 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)
go ew.reset(nil)
i--
bar.SetRefill(int64(i))
time.Sleep(3 * time.Second)
resumeCh <- struct{}{}
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()
}
func newCustomPercentage(nextCh <-chan struct{}) decor.Decorator {
base := decor.Percentage()
fn := func(s decor.Statistics) string {
select {
case <-nextCh:
return ""
default:
return base.Decor(s)
}
}
return decor.Any(fn)
}
mpb-7.3.2/_examples/tipOnComplete/ 0000775 0000000 0000000 00000000000 14172722005 0017040 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_examples/tipOnComplete/go.mod 0000664 0000000 0000000 00000000157 14172722005 0020151 0 ustar 00root root 0000000 0000000 module github.com/vbauerster/mpb/_examples/tipOnComplete
go 1.14
require github.com/vbauerster/mpb/v7 v7.3.2
mpb-7.3.2/_examples/tipOnComplete/main.go 0000664 0000000 0000000 00000001165 14172722005 0020316 0 ustar 00root root 0000000 0000000 package main
import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v7"
"github.com/vbauerster/mpb/v7/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-7.3.2/_svg/ 0000775 0000000 0000000 00000000000 14172722005 0013237 5 ustar 00root root 0000000 0000000 mpb-7.3.2/_svg/godEMrCZmJkHYH1X9dN4Nm0U7.svg 0000664 0000000 0000000 00000202517 14172722005 0020053 0 ustar 00root root 0000000 0000000