clifmt/util.go

23 lines
374 B
Go
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package clifmt
import (
"regexp"
)
var esc = regexp.MustCompile(`(?m)\[(?:\d+;)*\d+m`)
// displaySize returns the real size escaping special characters
func displaySize(s string) int {
// 1. get actual size
size := len(s)
// 2. get all terminal coloring matches
matches := esc.FindAllString(s, -1)
for _, m := range matches {
size -= len(m)
}
return size
}