diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 20:11:07 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-25 21:21:07 +1100 |
commit | 9fd9fd6816925debe64aa21269cdba5ec74ed5e9 (patch) | |
tree | a9e9cdf7285f246d9eaf59b42309a70c5ba9a029 /pkg/utils | |
parent | b8717d750a6d60b8f76698756e4d9ca9977ae14d (diff) |
better commit lines in fullscreen mode
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/utils.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 42529776f..7fa33e769 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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] + "..." +} |