~poldi1405/go-ansi

ref: 76d320c6afe7577b81dc9a9196484bbcad5057a9 go-ansi/length.go -rw-r--r-- 250 bytes
76d320c6 — Moritz Poldrack added function to remove all ANSI-Codes from a string 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
package ansi

import (
	"regexp"
	"unicode/utf8"
)

func GetLengthWithoutCodes(content string) int {
	var re = regexp.MustCompile(`(?m)\x1b\[([\d;]+m|[\d;]+(H|A|B|C|D|J|K|S|T)|s|u)`)
	return utf8.RuneCountInString(re.ReplaceAllString(content, ""))
}