diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-01-17 17:49:00 +0100 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-01-18 16:27:00 +0100 |
commit | 774271c38a8c3e96c7518b3c03de2f00e87138be (patch) | |
tree | 09532ca2680778112041ebac0576d483c2452c4f /vendor/github.com/buger/goterm/box.go | |
parent | 55ad6188b067ba6594819c318dd2ae92dea2f27e (diff) | |
download | podman-774271c38a8c3e96c7518b3c03de2f00e87138be.tar.gz podman-774271c38a8c3e96c7518b3c03de2f00e87138be.tar.bz2 podman-774271c38a8c3e96c7518b3c03de2f00e87138be.zip |
upgrade all dependencies
The dependabot does not update dependencies when they do not use a tag.
This patch upgrades all untagged depenencies if possible.
You can upgrade all dependencies with `go get -u ./... && make vendor`
in theory however this failed since the k8s changes do not compile on
go v1.16 so I only updated the other dependencies.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'vendor/github.com/buger/goterm/box.go')
-rw-r--r-- | vendor/github.com/buger/goterm/box.go | 66 |
1 files changed, 60 insertions, 6 deletions
diff --git a/vendor/github.com/buger/goterm/box.go b/vendor/github.com/buger/goterm/box.go index 7df929d7d..4a119c552 100644 --- a/vendor/github.com/buger/goterm/box.go +++ b/vendor/github.com/buger/goterm/box.go @@ -2,7 +2,9 @@ package goterm import ( "bytes" + "regexp" "strings" + _ "unicode/utf8" ) const DEFAULT_BORDER = "- │ ┌ ┐ └ ┘" @@ -61,7 +63,9 @@ func (b *Box) Write(p []byte) (int, error) { return b.Buf.Write(p) } -// Render Box +var ANSI_RE = regexp.MustCompile(`\\0\d+\[\d+(?:;\d+)?m`) + +// String renders Box func (b *Box) String() (out string) { borders := strings.Split(b.Border, " ") lines := strings.Split(b.Buf.String(), "\n") @@ -74,7 +78,6 @@ func (b *Box) String() (out string) { // Content width without borders and padding contentWidth := b.Width - (b.PaddingX+1)*2 - for y := 0; y < b.Height; y++ { var line string @@ -99,12 +102,63 @@ func (b *Box) String() (out string) { line = "" } - if len(line) > contentWidth-1 { + r := []rune(line) + + lastAnsii := "" + withoutAnsii := []rune{} + withOffset := []rune{} + i := 0 + + for { + if i >= len(r) { + break + } + + if r[i] == 27 { + lastAnsii = "" + withOffset = append(withOffset, r[i]) + lastAnsii += string(r[i]) + i++ + for { + + i++ + if i > len(r) { + break + } + + withOffset = append(withOffset, r[i]) + lastAnsii += string(r[i]) + + if r[i] == 'm' { + i++ + break + } + } + } + + if i >= len(r) { + break + } + + withoutAnsii = append(withoutAnsii, r[i]) + + if len(withoutAnsii) <= contentWidth { + withOffset = append(withOffset, r[i]) + } + + i++ + } + + if len(withoutAnsii) > contentWidth { // If line is too large limit it - line = line[0:contentWidth] + line = string(withOffset) } else { // If line is too small enlarge it by adding spaces - line = line + strings.Repeat(" ", contentWidth-len(line)) + line += strings.Repeat(" ", contentWidth-len(withoutAnsii)) + } + + if lastAnsii != "" { + line += RESET } line = prefix + line + suffix @@ -112,7 +166,7 @@ func (b *Box) String() (out string) { // Don't add newline for last element if y != b.Height-1 { - line = line + "\n" + line += "\n" } out += line |