mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
Fix multibyte initial characters
This commit is contained in:
committed by
Jesse Duffield
parent
253504a094
commit
6171690b00
@ -124,8 +124,8 @@ var authorInitialCache = make(map[string]string)
|
|||||||
var authorNameCache = make(map[string]string)
|
var authorNameCache = make(map[string]string)
|
||||||
|
|
||||||
func shortAuthor(authorName string) string {
|
func shortAuthor(authorName string) string {
|
||||||
if _, ok := authorInitialCache[authorName]; ok {
|
if value, ok := authorInitialCache[authorName]; ok {
|
||||||
return authorInitialCache[authorName]
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
initials := getInitials(authorName)
|
initials := getInitials(authorName)
|
||||||
@ -140,8 +140,8 @@ func shortAuthor(authorName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func longAuthor(authorName string) string {
|
func longAuthor(authorName string) string {
|
||||||
if _, ok := authorNameCache[authorName]; ok {
|
if value, ok := authorNameCache[authorName]; ok {
|
||||||
return authorNameCache[authorName]
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
truncatedName := utils.TruncateWithEllipsis(authorName, 17)
|
truncatedName := utils.TruncateWithEllipsis(authorName, 17)
|
||||||
@ -184,7 +184,7 @@ func getInitials(authorName string) string {
|
|||||||
return utils.LimitStr(authorName, 2)
|
return utils.LimitStr(authorName, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
return split[0][0:1] + split[1][0:1]
|
return utils.LimitStr(split[0], 1) + utils.LimitStr(split[1], 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func actionColorMap(str string) style.TextStyle {
|
func actionColorMap(str string) style.TextStyle {
|
||||||
|
@ -146,8 +146,12 @@ func Reverse(values []string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LimitStr(value string, limit int) string {
|
func LimitStr(value string, limit int) string {
|
||||||
if len(value) > limit {
|
n := 0
|
||||||
return value[:limit]
|
for i := range value {
|
||||||
|
if n >= limit {
|
||||||
|
return value[:i]
|
||||||
|
}
|
||||||
|
n++
|
||||||
}
|
}
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
@ -290,6 +290,16 @@ func TestLimitStr(t *testing.T) {
|
|||||||
limit: 3,
|
limit: 3,
|
||||||
want: "abc",
|
want: "abc",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
values: "あいう",
|
||||||
|
limit: 1,
|
||||||
|
want: "あ",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
values: "あいう",
|
||||||
|
limit: 2,
|
||||||
|
want: "あい",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
if got := LimitStr(test.values, test.limit); !assert.EqualValues(t, got, test.want) {
|
if got := LimitStr(test.values, test.limit); !assert.EqualValues(t, got, test.want) {
|
||||||
t.Errorf("LimitString(%v, %d) = %v; want %v", test.values, test.limit, got, test.want)
|
t.Errorf("LimitString(%v, %d) = %v; want %v", test.values, test.limit, got, test.want)
|
||||||
|
Reference in New Issue
Block a user