mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
4fe1feb488
commit
c34ea9c8f5
|
@ -1,8 +1,20 @@
|
||||||
package color
|
package color
|
||||||
|
|
||||||
import "unicode/utf8"
|
import (
|
||||||
|
"oh-my-posh/regex"
|
||||||
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
)
|
||||||
|
|
||||||
func measureText(text string) int {
|
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)
|
length := utf8.RuneCountInString(text)
|
||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ func (ir *ImageRenderer) Init(config string) {
|
||||||
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
|
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
|
||||||
lineChange: `^(?P<STR>\x1b\[(\d)[FB])`,
|
lineChange: `^(?P<STR>\x1b\[(\d)[FB])`,
|
||||||
consoleTitle: `^(?P<STR>\x1b\]0;(.+)\007)`,
|
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{}
|
regexCacheLock = sync.RWMutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
LINK = `(?P<STR>\x1b]8;;(file|https)(.+)\x1b\\(?P<TEXT>.+)\x1b]8;;\x1b\\)`
|
||||||
|
)
|
||||||
|
|
||||||
func GetCompiledRegex(pattern string) *regexp.Regexp {
|
func GetCompiledRegex(pattern string) *regexp.Regexp {
|
||||||
// try in cache first
|
// try in cache first
|
||||||
regexCacheLock.RLock()
|
regexCacheLock.RLock()
|
||||||
|
|
Loading…
Reference in a new issue