func Len(text string) int {
	length := 0
	escape := false
	for _, char := range text {
		if char == '\x1b' {
			escape = true
		}
		if !escape {
			length += runewidth.RuneWidth(char)
		}
		if char == 'm' {
			escape = false
		}
	}
	return length
}
Len return the length of a string in a terminal, while ignoring the terminal
escape sequences.
package text
import (
	"strings"
	"github.com/mattn/go-runewidth"
)