Skip to content

Commit 93af001

Browse files
committed
Use actual ellipsis character instead of ... to truncate strings
Space is scarce in lazygit's UI, and using ... wastes a lot of it.
1 parent a171ec4 commit 93af001

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

pkg/utils/formatting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ func MaxFn[T any](items []T, fn func(T) int) int {
161161

162162
// TruncateWithEllipsis returns a string, truncated to a certain length, with an ellipsis
163163
func TruncateWithEllipsis(str string, limit int) string {
164-
if runewidth.StringWidth(str) > limit && limit <= 3 {
164+
if runewidth.StringWidth(str) > limit && limit <= 2 {
165165
return strings.Repeat(".", limit)
166166
}
167-
return runewidth.Truncate(str, limit, "...")
167+
return runewidth.Truncate(str, limit, "")
168168
}
169169

170170
func SafeTruncate(str string, limit int) string {

pkg/utils/formatting_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,22 +107,22 @@ func TestTruncateWithEllipsis(t *testing.T) {
107107
{
108108
"hello world !",
109109
3,
110-
"...",
110+
"he…",
111111
},
112112
{
113113
"hello world !",
114114
4,
115-
"h...",
115+
"hel…",
116116
},
117117
{
118118
"hello world !",
119119
5,
120-
"he...",
120+
"hell…",
121121
},
122122
{
123123
"hello world !",
124124
12,
125-
"hello wor...",
125+
"hello world…",
126126
},
127127
{
128128
"hello world !",
@@ -137,13 +137,18 @@ func TestTruncateWithEllipsis(t *testing.T) {
137137
{
138138
"大大大大",
139139
5,
140-
"大...",
140+
"大大…",
141141
},
142142
{
143143
"大大大大",
144144
2,
145145
"..",
146146
},
147+
{
148+
"大大大大",
149+
1,
150+
".",
151+
},
147152
{
148153
"大大大大",
149154
0,

0 commit comments

Comments
 (0)