mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package utils
|
|
|
|
import "strings"
|
|
|
|
// WithPadding pads a string as much as you want
|
|
func WithPadding(str string, padding int) string {
|
|
uncoloredStr := Decolorise(str)
|
|
if padding < len(uncoloredStr) {
|
|
return str
|
|
}
|
|
return str + strings.Repeat(" ", padding-len(uncoloredStr))
|
|
}
|
|
|
|
func RenderDisplayStrings(displayStringsArr [][]string) string {
|
|
padWidths := getPadWidths(displayStringsArr)
|
|
paddedDisplayStrings := getPaddedDisplayStrings(displayStringsArr, padWidths)
|
|
|
|
return strings.Join(paddedDisplayStrings, "\n")
|
|
}
|
|
|
|
func getPaddedDisplayStrings(stringArrays [][]string, padWidths []int) []string {
|
|
paddedDisplayStrings := make([]string, len(stringArrays))
|
|
for i, stringArray := range stringArrays {
|
|
if len(stringArray) == 0 {
|
|
continue
|
|
}
|
|
for j, padWidth := range padWidths {
|
|
if len(stringArray)-1 < j {
|
|
continue
|
|
}
|
|
paddedDisplayStrings[i] += WithPadding(stringArray[j], padWidth) + " "
|
|
}
|
|
if len(stringArray)-1 < len(padWidths) {
|
|
continue
|
|
}
|
|
paddedDisplayStrings[i] += stringArray[len(padWidths)]
|
|
}
|
|
return paddedDisplayStrings
|
|
}
|