From 774271c38a8c3e96c7518b3c03de2f00e87138be Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Mon, 17 Jan 2022 17:49:00 +0100 Subject: 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 --- vendor/github.com/buger/goterm/box.go | 66 +++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 6 deletions(-) (limited to 'vendor/github.com/buger/goterm/box.go') 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 -- cgit v1.2.3-54-g00ecf