1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-15 00:15:32 +02:00

fix truncation

This commit is contained in:
Jesse Duffield
2021-10-30 20:15:50 +11:00
parent 72bce201df
commit f91892b8f1
3 changed files with 88 additions and 28 deletions

View File

@ -66,3 +66,19 @@ func getPadWidths(stringArrays [][]string) []int {
}
return padWidths
}
// TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
func TruncateWithEllipsis(str string, limit int) string {
if runewidth.StringWidth(str) > limit && limit <= 3 {
return strings.Repeat(".", limit)
}
return runewidth.Truncate(str, limit, "...")
}
func SafeTruncate(str string, limit int) string {
if len(str) > limit {
return str[0:limit]
} else {
return str
}
}