vendor c/image v5.4.2

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg
2020-04-07 12:09:48 +02:00
parent 64b6a19733
commit 42fcdbf1a8
131 changed files with 1936 additions and 683 deletions

View File

@ -1,10 +0,0 @@
module github.com/vbauerster/mpb/v4
require (
github.com/VividCortex/ewma v1.1.1
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6
golang.org/x/sys v0.0.0-20200217220822-9197077df867 // indirect
)
go 1.13

View File

@ -1,41 +0,0 @@
package mpb
import (
"io"
"time"
)
type proxyReader struct {
io.ReadCloser
bar *Bar
iT time.Time
}
func (prox *proxyReader) Read(p []byte) (n int, err error) {
n, err = prox.ReadCloser.Read(p)
if n > 0 {
prox.bar.IncrBy(n, time.Since(prox.iT))
prox.iT = time.Now()
}
if err == io.EOF {
go prox.bar.SetTotal(0, true)
}
return
}
type proxyWriterTo struct {
*proxyReader
wt io.WriterTo
}
func (prox *proxyWriterTo) WriteTo(w io.Writer) (n int64, err error) {
n, err = prox.wt.WriteTo(w)
if n > 0 {
prox.bar.IncrInt64(n, time.Since(prox.iT))
prox.iT = time.Now()
}
if err == io.EOF {
go prox.bar.SetTotal(0, true)
}
return
}

View File

@ -1,11 +1,7 @@
language: go
go:
- 1.12.x
- 1.13.x
env:
- GO111MODULE=on
- 1.14.x
script:
- go test -race ./...

View File

@ -25,8 +25,8 @@ import (
"math/rand"
"time"
"github.com/vbauerster/mpb/v4"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v5"
"github.com/vbauerster/mpb/v5/decor"
)
func main() {
@ -44,8 +44,7 @@ func main() {
decor.Name(name, decor.WC{W: len(name) + 1, C: decor.DidentRight}),
// replace ETA decorator with "done" message, OnComplete event
decor.OnComplete(
// ETA decorator with ewma age of 60, and width reservation of 4
decor.EwmaETA(decor.ET_STYLE_GO, 60, decor.WC{W: 4}), "done",
decor.AverageETA(decor.ET_STYLE_GO, decor.WC{W: 4}), "done",
),
),
mpb.AppendDecorators(decor.Percentage()),
@ -53,17 +52,15 @@ func main() {
// simulating some work
max := 100 * time.Millisecond
for i := 0; i < total; i++ {
start := time.Now()
time.Sleep(time.Duration(rand.Intn(10)+1) * max / 10)
// since ewma decorator is used, we need to pass time.Since(start)
bar.Increment(time.Since(start))
bar.Increment()
}
// wait for our bar to complete and flush
p.Wait()
}
```
#### [Rendering multiple bars](_examples/multiBars//main.go)
#### [Rendering multiple bars](_examples/multiBars/main.go)
```go
var wg sync.WaitGroup
// pass &wg (optional), so p will wait for it eventually
@ -94,10 +91,13 @@ func main() {
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)
// since ewma decorator is used, we need to pass time.Since(start)
bar.Increment(time.Since(start))
bar.Increment()
// we need to call DecoratorEwmaUpdate to fulfill ewma decorator's contract
bar.DecoratorEwmaUpdate(time.Since(start))
}
}()
}

View File

