aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-07-30 18:09:44 +0200
committerMichael Muré <batolettre@gmail.com>2018-07-30 18:09:44 +0200
commit29bb7364c8e873c72a386f4f6fa26248e5355cb2 (patch)
tree754077feaa733c87ca5b8d17af28644be373beae /util
parentc0dbe70ee08db699a35d573ba09f7900fb959f92 (diff)
downloadgit-bug-29bb7364c8e873c72a386f4f6fa26248e5355cb2.tar.gz
termui: interactive and responsible list of bugs
Diffstat (limited to 'util')
-rw-r--r--util/left_padded.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/util/left_padded.go b/util/left_padded.go
new file mode 100644
index 00000000..69c88074
--- /dev/null
+++ b/util/left_padded.go
@@ -0,0 +1,20 @@
+package util
+
+import (
+ "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 {
+ 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], " ") + "..."
+ tmpLength := utf8.RuneCountInString(tmp)
+ return strings.Repeat(" ", padAmount) + tmp + strings.Repeat(" ", maxValueLength-tmpLength-padAmount)
+ }
+
+ return value
+}