Handle CJK widths
This commit is contained in:
parent
09dd8e88a4
commit
66f1319170
20
helper.go
20
helper.go
@ -1,8 +1,7 @@
|
||||
package termui
|
||||
|
||||
import "unicode/utf8"
|
||||
import "strings"
|
||||
import tm "github.com/nsf/termbox-go"
|
||||
import rw "github.com/mattn/go-runewidth"
|
||||
|
||||
/* ---------------Port from termbox-go --------------------- */
|
||||
|
||||
@ -33,25 +32,12 @@ func toTmAttr(x Attribute) tm.Attribute {
|
||||
}
|
||||
|
||||
func str2runes(s string) []rune {
|
||||
n := utf8.RuneCountInString(s)
|
||||
ss := strings.Split(s, "")
|
||||
|
||||
rs := make([]rune, n)
|
||||
for i := 0; i < n; i++ {
|
||||
r, _ := utf8.DecodeRuneInString(ss[i])
|
||||
rs[i] = r
|
||||
}
|
||||
return rs
|
||||
return []rune(s)
|
||||
}
|
||||
|
||||
func trimStr2Runes(s string, w int) []rune {
|
||||
rs := str2runes(s)
|
||||
if w <= 0 {
|
||||
return []rune{}
|
||||
}
|
||||
if len(rs) > w {
|
||||
rs = rs[:w]
|
||||
rs[w-1] = '…'
|
||||
}
|
||||
return rs
|
||||
return []rune(rw.Truncate(s, w, "…"))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user