Skip to content

Commit e122f42

Browse files
committed
only use a single initial for double sized runes
1 parent 6171690 commit e122f42

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pkg/gui/presentation/commits.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/jesseduffield/lazygit/pkg/utils"
1212
"github.com/kyokomi/emoji/v2"
1313
colorful "github.com/lucasb-eyer/go-colorful"
14+
"github.com/mattn/go-runewidth"
1415
)
1516

1617
func GetCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string, parseEmoji bool) [][]string {
@@ -166,19 +167,16 @@ func randFloat(hash []byte) float64 {
166167
return float64(sum) / 100
167168
}
168169

169-
var authorStyles = []style.TextStyle{
170-
style.FgGreen,
171-
style.FgYellow,
172-
style.FgMagenta,
173-
style.FgCyan,
174-
style.FgRed,
175-
}
176-
177170
func getInitials(authorName string) string {
178171
if authorName == "" {
179172
return authorName
180173
}
181174

175+
firstRune := getFirstRune(authorName)
176+
if runewidth.RuneWidth(firstRune) > 1 {
177+
return string(firstRune)
178+
}
179+
182180
split := strings.Split(authorName, " ")
183181
if len(split) == 1 {
184182
return utils.LimitStr(authorName, 2)
@@ -187,6 +185,15 @@ func getInitials(authorName string) string {
187185
return utils.LimitStr(split[0], 1) + utils.LimitStr(split[1], 1)
188186
}
189187

188+
func getFirstRune(str string) rune {
189+
// just using the loop for the sake of getting the first rune
190+
for _, r := range str {
191+
return r
192+
}
193+
// should never land here
194+
return 0
195+
}
196+
190197
func actionColorMap(str string) style.TextStyle {
191198
switch str {
192199
case "pick":

pkg/gui/presentation/commits_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@ package presentation
33
import "testing"
44

55
func TestGetInitials(t *testing.T) {
6-
for input, output := range map[string]string{
6+
for input, expectedOutput := range map[string]string{
77
"Jesse Duffield": "JD",
88
"Jesse Duffield Man": "JD",
99
"JesseDuffield": "Je",
1010
"J": "J",
11+
"六书六書": "六",
12+
"書": "書",
1113
"": "",
1214
} {
13-
if output != getInitials(input) {
14-
t.Errorf("Expected %s to be %s", input, output)
15+
output := getInitials(input)
16+
if output != expectedOutput {
17+
t.Errorf("Expected %s to be %s", output, expectedOutput)
1518
}
1619
}
1720
}

0 commit comments

Comments
 (0)