1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-10 04:07:18 +02:00

only use a single initial for double sized runes

This commit is contained in:
Jesse Duffield 2021-10-24 15:54:20 +11:00
parent 6171690b00
commit e122f421e6
2 changed files with 21 additions and 11 deletions

View File

@ -11,6 +11,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/kyokomi/emoji/v2" "github.com/kyokomi/emoji/v2"
colorful "github.com/lucasb-eyer/go-colorful" colorful "github.com/lucasb-eyer/go-colorful"
"github.com/mattn/go-runewidth"
) )
func GetCommitListDisplayStrings(commits []*models.Commit, fullDescription bool, cherryPickedCommitShaMap map[string]bool, diffName string, parseEmoji bool) [][]string { 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 {
return float64(sum) / 100 return float64(sum) / 100
} }
var authorStyles = []style.TextStyle{
style.FgGreen,
style.FgYellow,
style.FgMagenta,
style.FgCyan,
style.FgRed,
}
func getInitials(authorName string) string { func getInitials(authorName string) string {
if authorName == "" { if authorName == "" {
return authorName return authorName
} }
firstRune := getFirstRune(authorName)
if runewidth.RuneWidth(firstRune) > 1 {
return string(firstRune)
}
split := strings.Split(authorName, " ") split := strings.Split(authorName, " ")
if len(split) == 1 { if len(split) == 1 {
return utils.LimitStr(authorName, 2) return utils.LimitStr(authorName, 2)
@ -187,6 +185,15 @@ func getInitials(authorName string) string {
return utils.LimitStr(split[0], 1) + utils.LimitStr(split[1], 1) return utils.LimitStr(split[0], 1) + utils.LimitStr(split[1], 1)
} }
func getFirstRune(str string) rune {
// just using the loop for the sake of getting the first rune
for _, r := range str {
return r
}
// should never land here
return 0
}
func actionColorMap(str string) style.TextStyle { func actionColorMap(str string) style.TextStyle {
switch str { switch str {
case "pick": case "pick":

View File

@ -3,15 +3,18 @@ package presentation
import "testing" import "testing"
func TestGetInitials(t *testing.T) { func TestGetInitials(t *testing.T) {
for input, output := range map[string]string{ for input, expectedOutput := range map[string]string{
"Jesse Duffield": "JD", "Jesse Duffield": "JD",
"Jesse Duffield Man": "JD", "Jesse Duffield Man": "JD",
"JesseDuffield": "Je", "JesseDuffield": "Je",
"J": "J", "J": "J",
"六书六書": "六",
"書": "書",
"": "", "": "",
} { } {
if output != getInitials(input) { output := getInitials(input)
t.Errorf("Expected %s to be %s", input, output) if output != expectedOutput {
t.Errorf("Expected %s to be %s", output, expectedOutput)
} }
} }
} }