summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v4/decor
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-12-19 13:29:25 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2019-12-20 09:30:47 -0500
commit50ece79387dcf6c748e3ae1bd6a7067059c0dfe3 (patch)
tree6b30c4f66f7be315ff2257447be3818be98fb50f /vendor/github.com/vbauerster/mpb/v4/decor
parenta359ca0d1825859dd8b7c1384f11d703ec6625b4 (diff)
downloadpodman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.tar.gz
podman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.tar.bz2
podman-50ece79387dcf6c748e3ae1bd6a7067059c0dfe3.zip
build(deps): bump github.com/containers/image/v5 from 5.0.0 to 5.1.0
Bumps [github.com/containers/image/v5](https://github.com/containers/image) from 5.0.0 to 5.1.0. - [Release notes](https://github.com/containers/image/releases) - [Commits](https://github.com/containers/image/compare/v5.0.0...v5.1.0) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v4/decor')
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/counters.go84
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/decorator.go173
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/doc.go21
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/elapsed.go48
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/eta.go212
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/merge.go97
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/moving_average.go40
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/name.go27
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/on_complete.go36
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/percentage.go72
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/size_type.go109
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/sizeb1000_string.go41
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/sizeb1024_string.go41
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/speed.go175
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/spinner.go35
15 files changed, 1211 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/counters.go b/vendor/github.com/vbauerster/mpb/v4/decor/counters.go
new file mode 100644
index 000000000..32bcdf76a
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/counters.go
@@ -0,0 +1,84 @@
+package decor
+
+import (
+ "fmt"
+)
+
+const (
+ _ = iota
+ UnitKiB
+ UnitKB
+)
+
+// CountersNoUnit is a wrapper around Counters with no unit param.
+func CountersNoUnit(pairFmt string, wcc ...WC) Decorator {
+ return Counters(0, pairFmt, wcc...)
+}
+
+// CountersKibiByte is a wrapper around Counters with predefined unit
+// UnitKiB (bytes/1024).
+func CountersKibiByte(pairFmt string, wcc ...WC) Decorator {
+ return Counters(UnitKiB, pairFmt, wcc...)
+}
+
+// CountersKiloByte is a wrapper around Counters with predefined unit
+// UnitKB (bytes/1000).
+func CountersKiloByte(pairFmt string, wcc ...WC) Decorator {
+ return Counters(UnitKB, pairFmt, wcc...)
+}
+
+// Counters decorator with dynamic unit measure adjustment.
+//
+// `unit` one of [0|UnitKiB|UnitKB] zero for no unit
+//
+// `pairFmt` printf compatible verbs for current and total, like "%f" or "%d"
+//
+// `wcc` optional WC config
+//
+// pairFmt example if unit=UnitKB:
+//
+// pairFmt="%.1f / %.1f" output: "1.0MB / 12.0MB"
+// pairFmt="% .1f / % .1f" output: "1.0 MB / 12.0 MB"
+// pairFmt="%d / %d" output: "1MB / 12MB"
+// pairFmt="% d / % d" output: "1 MB / 12 MB"
+//
+func Counters(unit int, pairFmt string, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ d := &countersDecorator{
+ WC: wc.Init(),
+ producer: chooseSizeProducer(unit, pairFmt),
+ }
+ return d
+}
+
+type countersDecorator struct {
+ WC
+ producer func(*Statistics) string
+}
+
+func (d *countersDecorator) Decor(st *Statistics) string {
+ return d.FormatMsg(d.producer(st))
+}
+
+func chooseSizeProducer(unit int, format string) func(*Statistics) string {
+ if format == "" {
+ format = "%d / %d"
+ }
+ switch unit {
+ case UnitKiB:
+ return func(st *Statistics) string {
+ return fmt.Sprintf(format, SizeB1024(st.Current), SizeB1024(st.Total))
+ }
+ case UnitKB:
+ return func(st *Statistics) string {
+ return fmt.Sprintf(format, SizeB1000(st.Current), SizeB1000(st.Total))
+ }
+ default:
+ return func(st *Statistics) string {
+ return fmt.Sprintf(format, st.Current, st.Total)
+ }
+ }
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go b/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
new file mode 100644
index 000000000..5c0d16880
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
@@ -0,0 +1,173 @@
+package decor
+
+import (
+ "fmt"
+ "time"
+ "unicode/utf8"
+)
+
+const (
+ // DidentRight bit specifies identation direction.
+ // |foo |b | With DidentRight
+ // | foo| b| Without DidentRight
+ DidentRight = 1 << iota
+
+ // DextraSpace bit adds extra space, makes sense with DSyncWidth only.
+ // When DidentRight bit set, the space will be added to the right,
+ // otherwise to the left.
+ DextraSpace
+
+ // DSyncWidth bit enables same column width synchronization.
+ // Effective with multiple bars only.
+ DSyncWidth
+
+ // DSyncWidthR is shortcut for DSyncWidth|DidentRight
+ DSyncWidthR = DSyncWidth | DidentRight
+
+ // DSyncSpace is shortcut for DSyncWidth|DextraSpace
+ DSyncSpace = DSyncWidth | DextraSpace
+
+ // DSyncSpaceR is shortcut for DSyncWidth|DextraSpace|DidentRight
+ DSyncSpaceR = DSyncWidth | DextraSpace | DidentRight
+)
+
+// TimeStyle enum.
+type TimeStyle int
+
+// TimeStyle kinds.
+const (
+ ET_STYLE_GO TimeStyle = iota
+ ET_STYLE_HHMMSS
+ ET_STYLE_HHMM
+ ET_STYLE_MMSS
+)
+
+// Statistics consists of progress related statistics, that Decorator
+// may need.
+type Statistics struct {
+ ID int
+ Completed bool
+ Total int64
+ Current int64
+}
+
+// Decorator interface.
+// Implementors should embed WC type, that way only single method
+// Decor(*Statistics) needs to be implemented, the rest will be handled
+// by WC type.
+type Decorator interface {
+ Configurator
+ Synchronizer
+ Decor(*Statistics) string
+}
+
+// Synchronizer interface.
+// All decorators implement this interface implicitly. Its Sync
+// method exposes width sync channel, if DSyncWidth bit is set.
+type Synchronizer interface {
+ Sync() (chan int, bool)
+}
+
+// Configurator interface.
+type Configurator interface {
+ GetConf() WC
+ SetConf(WC)
+}
+
+// Wrapper interface.
+// If you're implementing custom Decorator by wrapping a built-in one,
+// it is necessary to implement this interface to retain functionality
+// of built-in Decorator.
+type Wrapper interface {
+ Base() Decorator
+}
+
+// AmountReceiver interface.
+// EWMA based decorators need to implement this one.
+type AmountReceiver interface {
+ NextAmount(int64, ...time.Duration)
+}
+
+// ShutdownListener interface.
+// If decorator needs to be notified once upon bar shutdown event, so
+// this is the right interface to implement.
+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.
+var (
+ WCSyncWidth = WC{C: DSyncWidth}
+ WCSyncWidthR = WC{C: DSyncWidthR}
+ WCSyncSpace = WC{C: DSyncSpace}
+ WCSyncSpaceR = WC{C: DSyncSpaceR}
+)
+
+// WC is a struct with two public fields W and C, both of int type.
+// W represents width and C represents bit set of width related config.
+// A decorator should embed WC, to enable width synchronization.
+type WC struct {
+ W int
+ C int
+ dynFormat string
+ staticFormat string
+ wsync chan int
+}
+
+// FormatMsg formats final message according to WC.W and WC.C.
+// Should be called by any Decorator implementation.
+func (wc *WC) FormatMsg(msg string) string {
+ if (wc.C & DSyncWidth) != 0 {
+ wc.wsync <- utf8.RuneCountInString(msg)
+ max := <-wc.wsync
+ if (wc.C & DextraSpace) != 0 {
+ max++
+ }
+ return fmt.Sprintf(fmt.Sprintf(wc.dynFormat, max), msg)
+ }
+ return fmt.Sprintf(wc.staticFormat, msg)
+}
+
+// Init initializes width related config.
+func (wc *WC) Init() WC {
+ wc.dynFormat = "%%"
+ if (wc.C & DidentRight) != 0 {
+ wc.dynFormat += "-"
+ }
+ wc.dynFormat += "%ds"
+ wc.staticFormat = fmt.Sprintf(wc.dynFormat, wc.W)
+ if (wc.C & DSyncWidth) != 0 {
+ // it's deliberate choice to override wsync on each Init() call,
+ // this way globals like WCSyncSpace can be reused
+ wc.wsync = make(chan int)
+ }
+ return *wc
+}
+
+// Sync is implementation of Synchronizer interface.
+func (wc *WC) Sync() (chan int, bool) {
+ if (wc.C&DSyncWidth) != 0 && wc.wsync == nil {
+ panic(fmt.Sprintf("%T is not initialized", wc))
+ }
+ return wc.wsync, (wc.C & DSyncWidth) != 0
+}
+
+// GetConf is implementation of Configurator interface.
+func (wc *WC) GetConf() WC {
+ return *wc
+}
+
+// SetConf is implementation of Configurator interface.
+func (wc *WC) SetConf(conf WC) {
+ *wc = conf.Init()
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/doc.go b/vendor/github.com/vbauerster/mpb/v4/decor/doc.go
new file mode 100644
index 000000000..b595e8015
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/doc.go
@@ -0,0 +1,21 @@
+/*
+ Package decor provides common decorators for "github.com/vbauerster/mpb/v4" 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
+ *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance.
+
+ Don't:
+
+ p := mpb.New()
+ name := decor.Name("bar")
+ p.AddBar(100, mpb.AppendDecorators(name))
+ p.AddBar(100, mpb.AppendDecorators(name))
+
+ Do:
+
+ p := mpb.New()
+ p.AddBar(100, mpb.AppendDecorators(decor.Name("bar1")))
+ p.AddBar(100, mpb.AppendDecorators(decor.Name("bar2")))
+*/
+package decor
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/elapsed.go b/vendor/github.com/vbauerster/mpb/v4/decor/elapsed.go
new file mode 100644
index 000000000..ac2873143
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/elapsed.go
@@ -0,0 +1,48 @@
+package decor
+
+import (
+ "time"
+)
+
+// Elapsed decorator. It's wrapper of NewElapsed.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `wcc` optional WC config
+func Elapsed(style TimeStyle, wcc ...WC) Decorator {
+ return NewElapsed(style, time.Now(), wcc...)
+}
+
+// NewElapsed returns elapsed time decorator.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `startTime` start time
+//
+// `wcc` optional WC config
+func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ d := &elapsedDecorator{
+ WC: wc.Init(),
+ startTime: startTime,
+ producer: chooseTimeProducer(style),
+ }
+ return d
+}
+
+type elapsedDecorator struct {
+ WC
+ startTime time.Time
+ producer func(time.Duration) string
+ msg string
+}
+
+func (d *elapsedDecorator) Decor(st *Statistics) string {
+ if !st.Completed {
+ d.msg = d.producer(time.Since(d.startTime))
+ }
+ return d.FormatMsg(d.msg)
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/eta.go b/vendor/github.com/vbauerster/mpb/v4/decor/eta.go
new file mode 100644
index 000000000..818cded17
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/eta.go
@@ -0,0 +1,212 @@
+package decor
+
+import (
+ "fmt"
+ "math"
+ "time"
+
+ "github.com/VividCortex/ewma"
+)
+
+// TimeNormalizer interface. Implementors could be passed into
+// MovingAverageETA, in order to affect i.e. normalize its output.
+type TimeNormalizer interface {
+ Normalize(time.Duration) time.Duration
+}
+
+// TimeNormalizerFunc is function type adapter to convert function
+// into TimeNormalizer.
+type TimeNormalizerFunc func(time.Duration) time.Duration
+
+func (f TimeNormalizerFunc) Normalize(src time.Duration) time.Duration {
+ return f(src)
+}
+
+// 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.
+func EwmaETA(style TimeStyle, age float64, wcc ...WC) Decorator {
+ var average MovingAverage
+ if age == 0 {
+ average = ewma.NewMovingAverage()
+ } else {
+ average = ewma.NewMovingAverage(age)
+ }
+ return MovingAverageETA(style, average, nil, wcc...)
+}
+
+// MovingAverageETA decorator relies on MovingAverage implementation to calculate its average.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `average` implementation of MovingAverage interface
+//
+// `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer]
+//
+// `wcc` optional WC config
+func MovingAverageETA(style TimeStyle, average MovingAverage, normalizer TimeNormalizer, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ d := &movingAverageETA{
+ WC: wc.Init(),
+ average: average,
+ normalizer: normalizer,
+ producer: chooseTimeProducer(style),
+ }
+ return d
+}
+
+type movingAverageETA struct {
+ WC
+ average ewma.MovingAverage
+ normalizer TimeNormalizer
+ producer func(time.Duration) string
+}
+
+func (d *movingAverageETA) Decor(st *Statistics) string {
+ v := math.Round(d.average.Value())
+ remaining := time.Duration((st.Total - st.Current) * int64(v))
+ if d.normalizer != nil {
+ remaining = d.normalizer.Normalize(remaining)
+ }
+ 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)
+ if math.IsInf(durPerItem, 0) || math.IsNaN(durPerItem) {
+ return
+ }
+ d.average.Add(durPerItem)
+}
+
+// AverageETA decorator. It's wrapper of NewAverageETA.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `wcc` optional WC config
+func AverageETA(style TimeStyle, wcc ...WC) Decorator {
+ return NewAverageETA(style, time.Now(), nil, wcc...)
+}
+
+// NewAverageETA decorator with user provided start time.
+//
+// `style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]
+//
+// `startTime` start time
+//
+// `normalizer` available implementations are [FixedIntervalTimeNormalizer|MaxTolerateTimeNormalizer]
+//
+// `wcc` optional WC config
+func NewAverageETA(style TimeStyle, startTime time.Time, normalizer TimeNormalizer, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ d := &averageETA{
+ WC: wc.Init(),
+ startTime: startTime,
+ normalizer: normalizer,
+ producer: chooseTimeProducer(style),
+ }
+ return d
+}
+
+type averageETA struct {
+ WC
+ startTime time.Time
+ normalizer TimeNormalizer
+ producer func(time.Duration) string
+}
+
+func (d *averageETA) Decor(st *Statistics) string {
+ var remaining time.Duration
+ if st.Current != 0 {
+ durPerItem := float64(time.Since(d.startTime)) / float64(st.Current)
+ durPerItem = math.Round(durPerItem)
+ remaining = time.Duration((st.Total - st.Current) * int64(durPerItem))
+ if d.normalizer != nil {
+ remaining = d.normalizer.Normalize(remaining)
+ }
+ }
+ return d.FormatMsg(d.producer(remaining))
+}
+
+func (d *averageETA) AverageAdjust(startTime time.Time) {
+ d.startTime = startTime
+}
+
+// MaxTolerateTimeNormalizer returns implementation of TimeNormalizer.
+func MaxTolerateTimeNormalizer(maxTolerate time.Duration) TimeNormalizer {
+ var normalized time.Duration
+ var lastCall time.Time
+ return TimeNormalizerFunc(func(remaining time.Duration) time.Duration {
+ if diff := normalized - remaining; diff <= 0 || diff > maxTolerate || remaining < time.Minute {
+ normalized = remaining
+ lastCall = time.Now()
+ return remaining
+ }
+ normalized -= time.Since(lastCall)
+ lastCall = time.Now()
+ return normalized
+ })
+}
+
+// FixedIntervalTimeNormalizer returns implementation of TimeNormalizer.
+func FixedIntervalTimeNormalizer(updInterval int) TimeNormalizer {
+ var normalized time.Duration
+ var lastCall time.Time
+ var count int
+ return TimeNormalizerFunc(func(remaining time.Duration) time.Duration {
+ if count == 0 || remaining < time.Minute {
+ count = updInterval
+ normalized = remaining
+ lastCall = time.Now()
+ return remaining
+ }
+ count--
+ normalized -= time.Since(lastCall)
+ lastCall = time.Now()
+ return normalized
+ })
+}
+
+func chooseTimeProducer(style TimeStyle) func(time.Duration) string {
+ switch style {
+ case ET_STYLE_HHMMSS:
+ return func(remaining time.Duration) string {
+ hours := int64(remaining/time.Hour) % 60
+ minutes := int64(remaining/time.Minute) % 60
+ seconds := int64(remaining/time.Second) % 60
+ return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
+ }
+ case ET_STYLE_HHMM:
+ return func(remaining time.Duration) string {
+ hours := int64(remaining/time.Hour) % 60
+ minutes := int64(remaining/time.Minute) % 60
+ return fmt.Sprintf("%02d:%02d", hours, minutes)
+ }
+ case ET_STYLE_MMSS:
+ return func(remaining time.Duration) string {
+ hours := int64(remaining/time.Hour) % 60
+ minutes := int64(remaining/time.Minute) % 60
+ seconds := int64(remaining/time.Second) % 60
+ if hours > 0 {
+ return fmt.Sprintf("%02d:%02d:%02d", hours, minutes, seconds)
+ }
+ return fmt.Sprintf("%02d:%02d", minutes, seconds)
+ }
+ default:
+ return func(remaining time.Duration) string {
+ // strip off nanoseconds
+ return ((remaining / time.Second) * time.Second).String()
+ }
+ }
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/merge.go b/vendor/github.com/vbauerster/mpb/v4/decor/merge.go
new file mode 100644
index 000000000..fdf9e107b
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/merge.go
@@ -0,0 +1,97 @@
+package decor
+
+import (
+ "fmt"
+ "unicode/utf8"
+)
+
+// Merge wraps its decorator argument with intention to sync width
+// with several decorators of another bar. Visual example:
+//
+// +----+--------+---------+--------+
+// | B1 | MERGE(D, P1, Pn) |
+// +----+--------+---------+--------+
+// | B2 | D0 | D1 | Dn |
+// +----+--------+---------+--------+
+//
+func Merge(decorator Decorator, placeholders ...WC) Decorator {
+ if _, ok := decorator.Sync(); !ok || len(placeholders) == 0 {
+ return decorator
+ }
+ md := &mergeDecorator{
+ Decorator: decorator,
+ wc: decorator.GetConf(),
+ placeHolders: make([]*placeHolderDecorator, len(placeholders)),
+ }
+ decorator.SetConf(WC{})
+ for i, wc := range placeholders {
+ if (wc.C & DSyncWidth) == 0 {
+ return decorator
+ }
+ md.placeHolders[i] = &placeHolderDecorator{
+ WC: wc.Init(),
+ wch: make(chan int),
+ }
+ }
+ return md
+}
+
+type mergeDecorator struct {
+ Decorator
+ wc WC
+ placeHolders []*placeHolderDecorator
+}
+
+func (d *mergeDecorator) GetConf() WC {
+ return d.wc
+}
+
+func (d *mergeDecorator) SetConf(conf WC) {
+ d.wc = conf.Init()
+}
+
+func (d *mergeDecorator) MergeUnwrap() []Decorator {
+ decorators := make([]Decorator, len(d.placeHolders))
+ for i, ph := range d.placeHolders {
+ decorators[i] = ph
+ }
+ return decorators
+}
+
+func (d *mergeDecorator) Sync() (chan int, bool) {
+ return d.wc.Sync()
+}
+
+func (d *mergeDecorator) Base() Decorator {
+ return d.Decorator
+}
+
+func (d *mergeDecorator) Decor(st *Statistics) string {
+ msg := d.Decorator.Decor(st)
+ msgLen := utf8.RuneCountInString(msg)
+
+ var space int
+ for _, ph := range d.placeHolders {
+ space += <-ph.wch
+ }
+
+ d.wc.wsync <- msgLen - space
+
+ max := <-d.wc.wsync
+ if (d.wc.C & DextraSpace) != 0 {
+ max++
+ }
+ return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max+space), msg)
+}
+
+type placeHolderDecorator struct {
+ WC
+ wch chan int
+}
+
+func (d *placeHolderDecorator) Decor(st *Statistics) string {
+ go func() {
+ d.wch <- utf8.RuneCountInString(d.FormatMsg(""))
+ }()
+ return ""
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/moving_average.go b/vendor/github.com/vbauerster/mpb/v4/decor/moving_average.go
new file mode 100644
index 000000000..933b1f2cd
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/moving_average.go
@@ -0,0 +1,40 @@
+package decor
+
+import (
+ "sort"
+
+ "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 medianWindow [3]float64
+
+func (s *medianWindow) Len() int { return len(s) }
+func (s *medianWindow) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+func (s *medianWindow) Less(i, j int) bool { return s[i] < s[j] }
+
+func (s *medianWindow) Add(value float64) {
+ s[0], s[1] = s[1], s[2]
+ s[2] = value
+}
+
+func (s *medianWindow) Value() float64 {
+ tmp := *s
+ sort.Sort(&tmp)
+ return tmp[1]
+}
+
+func (s *medianWindow) Set(value float64) {
+ for i := 0; i < len(s); i++ {
+ s[i] = value
+ }
+}
+
+// NewMedian is fixed last 3 samples median MovingAverage.
+func NewMedian() MovingAverage {
+ return new(medianWindow)
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/name.go b/vendor/github.com/vbauerster/mpb/v4/decor/name.go
new file mode 100644
index 000000000..2d5865f6c
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/name.go
@@ -0,0 +1,27 @@
+package decor
+
+// Name returns name decorator.
+//
+// `name` string to display
+//
+// `wcc` optional WC config
+func Name(name string, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ d := &nameDecorator{
+ WC: wc.Init(),
+ msg: name,
+ }
+ return d
+}
+
+type nameDecorator struct {
+ WC
+ msg string
+}
+
+func (d *nameDecorator) Decor(st *Statistics) string {
+ return d.FormatMsg(d.msg)
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/on_complete.go b/vendor/github.com/vbauerster/mpb/v4/decor/on_complete.go
new file mode 100644
index 000000000..714a0ded3
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/on_complete.go
@@ -0,0 +1,36 @@
+package decor
+
+// OnComplete returns decorator, which wraps provided decorator, with
+// sole purpose to display provided message on complete event.
+//
+// `decorator` Decorator to wrap
+//
+// `message` message to display on complete event
+func OnComplete(decorator Decorator, message string) Decorator {
+ d := &onCompleteWrapper{
+ Decorator: decorator,
+ msg: message,
+ }
+ if md, ok := decorator.(*mergeDecorator); ok {
+ d.Decorator, md.Decorator = md.Decorator, d
+ return md
+ }
+ return d
+}
+
+type onCompleteWrapper struct {
+ Decorator
+ msg string
+}
+
+func (d *onCompleteWrapper) Decor(st *Statistics) string {
+ if st.Completed {
+ wc := d.GetConf()
+ return wc.FormatMsg(d.msg)
+ }
+ return d.Decorator.Decor(st)
+}
+
+func (d *onCompleteWrapper) Base() Decorator {
+ return d.Decorator
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/percentage.go b/vendor/github.com/vbauerster/mpb/v4/decor/percentage.go
new file mode 100644
index 000000000..abf343a35
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/percentage.go
@@ -0,0 +1,72 @@
+package decor
+
+import (
+ "fmt"
+ "io"
+ "strconv"
+
+ "github.com/vbauerster/mpb/v4/internal"
+)
+
+type percentageType float64
+
+func (s percentageType) Format(st fmt.State, verb rune) {
+ var prec int
+ switch verb {
+ case 'd':
+ case 's':
+ prec = -1
+ default:
+ if p, ok := st.Precision(); ok {
+ prec = p
+ } else {
+ prec = 6
+ }
+ }
+
+ io.WriteString(st, strconv.FormatFloat(float64(s), 'f', prec, 64))
+
+ if st.Flag(' ') {
+ io.WriteString(st, " ")
+ }
+ io.WriteString(st, "%")
+}
+
+// Percentage returns percentage decorator. It's a wrapper of NewPercentage.
+func Percentage(wcc ...WC) Decorator {
+ return NewPercentage("% d", wcc...)
+}
+
+// NewPercentage percentage decorator with custom fmt string.
+//
+// fmt examples:
+//
+// fmt="%.1f" output: "1.0%"
+// fmt="% .1f" output: "1.0 %"
+// fmt="%d" output: "1%"
+// fmt="% d" output: "1 %"
+//
+func NewPercentage(fmt string, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ if fmt == "" {
+ fmt = "% d"
+ }
+ d := &percentageDecorator{
+ WC: wc.Init(),
+ fmt: fmt,
+ }
+ return d
+}
+
+type percentageDecorator struct {
+ WC
+ fmt string
+}
+
+func (d *percentageDecorator) Decor(st *Statistics) string {
+ p := internal.Percentage(st.Total, st.Current, 100)
+ return d.FormatMsg(fmt.Sprintf(d.fmt, percentageType(p)))
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/size_type.go b/vendor/github.com/vbauerster/mpb/v4/decor/size_type.go
new file mode 100644
index 000000000..e4b974058
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/size_type.go
@@ -0,0 +1,109 @@
+package decor
+
+import (
+ "fmt"
+ "io"
+ "math"
+ "strconv"
+)
+
+//go:generate stringer -type=SizeB1024 -trimprefix=_i
+//go:generate stringer -type=SizeB1000 -trimprefix=_
+
+const (
+ _ib SizeB1024 = iota + 1
+ _iKiB SizeB1024 = 1 << (iota * 10)
+ _iMiB
+ _iGiB
+ _iTiB
+)
+
+// SizeB1024 named type, which implements fmt.Formatter interface. It
+// adjusts its value according to byte size multiple by 1024 and appends
+// appropriate size marker (KiB, MiB, GiB, TiB).
+type SizeB1024 int64
+
+func (self SizeB1024) Format(st fmt.State, verb rune) {
+ var prec int
+ switch verb {
+ case 'd':
+ case 's':
+ prec = -1
+ default:
+ if p, ok := st.Precision(); ok {
+ prec = p
+ } else {
+ prec = 6
+ }
+ }
+
+ var unit SizeB1024
+ switch {
+ case self < _iKiB:
+ unit = _ib
+ case self < _iMiB:
+ unit = _iKiB
+ case self < _iGiB:
+ unit = _iMiB
+ case self < _iTiB:
+ unit = _iGiB
+ case self <= math.MaxInt64:
+ unit = _iTiB
+ }
+
+ io.WriteString(st, strconv.FormatFloat(float64(self)/float64(unit), 'f', prec, 64))
+
+ if st.Flag(' ') {
+ io.WriteString(st, " ")
+ }
+ io.WriteString(st, unit.String())
+}
+
+const (
+ _b SizeB1000 = 1
+ _KB SizeB1000 = _b * 1000
+ _MB SizeB1000 = _KB * 1000
+ _GB SizeB1000 = _MB * 1000
+ _TB SizeB1000 = _GB * 1000
+)
+
+// SizeB1000 named type, which implements fmt.Formatter interface. It
+// adjusts its value according to byte size multiple by 1000 and appends
+// appropriate size marker (KB, MB, GB, TB).
+type SizeB1000 int64
+
+func (self SizeB1000) Format(st fmt.State, verb rune) {
+ var prec int
+ switch verb {
+ case 'd':
+ case 's':
+ prec = -1
+ default:
+ if p, ok := st.Precision(); ok {
+ prec = p
+ } else {
+ prec = 6
+ }
+ }
+
+ var unit SizeB1000
+ switch {
+ case self < _KB:
+ unit = _b
+ case self < _MB:
+ unit = _KB
+ case self < _GB:
+ unit = _MB
+ case self < _TB:
+ unit = _GB
+ case self <= math.MaxInt64:
+ unit = _TB
+ }
+
+ io.WriteString(st, strconv.FormatFloat(float64(self)/float64(unit), 'f', prec, 64))
+
+ if st.Flag(' ') {
+ io.WriteString(st, " ")
+ }
+ io.WriteString(st, unit.String())
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1000_string.go b/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1000_string.go
new file mode 100644
index 000000000..3f32ef715
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1000_string.go
@@ -0,0 +1,41 @@
+// Code generated by "stringer -type=SizeB1000 -trimprefix=_"; DO NOT EDIT.
+
+package decor
+
+import "strconv"
+
+func _() {
+ // An "invalid array index" compiler error signifies that the constant values have changed.
+ // Re-run the stringer command to generate them again.
+ var x [1]struct{}
+ _ = x[_b-1]
+ _ = x[_KB-1000]
+ _ = x[_MB-1000000]
+ _ = x[_GB-1000000000]
+ _ = x[_TB-1000000000000]
+}
+
+const (
+ _SizeB1000_name_0 = "b"
+ _SizeB1000_name_1 = "KB"
+ _SizeB1000_name_2 = "MB"
+ _SizeB1000_name_3 = "GB"
+ _SizeB1000_name_4 = "TB"
+)
+
+func (i SizeB1000) String() string {
+ switch {
+ case i == 1:
+ return _SizeB1000_name_0
+ case i == 1000:
+ return _SizeB1000_name_1
+ case i == 1000000:
+ return _SizeB1000_name_2
+ case i == 1000000000:
+ return _SizeB1000_name_3
+ case i == 1000000000000:
+ return _SizeB1000_name_4
+ default:
+ return "SizeB1000(" + strconv.FormatInt(int64(i), 10) + ")"
+ }
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1024_string.go b/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1024_string.go
new file mode 100644
index 000000000..9fca66cc7
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/sizeb1024_string.go
@@ -0,0 +1,41 @@
+// Code generated by "stringer -type=SizeB1024 -trimprefix=_i"; DO NOT EDIT.
+
+package decor
+
+import "strconv"
+
+func _() {
+ // An "invalid array index" compiler error signifies that the constant values have changed.
+ // Re-run the stringer command to generate them again.
+ var x [1]struct{}
+ _ = x[_ib-1]
+ _ = x[_iKiB-1024]
+ _ = x[_iMiB-1048576]
+ _ = x[_iGiB-1073741824]
+ _ = x[_iTiB-1099511627776]
+}
+
+const (
+ _SizeB1024_name_0 = "b"
+ _SizeB1024_name_1 = "KiB"
+ _SizeB1024_name_2 = "MiB"
+ _SizeB1024_name_3 = "GiB"
+ _SizeB1024_name_4 = "TiB"
+)
+
+func (i SizeB1024) String() string {
+ switch {
+ case i == 1:
+ return _SizeB1024_name_0
+ case i == 1024:
+ return _SizeB1024_name_1
+ case i == 1048576:
+ return _SizeB1024_name_2
+ case i == 1073741824:
+ return _SizeB1024_name_3
+ case i == 1099511627776:
+ return _SizeB1024_name_4
+ default:
+ return "SizeB1024(" + strconv.FormatInt(int64(i), 10) + ")"
+ }
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/speed.go b/vendor/github.com/vbauerster/mpb/v4/decor/speed.go
new file mode 100644
index 000000000..795a5536f
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/speed.go
@@ -0,0 +1,175 @@
+package decor
+
+import (
+ "fmt"
+ "io"
+ "math"
+ "time"
+
+ "github.com/VividCortex/ewma"
+)
+
+// SpeedFormatter is wrapper for SizeB1024 and SizeB1000 to format value as speed/s.
+type SpeedFormatter struct {
+ fmt.Formatter
+}
+
+func (self *SpeedFormatter) Format(st fmt.State, verb rune) {
+ self.Formatter.Format(st, verb)
+ io.WriteString(st, "/s")
+}
+
+// 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.
+func EwmaSpeed(unit int, format string, age float64, wcc ...WC) Decorator {
+ var average MovingAverage
+ if age == 0 {
+ average = ewma.NewMovingAverage()
+ } else {
+ average = ewma.NewMovingAverage(age)
+ }
+ return MovingAverageSpeed(unit, format, average, wcc...)
+}
+
+// MovingAverageSpeed decorator relies on MovingAverage implementation
+// to calculate its average.
+//
+// `unit` one of [0|UnitKiB|UnitKB] zero for no unit
+//
+// `format` printf compatible verb for value, like "%f" or "%d"
+//
+// `average` MovingAverage implementation
+//
+// `wcc` optional WC config
+//
+// format examples:
+//
+// unit=UnitKiB, format="%.1f" output: "1.0MiB/s"
+// unit=UnitKiB, format="% .1f" output: "1.0 MiB/s"
+// 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 {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ if format == "" {
+ format = "%.0f"
+ }
+ d := &movingAverageSpeed{
+ WC: wc.Init(),
+ average: average,
+ producer: chooseSpeedProducer(unit, format),
+ }
+ return d
+}
+
+type movingAverageSpeed struct {
+ WC
+ producer func(float64) string
+ average ewma.MovingAverage
+ msg string
+}
+
+func (d *movingAverageSpeed) Decor(st *Statistics) string {
+ if !st.Completed {
+ var speed float64
+ if v := d.average.Value(); v > 0 {
+ speed = 1 / v
+ }
+ d.msg = d.producer(speed * 1e9)
+ }
+ 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)
+ if math.IsInf(durPerByte, 0) || math.IsNaN(durPerByte) {
+ return
+ }
+ d.average.Add(durPerByte)
+}
+
+// AverageSpeed decorator with dynamic unit measure adjustment. It's
+// a wrapper of NewAverageSpeed.
+func AverageSpeed(unit int, format string, wcc ...WC) Decorator {
+ return NewAverageSpeed(unit, format, time.Now(), wcc...)
+}
+
+// NewAverageSpeed decorator with dynamic unit measure adjustment and
+// user provided start time.
+//
+// `unit` one of [0|UnitKiB|UnitKB] zero for no unit
+//
+// `format` printf compatible verb for value, like "%f" or "%d"
+//
+// `startTime` start time
+//
+// `wcc` optional WC config
+//
+// format examples:
+//
+// unit=UnitKiB, format="%.1f" output: "1.0MiB/s"
+// unit=UnitKiB, format="% .1f" output: "1.0 MiB/s"
+// unit=UnitKB, format="%.1f" output: "1.0MB/s"
+// unit=UnitKB, format="% .1f" output: "1.0 MB/s"
+//
+func NewAverageSpeed(unit int, format string, startTime time.Time, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ if format == "" {
+ format = "%.0f"
+ }
+ d := &averageSpeed{
+ WC: wc.Init(),
+ startTime: startTime,
+ producer: chooseSpeedProducer(unit, format),
+ }
+ return d
+}
+
+type averageSpeed struct {
+ WC
+ startTime time.Time
+ producer func(float64) string
+ msg string
+}
+
+func (d *averageSpeed) Decor(st *Statistics) string {
+ if !st.Completed {
+ speed := float64(st.Current) / float64(time.Since(d.startTime))
+ d.msg = d.producer(speed * 1e9)
+ }
+
+ return d.FormatMsg(d.msg)
+}
+
+func (d *averageSpeed) AverageAdjust(startTime time.Time) {
+ d.startTime = startTime
+}
+
+func chooseSpeedProducer(unit int, format string) func(float64) string {
+ switch unit {
+ case UnitKiB:
+ return func(speed float64) string {
+ return fmt.Sprintf(format, &SpeedFormatter{SizeB1024(math.Round(speed))})
+ }
+ case UnitKB:
+ return func(speed float64) string {
+ return fmt.Sprintf(format, &SpeedFormatter{SizeB1000(math.Round(speed))})
+ }
+ default:
+ return func(speed float64) string {
+ return fmt.Sprintf(format, speed)
+ }
+ }
+}
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/spinner.go b/vendor/github.com/vbauerster/mpb/v4/decor/spinner.go
new file mode 100644
index 000000000..24f553142
--- /dev/null
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/spinner.go
@@ -0,0 +1,35 @@
+package decor
+
+var defaultSpinnerStyle = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
+
+// Spinner returns spinner decorator.
+//
+// `frames` spinner frames, if nil or len==0, default is used
+//
+// `wcc` optional WC config
+func Spinner(frames []string, wcc ...WC) Decorator {
+ var wc WC
+ for _, widthConf := range wcc {
+ wc = widthConf
+ }
+ if len(frames) == 0 {
+ frames = defaultSpinnerStyle
+ }
+ d := &spinnerDecorator{
+ WC: wc.Init(),
+ frames: frames,
+ }
+ return d
+}
+
+type spinnerDecorator struct {
+ WC
+ frames []string
+ count uint
+}
+
+func (d *spinnerDecorator) Decor(st *Statistics) string {
+ frame := d.frames[d.count%uint(len(d.frames))]
+ d.count++
+ return d.FormatMsg(frame)
+}