summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v5/decor
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v5/decor')
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/any.go14
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/counters.go8
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/decorator.go59
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/elapsed.go4
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/eta.go4
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/merge.go29
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/name.go2
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/on_complete.go2
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/percentage.go2
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/speed.go4
-rw-r--r--vendor/github.com/vbauerster/mpb/v5/decor/spinner.go2
11 files changed, 69 insertions, 61 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/any.go b/vendor/github.com/vbauerster/mpb/v5/decor/any.go
index bf9cf51a5..39518f594 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/any.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/any.go
@@ -1,21 +1,21 @@
package decor
// Any decorator displays text, that can be changed during decorator's
-// lifetime via provided func call back.
+// lifetime via provided DecorFunc.
//
-// `f` call back which provides string to display
+// `fn` DecorFunc callback
//
// `wcc` optional WC config
//
-func Any(f func(*Statistics) string, wcc ...WC) Decorator {
- return &any{initWC(wcc...), f}
+func Any(fn DecorFunc, wcc ...WC) Decorator {
+ return &any{initWC(wcc...), fn}
}
type any struct {
WC
- f func(*Statistics) string
+ fn DecorFunc
}
-func (d *any) Decor(s *Statistics) string {
- return d.FormatMsg(d.f(s))
+func (d *any) Decor(s Statistics) string {
+ return d.FormatMsg(d.fn(s))
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/counters.go b/vendor/github.com/vbauerster/mpb/v5/decor/counters.go
index 297bf937b..010ec371a 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/counters.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/counters.go
@@ -46,21 +46,21 @@ func Counters(unit int, pairFmt string, wcc ...WC) Decorator {
return Any(chooseSizeProducer(unit, pairFmt), wcc...)
}
-func chooseSizeProducer(unit int, format string) func(*Statistics) string {
+func chooseSizeProducer(unit int, format string) DecorFunc {
if format == "" {
format = "%d / %d"
}
switch unit {
case UnitKiB:
- return func(s *Statistics) string {
+ return func(s Statistics) string {
return fmt.Sprintf(format, SizeB1024(s.Current), SizeB1024(s.Total))
}
case UnitKB:
- return func(s *Statistics) string {
+ return func(s Statistics) string {
return fmt.Sprintf(format, SizeB1000(s.Current), SizeB1000(s.Total))
}
default:
- return func(s *Statistics) string {
+ return func(s Statistics) string {
return fmt.Sprintf(format, s.Current, s.Total)
}
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/decorator.go b/vendor/github.com/vbauerster/mpb/v5/decor/decorator.go
index 5bca63d52..e81fae367 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/decorator.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/decorator.go
@@ -3,9 +3,9 @@ package decor
import (
"fmt"
"time"
- "unicode/utf8"
"github.com/acarl005/stripansi"
+ "github.com/mattn/go-runewidth"
)
const (
@@ -47,22 +47,32 @@ const (
// Statistics consists of progress related statistics, that Decorator
// may need.
type Statistics struct {
- ID int
- Completed bool
- Total int64
- Current int64
+ ID int
+ AvailableWidth int
+ Total int64
+ Current int64
+ Refill int64
+ Completed bool
}
// 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.
+// Most of the time there is no need to implement this interface
+// manually, as decor package already provides a wide range of decorators
+// which implement this interface. If however built-in decorators don't
+// meet your needs, you're free to implement your own one by implementing
+// this particular interface. The easy way to go is to convert a
+// `DecorFunc` into a `Decorator` interface by using provided
+// `func Any(DecorFunc, ...WC) Decorator`.
type Decorator interface {
Configurator
Synchronizer
- Decor(*Statistics) string
+ Decor(Statistics) string
}
+// DecorFunc func type.
+// To be used with `func Any`(DecorFunc, ...WC) Decorator`.
+type DecorFunc func(Statistics) string
+
// Synchronizer interface.
// All decorators implement this interface implicitly. Its Sync
// method exposes width sync channel, if DSyncWidth bit is set.
@@ -117,38 +127,35 @@ var (
// 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
- wsync chan int
+ W int
+ C int
+ fill func(s string, w int) 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 {
- var format string
- runeCount := utf8.RuneCountInString(stripansi.Strip(msg))
- ansiCount := utf8.RuneCountInString(msg) - runeCount
+ pureWidth := runewidth.StringWidth(msg)
+ stripWidth := runewidth.StringWidth(stripansi.Strip(msg))
+ maxCell := wc.W
if (wc.C & DSyncWidth) != 0 {
+ cellCount := stripWidth
if (wc.C & DextraSpace) != 0 {
- runeCount++
+ cellCount++
}
- wc.wsync <- runeCount
- max := <-wc.wsync
- format = fmt.Sprintf(wc.dynFormat, ansiCount+max)
- } else {
- format = fmt.Sprintf(wc.dynFormat, ansiCount+wc.W)
+ wc.wsync <- cellCount
+ maxCell = <-wc.wsync
}
- return fmt.Sprintf(format, msg)
+ return wc.fill(msg, maxCell+(pureWidth-stripWidth))
}
// Init initializes width related config.
func (wc *WC) Init() WC {
- wc.dynFormat = "%%"
+ wc.fill = runewidth.FillLeft
if (wc.C & DidentRight) != 0 {
- wc.dynFormat += "-"
+ wc.fill = runewidth.FillRight
}
- wc.dynFormat += "%ds"
if (wc.C & DSyncWidth) != 0 {
// it's deliberate choice to override wsync on each Init() call,
// this way globals like WCSyncSpace can be reused
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/elapsed.go b/vendor/github.com/vbauerster/mpb/v5/decor/elapsed.go
index c9999a3b5..e389f1581 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/elapsed.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/elapsed.go
@@ -25,11 +25,11 @@ func Elapsed(style TimeStyle, wcc ...WC) Decorator {
func NewElapsed(style TimeStyle, startTime time.Time, wcc ...WC) Decorator {
var msg string
producer := chooseTimeProducer(style)
- f := func(s *Statistics) string {
+ fn := func(s Statistics) string {
if !s.Completed {
msg = producer(time.Since(startTime))
}
return msg
}
- return Any(f, wcc...)
+ return Any(fn, wcc...)
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/eta.go b/vendor/github.com/vbauerster/mpb/v5/decor/eta.go
index 6cb27a247..d03caa735 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/eta.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/eta.go
@@ -63,7 +63,7 @@ type movingAverageETA struct {
producer func(time.Duration) string
}
-func (d *movingAverageETA) Decor(s *Statistics) string {
+func (d *movingAverageETA) Decor(s Statistics) string {
v := math.Round(d.average.Value())
remaining := time.Duration((s.Total - s.Current) * int64(v))
if d.normalizer != nil {
@@ -117,7 +117,7 @@ type averageETA struct {
producer func(time.Duration) string
}
-func (d *averageETA) Decor(s *Statistics) string {
+func (d *averageETA) Decor(s Statistics) string {
var remaining time.Duration
if s.Current != 0 {
durPerItem := float64(time.Since(d.startTime)) / float64(s.Current)
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/merge.go b/vendor/github.com/vbauerster/mpb/v5/decor/merge.go
index 520f13a7f..e41406a64 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/merge.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/merge.go
@@ -1,9 +1,10 @@
package decor
import (
- "fmt"
"strings"
- "unicode/utf8"
+
+ "github.com/acarl005/stripansi"
+ "github.com/mattn/go-runewidth"
)
// Merge wraps its decorator argument with intention to sync width
@@ -64,18 +65,18 @@ func (d *mergeDecorator) Base() Decorator {
return d.Decorator
}
-func (d *mergeDecorator) Decor(s *Statistics) string {
+func (d *mergeDecorator) Decor(s Statistics) string {
msg := d.Decorator.Decor(s)
- msgLen := utf8.RuneCountInString(msg)
+ pureWidth := runewidth.StringWidth(msg)
+ stripWidth := runewidth.StringWidth(stripansi.Strip(msg))
+ cellCount := stripWidth
if (d.wc.C & DextraSpace) != 0 {
- msgLen++
+ cellCount++
}
- var total int
- max := utf8.RuneCountInString(d.placeHolders[0].FormatMsg(""))
- total += max
- pw := (msgLen - max) / len(d.placeHolders)
- rem := (msgLen - max) % len(d.placeHolders)
+ total := runewidth.StringWidth(d.placeHolders[0].FormatMsg(""))
+ pw := (cellCount - total) / len(d.placeHolders)
+ rem := (cellCount - total) % len(d.placeHolders)
var diff int
for i := 1; i < len(d.placeHolders); i++ {
@@ -87,20 +88,20 @@ func (d *mergeDecorator) Decor(s *Statistics) string {
width = 0
}
}
- max = utf8.RuneCountInString(ph.FormatMsg(strings.Repeat(" ", width)))
+ max := runewidth.StringWidth(ph.FormatMsg(strings.Repeat(" ", width)))
total += max
diff = max - pw
}
d.wc.wsync <- pw + rem
- max = <-d.wc.wsync
- return fmt.Sprintf(fmt.Sprintf(d.wc.dynFormat, max+total), msg)
+ max := <-d.wc.wsync
+ return d.wc.fill(msg, max+total+(pureWidth-stripWidth))
}
type placeHolderDecorator struct {
WC
}
-func (d *placeHolderDecorator) Decor(*Statistics) string {
+func (d *placeHolderDecorator) Decor(Statistics) string {
return ""
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/name.go b/vendor/github.com/vbauerster/mpb/v5/decor/name.go
index a7d477e07..3af311254 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/name.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/name.go
@@ -8,5 +8,5 @@ package decor
// `wcc` optional WC config
//
func Name(str string, wcc ...WC) Decorator {
- return Any(func(*Statistics) string { return str }, wcc...)
+ return Any(func(Statistics) string { return str }, wcc...)
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/on_complete.go b/vendor/github.com/vbauerster/mpb/v5/decor/on_complete.go
index 0a1526bf5..f46b19aba 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/on_complete.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/on_complete.go
@@ -24,7 +24,7 @@ type onCompleteWrapper struct {
msg string
}
-func (d *onCompleteWrapper) Decor(s *Statistics) string {
+func (d *onCompleteWrapper) Decor(s Statistics) string {
if s.Completed {
wc := d.GetConf()
return wc.FormatMsg(d.msg)
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/percentage.go b/vendor/github.com/vbauerster/mpb/v5/decor/percentage.go
index 65ca7d318..d6314a619 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/percentage.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/percentage.go
@@ -50,7 +50,7 @@ func NewPercentage(format string, wcc ...WC) Decorator {
if format == "" {
format = "% d"
}
- f := func(s *Statistics) string {
+ f := func(s Statistics) string {
p := internal.Percentage(s.Total, s.Current, 100)
return fmt.Sprintf(format, percentageType(p))
}
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/speed.go b/vendor/github.com/vbauerster/mpb/v5/decor/speed.go
index 8a48e3f52..634edabfd 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/speed.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/speed.go
@@ -78,7 +78,7 @@ type movingAverageSpeed struct {
msg string
}
-func (d *movingAverageSpeed) Decor(s *Statistics) string {
+func (d *movingAverageSpeed) Decor(s Statistics) string {
if !s.Completed {
var speed float64
if v := d.average.Value(); v > 0 {
@@ -140,7 +140,7 @@ type averageSpeed struct {
msg string
}
-func (d *averageSpeed) Decor(s *Statistics) string {
+func (d *averageSpeed) Decor(s Statistics) string {
if !s.Completed {
speed := float64(s.Current) / float64(time.Since(d.startTime))
d.msg = d.producer(speed * 1e9)
diff --git a/vendor/github.com/vbauerster/mpb/v5/decor/spinner.go b/vendor/github.com/vbauerster/mpb/v5/decor/spinner.go
index abfb2f76c..6871639db 100644
--- a/vendor/github.com/vbauerster/mpb/v5/decor/spinner.go
+++ b/vendor/github.com/vbauerster/mpb/v5/decor/spinner.go
@@ -12,7 +12,7 @@ func Spinner(frames []string, wcc ...WC) Decorator {
frames = defaultSpinnerStyle
}
var count uint
- f := func(s *Statistics) string {
+ f := func(s Statistics) string {
frame := frames[count%uint(len(frames))]
count++
return frame