fix(yay): fix -Si alignment when language is Chinese (#1799) (#1803)

This commit is contained in:
linweiyuan authored and GitHub committed 2022-08-29 15:33:48 +00:00
1 parent 14cc8d4ef0
commit 7ebe64871d
1 file changed
+20 -3
+20 -3
View File
@@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"syscall"
"unicode"
"github.com/leonelquinteros/gotext"
"golang.org/x/sys/unix"
@@ -84,13 +85,29 @@ func getColumnCount() int {
}
func PrintInfoValue(key string, values ...string) {
// 16 (text) + 1 (:) + 1 ( )
const (
keyLength = 18
keyLength = 32
delimCount = 2
)
str := fmt.Sprintf(Bold("%-16s: "), key)
specialWordsCount := 0
for _, runeValue := range key {
// CJK handling: the character 'ー' is Katakana
// but if use unicode.Katakana, it will return false
if unicode.IsOneOf([]*unicode.RangeTable{
unicode.Han,
unicode.Hiragana,
unicode.Katakana,
unicode.Hangul,
}, runeValue) || runeValue == 'ー' {
specialWordsCount++
}
}
keyTextCount := specialWordsCount - keyLength + delimCount
str := fmt.Sprintf(Bold("%-*s: "), keyTextCount, key)
if len(values) == 0 || (len(values) == 1 && values[0] == "") {
fmt.Fprintf(os.Stdout, "%s%s\n", str, gotext.Get("None"))
return