func trimStr2Runes(s string, w int) []rune { if w <= 0 { return []rune{} } sw := rw.StringWidth(s) if sw > w { return []rune(rw.Truncate(s, w, dot)) } return str2runes(s) //[]rune(rw.Truncate(s, w, "")) }
// TrimStrIfAppropriate trim string to "s[:-1] + …" // if string > width otherwise return string func TrimStrIfAppropriate(s string, w int) string { if w <= 0 { return "" } sw := rw.StringWidth(s) if sw > w { return rw.Truncate(s, w, dot) } return s }
func BenchmarkOtherlib3(b *testing.B) { for n := 0; n < b.N; n++ { _ = mattn.StringWidth("あいうえおあいうえおえおおおおおおおおおおおおおおおおおおおおおおおおおおおおおお") } }
func BenchmarkOtherlib2(b *testing.B) { for n := 0; n < b.N; n++ { _ = mattn.StringWidth("■㈱の世界①") } }
func BenchmarkOtherlibEasyString(b *testing.B) { for n := 0; n < b.N; n++ { _ = mattn.StringWidth("abcdefgkljjsfkjn") } }
func BenchmarkOtherlib4(b *testing.B) { for n := 0; n < b.N; n++ { _ = mattn.StringWidth(long) } }
func strWidth(s string) int { return rw.StringWidth(s) }
ColorBlue ColorMagenta ColorCyan ColorWhite ) const NumberofColors = 8 //Have a constant that defines number of colors const ( AttrBold Attribute = 1 << (iota + 9) AttrUnderline AttrReverse ) var ( dot = "…" dotw = rw.StringWidth(dot) ) /* ----------------------- End ----------------------------- */ func toTmAttr(x Attribute) tm.Attribute { return tm.Attribute(x) } func str2runes(s string) []rune { return []rune(s) } func trimStr2Runes(s string, w int) []rune { if w <= 0 { return []rune{}