better commit lines in fullscreen mode

This commit is contained in:
Jesse Duffield 2020-02-25 20:11:07 +11:00
parent b8717d750a
commit 9fd9fd6816
7 changed files with 202 additions and 102 deletions

View file

@ -348,3 +348,22 @@ func PrevIntInCycle(sl []int, current int) int {
}
return sl[len(sl)-1]
}
// TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
func TruncateWithEllipsis(str string, limit int) string {
if limit == 1 && len(str) > 1 {
return "."
}
if limit == 2 && len(str) > 2 {
return ".."
}
ellipsis := "..."
if len(str) <= limit {
return str
}
remainingLength := limit - len(ellipsis)
return str[0:remainingLength] + "..."
}