From bfb5e96aab9e78f05942151060cc92fdaa32bedd Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 15 Sep 2018 20:30:31 +0200 Subject: commands: git bug comment now show the comments of a bug --- util/text/left_padded.go | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'util/text/left_padded.go') diff --git a/util/text/left_padded.go b/util/text/left_padded.go index a38dfba5..78d772d5 100644 --- a/util/text/left_padded.go +++ b/util/text/left_padded.go @@ -1,20 +1,36 @@ package text import ( + "bytes" "strings" "unicode/utf8" ) -// LeftPaddedString pads a string on the left by a specified amount and pads the string on the right to fill the maxLength -func LeftPaddedString(value string, maxValueLength, padAmount int) string { +// LeftPadMaxLine pads a string on the left by a specified amount and pads the string on the right to fill the maxLength +func LeftPadMaxLine(value string, maxValueLength, leftPad int) string { valueLength := utf8.RuneCountInString(value) - if maxValueLength-padAmount >= valueLength { - return strings.Repeat(" ", padAmount) + value + strings.Repeat(" ", maxValueLength-valueLength-padAmount) - } else if maxValueLength-padAmount < valueLength { - tmp := strings.Trim(value[0:maxValueLength-padAmount-3], " ") + "..." + if maxValueLength-leftPad >= valueLength { + return strings.Repeat(" ", leftPad) + value + strings.Repeat(" ", maxValueLength-valueLength-leftPad) + } else if maxValueLength-leftPad < valueLength { + tmp := strings.Trim(value[0:maxValueLength-leftPad-3], " ") + "..." tmpLength := utf8.RuneCountInString(tmp) - return strings.Repeat(" ", padAmount) + tmp + strings.Repeat(" ", maxValueLength-tmpLength-padAmount) + return strings.Repeat(" ", leftPad) + tmp + strings.Repeat(" ", maxValueLength-tmpLength-leftPad) } return value } + +// LeftPad left pad each line of the given text +func LeftPad(text string, leftPad int) string { + var result bytes.Buffer + + pad := strings.Repeat(" ", leftPad) + + for _, line := range strings.Split(text, "\n") { + result.WriteString(pad) + result.WriteString(line) + result.WriteString("\n") + } + + return result.String() +} -- cgit