From 75b4760f34f9f15659a59af81b9aada744494316 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:24:52 +0300 Subject: [PATCH] chore(deps): bump github.com/briandowns/spinner from 1.20.0 to 1.21.0 (#239) --- go.mod | 2 +- go.sum | 4 +- .../github.com/briandowns/spinner/spinner.go | 49 ++++++++++++++----- vendor/modules.txt | 2 +- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 8a7609b6..53d1096c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/Davincible/goinsta/v3 v3.2.6 - github.com/briandowns/spinner v1.20.0 + github.com/briandowns/spinner v1.21.0 github.com/disintegration/imaging v1.6.2 github.com/hashicorp/go-multierror v1.1.1 github.com/obalunenko/getenv v1.2.1 diff --git a/go.sum b/go.sum index 7a353a63..5314fdf0 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VM github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk= -github.com/briandowns/spinner v1.20.0 h1:GQq1Yf1KyzYT8CY19GzWrDKP6hYOFB6J72Ks7d8aO1U= -github.com/briandowns/spinner v1.20.0/go.mod h1:TcwZHb7Wb6vn/+bcVv1UXEzaA4pLS7yznHlkY/HzH44= +github.com/briandowns/spinner v1.21.0 h1:2lVBzf3iZ3cT/ulVXljc4BzlL3yTWZDzsGsamI7si+A= +github.com/briandowns/spinner v1.21.0/go.mod h1:TcwZHb7Wb6vn/+bcVv1UXEzaA4pLS7yznHlkY/HzH44= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= diff --git a/vendor/github.com/briandowns/spinner/spinner.go b/vendor/github.com/briandowns/spinner/spinner.go index ae5f238f..7b7b081d 100644 --- a/vendor/github.com/briandowns/spinner/spinner.go +++ b/vendor/github.com/briandowns/spinner/spinner.go @@ -496,18 +496,43 @@ func computeNumberOfLinesNeededToPrintString(linePrinted string) int { return computeNumberOfLinesNeededToPrintStringInternal(linePrinted, terminalWidth) } -func computeNumberOfLinesNeededToPrintStringInternal(linePrinted string, maxLineWidth int) int { - if linePrinted == "" { - // empty string will necessarily take one line - return 1 +// isAnsiMarker returns if a rune denotes the start of an ANSI sequence +func isAnsiMarker(r rune) bool { + return r == '\x1b' +} + +// isAnsiTerminator returns if a rune denotes the end of an ANSI sequence +func isAnsiTerminator(r rune) bool { + return (r >= 0x40 && r <= 0x5a) || (r == 0x5e) || (r >= 0x60 && r <= 0x7e) +} + +// computeLineWidth returns the displayed width of a line +func computeLineWidth(line string) int { + width := 0 + ansi := false + + for _, r := range []rune(line) { + // increase width only when outside of ANSI escape sequences + if ansi || isAnsiMarker(r) { + ansi = !isAnsiTerminator(r) + } else { + width += utf8.RuneLen(r) + } } - idxOfNewline := strings.Index(linePrinted, "\n") - if idxOfNewline < 0 { - // we use utf8.RunCountInString() in place of len() because the string contains "complex" unicode chars that - // might be represented by multiple individual bytes (typically spinner char) - return int(math.Ceil(float64(utf8.RuneCountInString(linePrinted)) / float64(maxLineWidth))) - } else { - return computeNumberOfLinesNeededToPrintStringInternal(linePrinted[:idxOfNewline], maxLineWidth) + - computeNumberOfLinesNeededToPrintStringInternal(linePrinted[idxOfNewline+1:], maxLineWidth) + + return width +} + +func computeNumberOfLinesNeededToPrintStringInternal(linePrinted string, maxLineWidth int) int { + lineCount := 0 + for _, line := range strings.Split(linePrinted, "\n") { + lineCount += 1 + + lineWidth := computeLineWidth(line) + if lineWidth > maxLineWidth { + lineCount += int(float64(lineWidth) / float64(maxLineWidth)) + } } + + return lineCount } diff --git a/vendor/modules.txt b/vendor/modules.txt index d8f5eb47..ab903011 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -13,7 +13,7 @@ github.com/Microsoft/go-winio/pkg/guid # github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 ## explicit github.com/Nvveen/Gotty -# github.com/briandowns/spinner v1.20.0 +# github.com/briandowns/spinner v1.21.0 ## explicit; go 1.14 github.com/briandowns/spinner # github.com/cenkalti/backoff/v4 v4.1.3