From f72a9dc62ba20546b2cdeb466434fc1900741a4f Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 3 Nov 2019 14:00:35 +0100 Subject: switch to go-term-text to fix bad underflow for label rendering --- vendor/github.com/MichaelMure/go-term-text/trim.go | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 vendor/github.com/MichaelMure/go-term-text/trim.go (limited to 'vendor/github.com/MichaelMure/go-term-text/trim.go') diff --git a/vendor/github.com/MichaelMure/go-term-text/trim.go b/vendor/github.com/MichaelMure/go-term-text/trim.go new file mode 100644 index 00000000..eaf2ca0c --- /dev/null +++ b/vendor/github.com/MichaelMure/go-term-text/trim.go @@ -0,0 +1,28 @@ +package text + +import ( + "strings" + "unicode" +) + +// TrimSpace remove the leading and trailing whitespace while ignoring the +// terminal escape sequences. +// Returns the number of trimmed space on both side. +func TrimSpace(line string) string { + cleaned, escapes := ExtractTermEscapes(line) + + // trim left while counting + left := 0 + trimmed := strings.TrimLeftFunc(cleaned, func(r rune) bool { + if unicode.IsSpace(r) { + left++ + return true + } + return false + }) + + trimmed = strings.TrimRightFunc(trimmed, unicode.IsSpace) + + escapes = OffsetEscapes(escapes, -left) + return ApplyTermEscapes(trimmed, escapes) +} -- cgit