diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-15 14:30:27 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:25:28 +0200 |
commit | 93af0016f777fb477263d44e4f7530a7b59bc53b (patch) | |
tree | 0af899cfb7a9f0fcf871da5b7eb547926455a5cf /pkg | |
parent | a171ec42943c048e4210bd6beac64aa138ea7c56 (diff) |
Use actual ellipsis character instead of ... to truncate strings
Space is scarce in lazygit's UI, and using ... wastes a lot of it.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/utils/formatting.go | 4 | ||||
-rw-r--r-- | pkg/utils/formatting_test.go | 15 |
2 files changed, 12 insertions, 7 deletions
diff --git a/pkg/utils/formatting.go b/pkg/utils/formatting.go index 139946ddb..a6bbc5670 100644 --- a/pkg/utils/formatting.go +++ b/pkg/utils/formatting.go @@ -161,10 +161,10 @@ func MaxFn[T any](items []T, fn func(T) int) int { // 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 { + if runewidth.StringWidth(str) > limit && limit <= 2 { return strings.Repeat(".", limit) } - return runewidth.Truncate(str, limit, "...") + return runewidth.Truncate(str, limit, "…") } func SafeTruncate(str string, limit int) string { diff --git a/pkg/utils/formatting_test.go b/pkg/utils/formatting_test.go index 3858fd2ec..5b56a9b33 100644 --- a/pkg/utils/formatting_test.go +++ b/pkg/utils/formatting_test.go @@ -107,22 +107,22 @@ func TestTruncateWithEllipsis(t *testing.T) { { "hello world !", 3, - "...", + "he…", }, { "hello world !", 4, - "h...", + "hel…", }, { "hello world !", 5, - "he...", + "hell…", }, { "hello world !", 12, - "hello wor...", + "hello world…", }, { "hello world !", @@ -137,7 +137,7 @@ func TestTruncateWithEllipsis(t *testing.T) { { "大大大大", 5, - "大...", + "大大…", }, { "大大大大", @@ -146,6 +146,11 @@ func TestTruncateWithEllipsis(t *testing.T) { }, { "大大大大", + 1, + ".", + }, + { + "大大大大", 0, "", }, |