summaryrefslogtreecommitdiff
path: root/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2020-02-03 16:09:04 +0100
committerValentin Rothberg <rothberg@redhat.com>2020-02-05 09:55:50 +0100
commit801977b40d8500ff68cf5a6facd82f035735076a (patch)
tree3e67e319511dce7b84a6ab16dfa8ecc3d8ec5e7a /vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
parent5092c078ec635c9f1598989b27ccf53369b3cf2b (diff)
downloadpodman-801977b40d8500ff68cf5a6facd82f035735076a.tar.gz
podman-801977b40d8500ff68cf5a6facd82f035735076a.tar.bz2
podman-801977b40d8500ff68cf5a6facd82f035735076a.zip
vendor github.com/containers/image/v5@v5.2.0
See release notes: https://github.com/containers/image/releases/tag/v5.2.0 Fixes: #4877 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/v4/decor/decorator.go')
-rw-r--r--vendor/github.com/vbauerster/mpb/v4/decor/decorator.go27
1 files changed, 16 insertions, 11 deletions
diff --git a/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go b/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
index 5c0d16880..2271cbbe1 100644
--- a/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
+++ b/vendor/github.com/vbauerster/mpb/v4/decor/decorator.go
@@ -4,6 +4,8 @@ import (
"fmt"
"time"
"unicode/utf8"
+
+ "github.com/acarl005/stripansi"
)
const (
@@ -117,25 +119,29 @@ 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
- staticFormat string
- wsync chan int
+ W int
+ C int
+ dynFormat 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
if (wc.C & DSyncWidth) != 0 {
- wc.wsync <- utf8.RuneCountInString(msg)
- max := <-wc.wsync
if (wc.C & DextraSpace) != 0 {
- max++
+ runeCount++
}
- return fmt.Sprintf(fmt.Sprintf(wc.dynFormat, max), msg)
+ wc.wsync <- runeCount
+ max := <-wc.wsync
+ format = fmt.Sprintf(wc.dynFormat, ansiCount+max)
+ } else {
+ format = fmt.Sprintf(wc.dynFormat, ansiCount+wc.W)
}
- return fmt.Sprintf(wc.staticFormat, msg)
+ return fmt.Sprintf(format, msg)
}
// Init initializes width related config.
@@ -145,7 +151,6 @@ func (wc *WC) Init() WC {
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