1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-07 13:42:01 +02:00
lazygit/utils.go

43 lines
1022 B
Go
Raw Normal View History

package main
import (
2018-08-10 22:09:10 +10:00
"fmt"
"strings"
2018-08-10 22:09:10 +10:00
"github.com/fatih/color"
"github.com/jesseduffield/gocui"
)
func splitLines(multilineString string) []string {
multilineString = strings.Replace(multilineString, "\r", "", -1)
if multilineString == "" || multilineString == "\n" {
return make([]string, 0)
}
lines := strings.Split(multilineString, "\n")
if lines[len(lines)-1] == "" {
return lines[:len(lines)-1]
}
return lines
}
func trimmedContent(v *gocui.View) string {
return strings.TrimSpace(v.Buffer())
}
2018-08-10 21:51:21 +10:00
func withPadding(str string, padding int) string {
if padding-len(str) < 0 {
return str
}
return str + strings.Repeat(" ", padding-len(str))
}
2018-08-10 22:09:10 +10:00
func coloredString(str string, colorAttribute color.Attribute) string {
colour := color.New(colorAttribute)
return coloredStringDirect(str, colour)
}
// used for aggregating a few color attributes rather than just sending a single one
func coloredStringDirect(str string, colour *color.Color) string {
return colour.SprintFunc()(fmt.Sprint(str))
}