package ui import ( "github.com/mattn/go-runewidth" ) // Splice splits the string s at the point x. func Splice(s string, x int) (string, string) { if runewidth.StringWidth(s) <= x { return s, "" } r := []rune(s) width := 0 i := 0 for ; i < len(r); i++ { cw := runewidth.RuneWidth(r[i]) if width+cw > x { break } width += cw } return string(r[:i]), string(r[i:]) }