diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-24 16:26:03 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-10-30 18:26:06 +1100 |
commit | 6457800748f4769b96508da5054208b28a0dee6e (patch) | |
tree | 34bc13ed2eb5adfa7043ba7cc7d91213e109beea /pkg/utils/formatting.go | |
parent | 7d9461877aefd417b126e6c56ebfb7745fecef62 (diff) |
fix another issue with indentation
Diffstat (limited to 'pkg/utils/formatting.go')
-rw-r--r-- | pkg/utils/formatting.go | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index 3b4b35bb8..8a439bc32 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -1,6 +1,10 @@ package utils -import "strings" +import ( + "strings" + + "github.com/mattn/go-runewidth" +) // WithPadding pads a string as much as you want func WithPadding(str string, padding int) string { @@ -37,3 +41,27 @@ func getPaddedDisplayStrings(stringArrays [][]string, padWidths []int) []string } return paddedDisplayStrings } + +func getPadWidths(stringArrays [][]string) []int { + maxWidth := 0 + for _, stringArray := range stringArrays { + if len(stringArray) > maxWidth { + maxWidth = len(stringArray) + } + } + if maxWidth-1 < 0 { + return []int{} + } + padWidths := make([]int, maxWidth-1) + for i := range padWidths { + for _, strings := range stringArrays { + uncoloredString := Decolorise(strings[i]) + + width := runewidth.StringWidth(uncoloredString) + if width > padWidths[i] { + padWidths[i] = width + } + } + } + return padWidths +} |