@ -5,51 +5,43 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"strings"
"time"
"unicode/utf8"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v5/decor"
)
// Filler interface.
// Bar renders by calling Filler's Fill method. You can literally have
// any bar kind, by implementing this interface and passing it to the
// *Progress.Add method.
type Filler interface {
// BarFiller interface.
// Bar renders itself by calling BarFiller's Fill method. You can
// literally have any bar kind, by implementing this interface and
// passing it to the *Progress.Add(...) *Bar method.
type BarFiller interface {
Fill(w io.Writer, width int, stat *decor.Statistics)
}
// FillerFunc is function type adapter to convert function into Filler.
type FillerFunc func(w io.Writer, width int, stat *decor.Statistics)
// BarFillerFunc is function type adapter to convert function into Filler.
type BarFillerFunc func(w io.Writer, width int, stat *decor.Statistics)
func (f FillerFunc) Fill(w io.Writer, width int, stat *decor.Statistics) {
func (f BarFillerFunc) Fill(w io.Writer, width int, stat *decor.Statistics) {
f(w, width, stat)
}
// WrapFiller interface.
// If you're implementing custom Filler by wrapping a built-in one,
// it is necessary to implement this interface to retain functionality
// of built-in Filler.
type WrapFiller interface {
Base() Filler
}
// Bar represents a progress Bar.
type Bar struct {
priority int // used by heap
index int // used by heap
extendedLines int
toShutdown bool
toDrop bool
noPop bool
operateState chan func(*bState)
frameCh chan io.Reader
syncTableCh chan [][]chan int
completed chan bool
extendedLines int
toShutdown bool
toDrop bool
noPop bool
hasEwmaDecorators bool
operateState chan func(*bState)
frameCh chan io.Reader
syncTableCh chan [][]chan int
completed chan bool
// cancel is called either by user or on complete event
cancel func()
@ -66,21 +58,23 @@ type Bar struct {
type extFunc func(in io.Reader, tw int, st *decor.Statistics) (out io.Reader, lines int)
type bState struct {
baseF Filler
filler Filler
baseF BarFiller
filler BarFiller
id int
width int
total int64
current int64
lastN int64
iterated bool
trimSpace bool
toComplete bool
completeFlushed bool
noPop bool
aDecorators []decor.Decorator
pDecorators []decor.Decorator
amountReceivers []decor.AmountReceiver
averageDecorators []decor.AverageDecorator
ewmaDecorators []decor.EwmaDecorator
shutdownListeners []decor.ShutdownListener
averageAdjusters []decor.AverageAdjuster
bufP, bufB, bufA *bytes.Buffer
extender extFunc
@ -116,36 +110,13 @@ func newBar(container *Progress, bs *bState) *Bar {
return bar
}
// RemoveAllPrependers removes all prepend functions.
func (b *Bar) RemoveAllPrependers() {
select {
case b.operateState <- func(s *bState) { s.pDecorators = nil }:
case <-b.done:
}
}
// RemoveAllAppenders removes all append functions.
func (b *Bar) RemoveAllAppenders() {
select {
case b.operateState <- func(s *bState) { s.aDecorators = nil }:
case <-b.done:
}
}
// ProxyReader wraps r with metrics required for progress tracking.
// Panics if r is nil.
func (b *Bar) ProxyReader(r io.Reader) io.ReadCloser {
if r == nil {
return nil
panic("expected non nil io.Reader")
}
rc, ok := r.(io.ReadCloser)
if !ok {
rc = ioutil.NopCloser(r)
}
prox := &proxyReader{rc, b, time.Now()}
if wt, ok := r.(io.WriterTo); ok {
return &proxyWriterTo{prox, wt}
}
return prox
return newProxyReader(r, b)
}
// ID returs id of the bar.
@ -170,8 +141,9 @@ func (b *Bar) Current() int64 {
}
}
// SetRefill sets refill, if supported by underlying Filler.
// Useful for resume-able tasks.
// SetRefill fills bar with refill rune up to amount argument.
// Given default bar style is "[=>-]<+", refill rune is '+'.
// To set bar style use mpb.BarStyle(string) BarOption.
func (b *Bar) SetRefill(amount int64) {
type refiller interface {
SetRefill(int64)
@ -183,18 +155,8 @@ func (b *Bar) SetRefill(amount int64) {
}
}
// AdjustAverageDecorators updates start time of all average decorators.
// Useful for resume-able tasks.
func (b *Bar) AdjustAverageDecorators(startTime time.Time) {
b.operateState <- func(s *bState) {
for _, adjuster := range s.averageAdjusters {
adjuster.AverageAdjust(startTime)
}
}
}
// TraverseDecorators traverses all available decorators and calls cb func on each.
func (b *Bar) TraverseDecorators(cb decor.CBFunc) {
func (b *Bar) TraverseDecorators(cb func(decor.Decorator)) {
b.operateState <- func(s *bState) {
for _, decorators := range [...][]decor.Decorator{
s.pDecorators,
@ -208,7 +170,8 @@ func (b *Bar) TraverseDecorators(cb decor.CBFunc) {
}
// SetTotal sets total dynamically.
// Set complete to true, to trigger bar complete event now.
// If total is less or equal to zero it takes progress' current value.
// If complete is true, complete event will be triggered.
func (b *Bar) SetTotal(total int64, complete bool) {
select {
case b.operateState <- func(s *bState) {
@ -227,13 +190,12 @@ func (b *Bar) SetTotal(total int64, complete bool) {
}
}
// SetCurrent sets progress' current to arbitrary amount.
func (b *Bar) SetCurrent(current int64, wdd ...time.Duration) {
// SetCurrent sets progress' current to an arbitrary value.
func (b *Bar) SetCurrent(current int64) {
select {
case b.operateState <- func(s *bState) {
for _, ar := range s.amountReceivers {
ar.NextAmount(current-s.current, wdd...)
}
s.iterated = true
s.lastN = current - s.current
s.current = current
if s.total > 0 && s.current >= s.total {
s.current = s.total
@ -245,25 +207,22 @@ func (b *Bar) SetCurrent(current int64, wdd ...time.Duration) {
}
}
// Increment is a shorthand for b.IncrInt64(1, wdd...).
func (b *Bar) Increment(wdd ...time.Duration) {
b.IncrInt64(1, wdd...)
// Increment is a shorthand for b.IncrInt64(1).
func (b *Bar) Increment() {
b.IncrInt64(1)
}
// IncrBy is a shorthand for b.IncrInt64(int64(n), wdd...).
func (b *Bar) IncrBy(n int, wdd ...time.Duration) {
b.IncrInt64(int64(n), wdd...)
// IncrBy is a shorthand for b.IncrInt64(int64(n)).
func (b *Bar) IncrBy(n int) {
b.IncrInt64(int64(n))
}
// IncrInt64 increments progress bar by amount of n. wdd is an optional
// work duration i.e. time.Since(start), which expected to be passed,
// if any ewma based decorator is used.
func (b *Bar) IncrInt64(n int64, wdd ...time.Duration) {
// IncrInt64 increments progress by amount of n.
func (b *Bar) IncrInt64(n int64) {
select {
case b.operateState <- func(s *bState) {
for _, ar := range s.amountReceivers {
ar.NextAmount(n, wdd...)
}
s.iterated = true
s.lastN = n
s.current += n
if s.total > 0 && s.current >= s.total {
s.current = s.total
@ -275,6 +234,34 @@ func (b *Bar) IncrInt64(n int64, wdd ...time.Duration) {
}
}
// DecoratorEwmaUpdate updates all EWMA based decorators. Should be
// called on each iteration, because EWMA's unit of measure is an
// iteration's duration. Panics if called before *Bar.Incr... family
// methods.
func (b *Bar) DecoratorEwmaUpdate(dur time.Duration) {
select {
case b.operateState <- func(s *bState) {
ewmaIterationUpdate(false, s, dur)
}:
case <-b.done:
ewmaIterationUpdate(true, b.cacheState, dur)
}
}
// DecoratorAverageAdjust adjusts all average based decorators. Call
// if you need to adjust start time of all average based decorators
// or after progress resume.
func (b *Bar) DecoratorAverageAdjust(start time.Time) {
select {
case b.operateState <- func(s *bState) {
for _, d := range s.averageDecorators {
d.AverageAdjust(start)
}
}:
case <-b.done:
}
}
// SetPriority changes bar's order among multiple bars. Zero is highest
// priority, i.e. bar will be on top. If you don't need to set priority
// dynamically, better use BarPriority option.
@ -368,25 +355,26 @@ func (b *Bar) panicToFrame(termWidth int) io.Reader {
}
func (b *Bar) subscribeDecorators() {
var amountReceivers []decor.AmountReceiver
var averageDecorators []decor.AverageDecorator
var ewmaDecorators []decor.EwmaDecorator
var shutdownListeners []decor.ShutdownListener
var averageAdjusters []decor.AverageAdjuster
b.TraverseDecorators(func(d decor.Decorator) {
if d, ok := d.(decor.AmountReceiver); ok {
amountReceivers = append(amountReceivers, d)
if d, ok := d.(decor.AverageDecorator); ok {
averageDecorators = append(averageDecorators, d)
}
if d, ok := d.(decor.EwmaDecorator); ok {
ewmaDecorators = append(ewmaDecorators, d)
}
if d, ok := d.(decor.ShutdownListener); ok {
shutdownListeners = append(shutdownListeners, d)
}
if d, ok := d.(decor.AverageAdjuster); ok {
averageAdjusters = append(averageAdjusters, d)
}
})
b.operateState <- func(s *bState) {
s.amountReceivers = amountReceivers
s.averageDecorators = averageDecorators
s.ewmaDecorators = ewmaDecorators
s.shutdownListeners = shutdownListeners
s.averageAdjusters = averageAdjusters
}
b.hasEwmaDecorators = len(ewmaDecorators) != 0
}
func (b *Bar) refreshTillShutdown() {
@ -475,3 +463,14 @@ func extractBaseDecorator(d decor.Decorator) decor.Decorator {
}
return d
}
func ewmaIterationUpdate(done bool, s *bState, dur time.Duration) {
if !done && !s.iterated {
panic("increment required before ewma iteration update")
} else {
s.iterated = false
}
for _, d := range s.ewmaDecorators {
d.EwmaUpdate(s.lastN, dur)
}
}

View File

@ -4,8 +4,8 @@ import (
"io"
"unicode/utf8"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v4/internal"
"github.com/vbauerster/mpb/v5/decor"
"github.com/vbauerster/mpb/v5/internal"
)
const (
@ -45,8 +45,8 @@ type barFiller struct {
flush func(w io.Writer, bb [][]byte)
}
// NewBarFiller constucts mpb.Filler, to be used with *Progress.Add(...) *Bar method.
func NewBarFiller(style string, reverse bool) Filler {
// NewBarFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
func NewBarFiller(style string, reverse bool) BarFiller {
if style == "" {
style = DefaultBarStyle
}

View File

@ -4,7 +4,7 @@ import (
"bytes"
"io"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v5/decor"
)
// BarOption is a function option which changes the default behavior of a bar.
@ -50,14 +50,9 @@ func BarWidth(width int) BarOption {
}
}
// BarReplaceOnComplete is deprecated. Use BarParkTo instead.
func BarReplaceOnComplete(runningBar *Bar) BarOption {
return BarParkTo(runningBar)
}
// BarParkTo parks constructed bar into the runningBar. In other words,
// constructed bar will replace runningBar after it has been completed.
func BarParkTo(runningBar *Bar) BarOption {
// BarQueueAfter queues this (being constructed) bar to relplace
// runningBar after it has been completed.
func BarQueueAfter(runningBar *Bar) BarOption {
if runningBar == nil {
return nil
}
@ -66,28 +61,29 @@ func BarParkTo(runningBar *Bar) BarOption {
}
}
// BarRemoveOnComplete removes bar filler and decorators if any, on
// complete event.
// BarRemoveOnComplete removes both bar's filler and its decorators
// on complete event.
func BarRemoveOnComplete() BarOption {
return func(s *bState) {
s.dropOnComplete = true
}
}
// BarClearOnComplete clears bar filler only, on complete event.
func BarClearOnComplete() BarOption {
return BarOnComplete("")
// BarFillerClearOnComplete clears bar's filler on complete event.
// It's shortcut for BarFillerOnComplete("").
func BarFillerClearOnComplete() BarOption {
return BarFillerOnComplete("")
}
// BarOnComplete replaces bar filler with message, on complete event.
func BarOnComplete(message string) BarOption {
// BarFillerOnComplete replaces bar's filler with message, on complete event.
func BarFillerOnComplete(message string) BarOption {
return func(s *bState) {
s.filler = makeBarOnCompleteFiller(s.baseF, message)
s.filler = makeBarFillerOnComplete(s.baseF, message)
}
}
func makeBarOnCompleteFiller(filler Filler, message string) Filler {
return FillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
func makeBarFillerOnComplete(filler BarFiller, message string) BarFiller {
return BarFillerFunc(func(w io.Writer, width int, st *decor.Statistics) {
if st.Completed {
io.WriteString(w, message)
} else {
@ -107,7 +103,7 @@ func BarPriority(priority int) BarOption {
// BarExtender is an option to extend bar to the next new line, with
// arbitrary output.
func BarExtender(extender Filler) BarOption {
func BarExtender(extender BarFiller) BarOption {
if extender == nil {
return nil
}
@ -116,7 +112,7 @@ func BarExtender(extender Filler) BarOption {
}
}
func makeExtFunc(extender Filler) extFunc {
func makeExtFunc(extender BarFiller) extFunc {
buf := new(bytes.Buffer)
nl := []byte("\n")
return func(r io.Reader, tw int, st *decor.Statistics) (io.Reader, int) {
@ -132,9 +128,9 @@ func TrimSpace() BarOption {
}
}
// BarStyle overrides mpb.DefaultBarStyle, for example BarStyle("╢▌▌░╟").
// If you need to override `reverse tip` and `refill rune` set 6th and
// 7th rune respectively, for example BarStyle("[=>-]<+").
// BarStyle overrides mpb.DefaultBarStyle which is "[=>-]<+".
// It's ok to pass string containing just 5 runes, for example "╢▌▌░╟",
// if you don't need to override '<' (reverse tip) and '+' (refill rune).
func BarStyle(style string) BarOption {
if style == "" {
return nil
@ -175,7 +171,7 @@ func SpinnerStyle(frames []string) BarOption {
if len(frames) == 0 {
return nil
}
chk := func(filler Filler) (interface{}, bool) {
chk := func(filler BarFiller) (interface{}, bool) {
t, ok := filler.(*spinnerFiller)
return t, ok
}
@ -189,7 +185,7 @@ func SpinnerStyle(frames []string) BarOption {
// actual type. If you implement your own Filler, so most probably
// you'll need this. See BarStyle or SpinnerStyle for example.
func MakeFillerTypeSpecificBarOption(
typeChecker func(Filler) (interface{}, bool),
typeChecker func(BarFiller) (interface{}, bool),
cb func(interface{}),
) BarOption {
return func(s *bState) {

View File

@ -84,10 +84,17 @@ type Wrapper interface {
Base() Decorator
}
// AmountReceiver interface.
// EWMA based decorators need to implement this one.
type AmountReceiver interface {
NextAmount(int64, ...time.Duration)
// EwmaDecorator interface.
// EWMA based decorators should implement this one.
type EwmaDecorator interface {
EwmaUpdate(int64, time.Duration)
}
// AverageDecorator interface.
// Average decorators should implement this interface to provide start
// time adjustment facility, for resume-able tasks.
type AverageDecorator interface {
AverageAdjust(time.Time)
}
// ShutdownListener interface.
@ -97,17 +104,8 @@ type ShutdownListener interface {
Shutdown()
}
// AverageAdjuster interface.
// Average decorators should implement this interface to provide start
// time adjustment facility, for resume-able tasks.
type AverageAdjuster interface {
AverageAdjust(time.Time)
}
// CBFunc convenience call back func type.
type CBFunc func(Decorator)
// Global convenience instances of WC with sync width bit set.
// To be used with multiple bars only, i.e. not effective for single bar usage.
var (
WCSyncWidth = WC{C: DSyncWidth}
WCSyncWidthR = WC{C: DSyncWidthR}

View File

@ -1,5 +1,5 @@
/*
Package decor provides common decorators for "github.com/vbauerster/mpb/v4" module.
Package decor provides common decorators for "github.com/vbauerster/mpb/v5" module.
Some decorators returned by this package might have a closure state. It is ok to use
decorators concurrently, unless you share the same decorator among multiple

View File

@ -23,11 +23,11 @@ func (f TimeNormalizerFunc) Normalize(src time.Duration) time.Duration {
}
// EwmaETA exponential-weighted-moving-average based ETA decorator.
// Note that it's necessary to supply bar.Incr* methods with incremental
// work duration as second argument, in order for this decorator to
// work correctly. This decorator is a wrapper of MovingAverageETA.
// For this decorator to work correctly you have to measure each
// iteration's duration and pass it to the
// *Bar.DecoratorEwmaUpdate(time.Duration) method after each increment.
func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator {
var average MovingAverage
var average ewma.MovingAverage
if age == 0 {
average = ewma.NewMovingAverage()
} else {
@ -46,7 +46,7 @@ func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator {
//
// `wcc` optional WC config
//
func MovingAverageETA(style TimeStyle, average MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator {
func MovingAverageETA(style TimeStyle, average ewma.MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator {
d := &movingAverageETA{
WC: initWC(wcc...),
average: average,
@ -72,12 +72,8 @@ func (d *movingAverageETA) Decor(s *Statistics) string {
return d.FormatMsg(d.producer(remaining))
}
func (d *movingAverageETA) NextAmount(n int64, wdd ...time.Duration) {
var workDuration time.Duration
for _, wd := range wdd {
workDuration = wd
}
durPerItem := float64(workDuration) / float64(n)
func (d *movingAverageETA) EwmaUpdate(n int64, dur time.Duration) {
durPerItem := float64(dur) / float64(n)
if math.IsInf(durPerItem, 0) || math.IsNaN(durPerItem) {
return
}

View File

@ -7,11 +7,6 @@ import (
"github.com/VividCortex/ewma"
)
// MovingAverage is the interface that computes a moving average over
// a time-series stream of numbers. The average may be over a window
// or exponentially decaying.
type MovingAverage = ewma.MovingAverage
type threadSafeMovingAverage struct {
ewma.MovingAverage
mu sync.Mutex
@ -68,6 +63,6 @@ func (s *medianWindow) Set(value float64) {
}
// NewMedian is fixed last 3 samples median MovingAverage.
func NewMedian() MovingAverage {
func NewMedian() ewma.MovingAverage {
return NewThreadSafeMovingAverage(new(medianWindow))
}

View File

@ -5,7 +5,7 @@ import (
"io"
"strconv"
"github.com/vbauerster/mpb/v4/internal"
"github.com/vbauerster/mpb/v5/internal"
)
type percentageType float64

View File

@ -28,11 +28,11 @@ func (self *speedFormatter) Format(st fmt.State, verb rune) {
}
// EwmaSpeed exponential-weighted-moving-average based speed decorator.
// Note that it's necessary to supply bar.Incr* methods with incremental
// work duration as second argument, in order for this decorator to
// work correctly. This decorator is a wrapper of MovingAverageSpeed.
// For this decorator to work correctly you have to measure each
// iteration's duration and pass it to the
// *Bar.DecoratorEwmaUpdate(time.Duration) method after each increment.
func EwmaSpeed(unit int, format string, age float64, wcc ...WC) Decorator {
var average MovingAverage
var average ewma.MovingAverage
if age == 0 {
average = ewma.NewMovingAverage()
} else {
@ -59,7 +59,7 @@ func EwmaSpeed(unit int, format string, age float64, wcc ...WC) Decorator {
// unit=UnitKB, format="%.1f" output: "1.0MB/s"
// unit=UnitKB, format="% .1f" output: "1.0 MB/s"
//
func MovingAverageSpeed(unit int, format string, average MovingAverage, wcc ...WC) Decorator {
func MovingAverageSpeed(unit int, format string, average ewma.MovingAverage, wcc ...WC) Decorator {
if format == "" {
format = "%.0f"
}
@ -89,12 +89,8 @@ func (d *movingAverageSpeed) Decor(s *Statistics) string {
return d.FormatMsg(d.msg)
}
func (d *movingAverageSpeed) NextAmount(n int64, wdd ...time.Duration) {
var workDuration time.Duration
for _, wd := range wdd {
workDuration = wd
}
durPerByte := float64(workDuration) / float64(n)
func (d *movingAverageSpeed) EwmaUpdate(n int64, dur time.Duration) {
durPerByte := float64(dur) / float64(n)
if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) {
return
}

10
vendor/github.com/vbauerster/mpb/v5/go.mod generated vendored Normal file
View File

@ -0,0 +1,10 @@
module github.com/vbauerster/mpb/v5
require (
github.com/VividCortex/ewma v1.1.1
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
)
go 1.14

View File

@ -3,11 +3,11 @@ github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmx
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6 h1:Sy5bstxEqwwbYs6n0/pBuxKENqOeZUgD45Gp3Q3pqLg=
golang.org/x/crypto v0.0.0-20200214034016-1d94cc7ab1c6/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 h1:QmwruyY+bKbDDL0BaglrbZABEali68eoMFhTZpCjYVA=
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200217220822-9197077df867 h1:JoRuNIf+rpHl+VhScRQQvzbHed86tKkqwPMV34T8myw=
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

View File

@ -12,8 +12,8 @@ import (
"sync"
"time"
"github.com/vbauerster/mpb/v4/cwriter"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v5/cwriter"
"github.com/vbauerster/mpb/v5/decor"
)
const (
@ -111,7 +111,7 @@ func (p *Progress) AddSpinner(total int64, alignment SpinnerAlignment, options .
// Add creates a bar which renders itself by provided filler.
// Set total to 0, if you plan to update it later.
// Panics if *Progress instance is done, i.e. called after *Progress.Wait().
func (p *Progress) Add(total int64, filler Filler, options ...BarOption) *Bar {
func (p *Progress) Add(total int64, filler BarFiller, options ...BarOption) *Bar {
if filler == nil {
filler = NewBarFiller(DefaultBarStyle, false)
}
@ -166,7 +166,7 @@ func (p *Progress) setBarPriority(b *Bar, priority int) {
}
}
// UpdateBarPriority same as *Bar.SetPriority.
// UpdateBarPriority same as *Bar.SetPriority(int).
func (p *Progress) UpdateBarPriority(b *Bar, priority int) {
p.setBarPriority(b, priority)
}
@ -340,7 +340,7 @@ func (s *pState) updateSyncMatrix() {
}
}
func (s *pState) makeBarState(total int64, filler Filler, options ...BarOption) *bState {
func (s *pState) makeBarState(total int64, filler BarFiller, options ...BarOption) *bState {
bs := &bState{
total: total,
baseF: extractBaseFiller(filler),
@ -388,8 +388,11 @@ func syncWidth(matrix map[int][]chan int) {
}
}
func extractBaseFiller(f Filler) Filler {
if f, ok := f.(WrapFiller); ok {
func extractBaseFiller(f BarFiller) BarFiller {
type wrapper interface {
Base() BarFiller
}
if f, ok := f.(wrapper); ok {
return extractBaseFiller(f.Base())
}
return f

90
vendor/github.com/vbauerster/mpb/v5/proxyreader.go generated vendored Normal file
View File

@ -0,0 +1,90 @@
package mpb
import (
"io"
"io/ioutil"
"time"
)
type proxyReader struct {
io.ReadCloser
bar *Bar
}
func (x *proxyReader) Read(p []byte) (int, error) {
n, err := x.ReadCloser.Read(p)
x.bar.IncrBy(n)
if err == io.EOF {
go x.bar.SetTotal(0, true)
}
return n, err
}
type proxyWriterTo struct {
io.ReadCloser // *proxyReader
wt io.WriterTo
bar *Bar
}
func (x *proxyWriterTo) WriteTo(w io.Writer) (int64, error) {
n, err := x.wt.WriteTo(w)
x.bar.IncrInt64(n)
if err == io.EOF {
go x.bar.SetTotal(0, true)
}
return n, err
}
type ewmaProxyReader struct {
io.ReadCloser // *proxyReader
bar *Bar
iT time.Time
}
func (x *ewmaProxyReader) Read(p []byte) (int, error) {
n, err := x.ReadCloser.Read(p)
if n > 0 {
x.bar.DecoratorEwmaUpdate(time.Since(x.iT))
x.iT = time.Now()
}
return n, err
}
type ewmaProxyWriterTo struct {
io.ReadCloser // *ewmaProxyReader
wt io.WriterTo // *proxyWriterTo
bar *Bar
iT time.Time
}
func (x *ewmaProxyWriterTo) WriteTo(w io.Writer) (int64, error) {
n, err := x.wt.WriteTo(w)
if n > 0 {
x.bar.DecoratorEwmaUpdate(time.Since(x.iT))
x.iT = time.Now()
}
return n, err
}
func newProxyReader(r io.Reader, bar *Bar) io.ReadCloser {
rc := toReadCloser(r)
rc = &proxyReader{rc, bar}
if wt, isWriterTo := r.(io.WriterTo); bar.hasEwmaDecorators {
now := time.Now()
rc = &ewmaProxyReader{rc, bar, now}
if isWriterTo {
rc = &ewmaProxyWriterTo{rc, wt, bar, now}
}
} else if isWriterTo {
rc = &proxyWriterTo{rc, wt, bar}
}
return rc
}
func toReadCloser(r io.Reader) io.ReadCloser {
if rc, ok := r.(io.ReadCloser); ok {
return rc
}
return ioutil.NopCloser(r)
}

View File

@ -5,7 +5,7 @@ import (
"strings"
"unicode/utf8"
"github.com/vbauerster/mpb/v4/decor"
"github.com/vbauerster/mpb/v5/decor"
)
// SpinnerAlignment enum.
@ -27,8 +27,8 @@ type spinnerFiller struct {
alignment SpinnerAlignment
}
// NewSpinnerFiller constucts mpb.Filler, to be used with *Progress.Add(...) *Bar method.
func NewSpinnerFiller(style []string, alignment SpinnerAlignment) Filler {
// NewSpinnerFiller constucts mpb.BarFiller, to be used with *Progress.Add(...) *Bar method.
func NewSpinnerFiller(style []string, alignment SpinnerAlignment) BarFiller {
if len(style) == 0 {
style = DefaultSpinnerStyle
}