fix: exclude link on measure

resolves #1691
This commit is contained in:
Jan De Dobbeleer 2022-02-05 20:54:05 +01:00 committed by Jan De Dobbeleer
parent 4fe1feb488
commit c34ea9c8f5
3 changed files with 18 additions and 2 deletions

View file

@ -1,8 +1,20 @@
package color
import "unicode/utf8"
import (
"oh-my-posh/regex"
"strings"
"unicode/utf8"
)
func measureText(text string) int {
// skip hyperlinks
if !strings.Contains(text, "\x1b]8;;") {
return utf8.RuneCountInString(text)
}
matches := regex.FindAllNamedRegexMatch(regex.LINK, text)
for _, match := range matches {
text = strings.ReplaceAll(text, match["STR"], match["TEXT"])
}
length := utf8.RuneCountInString(text)
return length
}

View file

@ -190,7 +190,7 @@ func (ir *ImageRenderer) Init(config string) {
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
lineChange: `^(?P<STR>\x1b\[(\d)[FB])`,
consoleTitle: `^(?P<STR>\x1b\]0;(.+)\007)`,
link: `^(?P<STR>\x1b]8;;(file|https)(.+)\x1b\\(?P<URL>.+)\x1b]8;;\x1b\\)`,
link: fmt.Sprintf(`^%s`, regex.LINK),
}
}

View file

@ -10,6 +10,10 @@ var (
regexCacheLock = sync.RWMutex{}
)
const (
LINK = `(?P<STR>\x1b]8;;(file|https)(.+)\x1b\\(?P<TEXT>.+)\x1b]8;;\x1b\\)`
)
func GetCompiledRegex(pattern string) *regexp.Regexp {
// try in cache first
regexCacheLock.RLock()