diff options
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, "", }, |