mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-26 19:39:39 -08:00
parent
4fe1feb488
commit
c34ea9c8f5
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue