1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +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
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 {

View File

@ -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,13 +137,18 @@ func TestTruncateWithEllipsis(t *testing.T) {
{
"大大大大",
5,
"大...",
"大大…",
},
{
"大大大大",
2,
"..",
},
{
"大大大大",
1,
".",
},
{
"大大大大",
0,