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:
parent
6171690b00
commit
e122f421e6
@ -11,6 +11,7 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/kyokomi/emoji/v2"
|
||||
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 {
|
||||
@ -166,19 +167,16 @@ func randFloat(hash []byte) float64 {
|
||||
return float64(sum) / 100
|
||||
}
|
||||
|
||||
var authorStyles = []style.TextStyle{
|
||||
style.FgGreen,
|
||||
style.FgYellow,
|
||||
style.FgMagenta,
|
||||
style.FgCyan,
|
||||
style.FgRed,
|
||||
}
|
||||
|
||||
func getInitials(authorName string) string {
|
||||
if authorName == "" {
|
||||
return authorName
|
||||
}
|
||||
|
||||
firstRune := getFirstRune(authorName)
|
||||
if runewidth.RuneWidth(firstRune) > 1 {
|
||||
return string(firstRune)
|
||||
}
|
||||
|
||||
split := strings.Split(authorName, " ")
|
||||
if len(split) == 1 {
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
switch str {
|
||||
case "pick":
|
||||
|
@ -3,15 +3,18 @@ package presentation
|
||||
import "testing"
|
||||
|
||||
func TestGetInitials(t *testing.T) {
|
||||
for input, output := range map[string]string{
|
||||
for input, expectedOutput := range map[string]string{
|
||||
"Jesse Duffield": "JD",
|
||||
"Jesse Duffield Man": "JD",
|
||||
"JesseDuffield": "Je",
|
||||
"J": "J",
|
||||
"六书六書": "六",
|
||||
"書": "書",
|
||||
"": "",
|
||||
} {
|
||||
if output != getInitials(input) {
|
||||
t.Errorf("Expected %s to be %s", input, output)
|
||||
output := getInitials(input)
|
||||
if output != expectedOutput {
|
||||
t.Errorf("Expected %s to be %s", output, expectedOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user