1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00

Use actual ellipsis character instead of ... to truncate strings

Space is scarce in lazygit's UI, and using ... wastes a lot of it.
This commit is contained in:
Stefan Haller 2024-06-15 14:30:27 +02:00
parent a171ec4294
commit 93af0016f7
2 changed files with 12 additions and 7 deletions

View File

@ -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 // TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
func TruncateWithEllipsis(str string, limit int) string { 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 strings.Repeat(".", limit)
} }
return runewidth.Truncate(str, limit, "...") return runewidth.Truncate(str, limit, "")
} }
func SafeTruncate(str string, limit int) string { func SafeTruncate(str string, limit int) string {

View File

@ -107,22 +107,22 @@ func TestTruncateWithEllipsis(t *testing.T) {
{ {
"hello world !", "hello world !",
3, 3,
"...", "he…",
}, },
{ {
"hello world !", "hello world !",
4, 4,
"h...", "hel…",
}, },
{ {
"hello world !", "hello world !",
5, 5,
"he...", "hell…",
}, },
{ {
"hello world !", "hello world !",
12, 12,
"hello wor...", "hello world…",
}, },
{ {
"hello world !", "hello world !",
@ -137,13 +137,18 @@ func TestTruncateWithEllipsis(t *testing.T) {
{ {
"大大大大", "大大大大",
5, 5,
"大...", "大大…",
}, },
{ {
"大大大大", "大大大大",
2, 2,
"..", "..",
}, },
{
"大大大大",
1,
".",
},
{ {
"大大大大", "大大大大",
0, 0,