diff options
author | Michael Muré <batolettre@gmail.com> | 2020-02-05 22:03:19 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-05 22:33:03 +0100 |
commit | 1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6 (patch) | |
tree | e088b0fa43058afde1db71541d8fcb4b94905d6e /vendor/github.com/MichaelMure/go-term-text/left_pad.go | |
parent | f093be96e98284580d61664adecd0a2ff8b354e4 (diff) | |
download | git-bug-1d4bb7ceb0cef79d68df0bacc913b01e40e6ddd6.tar.gz |
migrate to go modules
Diffstat (limited to 'vendor/github.com/MichaelMure/go-term-text/left_pad.go')
-rw-r--r-- | vendor/github.com/MichaelMure/go-term-text/left_pad.go | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/vendor/github.com/MichaelMure/go-term-text/left_pad.go b/vendor/github.com/MichaelMure/go-term-text/left_pad.go deleted file mode 100644 index a63fedb9..00000000 --- a/vendor/github.com/MichaelMure/go-term-text/left_pad.go +++ /dev/null @@ -1,50 +0,0 @@ -package text - -import ( - "bytes" - "strings" - - "github.com/mattn/go-runewidth" -) - -// LeftPadMaxLine pads a line on the left by a specified amount and pads the -// string on the right to fill the maxLength. -// If the given string is too long, it is truncated with an ellipsis. -// Handle properly terminal color escape code -func LeftPadMaxLine(line string, length, leftPad int) string { - cleaned, escapes := ExtractTermEscapes(line) - - scrWidth := runewidth.StringWidth(cleaned) - // truncate and ellipse if needed - if scrWidth+leftPad > length { - cleaned = runewidth.Truncate(cleaned, length-leftPad, "…") - } else if scrWidth+leftPad < length { - cleaned = runewidth.FillRight(cleaned, length-leftPad) - } - - rightPart := ApplyTermEscapes(cleaned, escapes) - pad := strings.Repeat(" ", leftPad) - - return pad + rightPart -} - -// LeftPad left pad each line of the given text -func LeftPadLines(text string, leftPad int) string { - var result bytes.Buffer - - pad := strings.Repeat(" ", leftPad) - - lines := strings.Split(text, "\n") - - for i, line := range lines { - result.WriteString(pad) - result.WriteString(line) - - // no additional line break at the end - if i < len(lines)-1 { - result.WriteString("\n") - } - } - - return result.String() -} |