mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
fix(link): allow multiple links in segment text
This commit is contained in:
parent
56a59a1b32
commit
336f351b98
|
@ -140,6 +140,22 @@ func (a *Ansi) InitPlain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Ansi) GenerateHyperlink(text string) string {
|
func (a *Ansi) GenerateHyperlink(text string) string {
|
||||||
|
parts := strings.SplitAfter(text, ")")
|
||||||
|
var buffer strings.Builder
|
||||||
|
var part string
|
||||||
|
for i := range parts {
|
||||||
|
if strings.Contains(parts[i], "[") && !strings.Contains(parts[i], "]") {
|
||||||
|
part += parts[i]
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
part += parts[i]
|
||||||
|
buffer.WriteString(a.replaceHyperlink(part))
|
||||||
|
part = ""
|
||||||
|
}
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Ansi) replaceHyperlink(text string) string {
|
||||||
// hyperlink matching
|
// hyperlink matching
|
||||||
results := regex.FindNamedRegexMatch("(?P<ALL>(?:\\[(?P<TEXT>.+)\\])(?:\\((?P<URL>.*)\\)))", text)
|
results := regex.FindNamedRegexMatch("(?P<ALL>(?:\\[(?P<TEXT>.+)\\])(?:\\((?P<URL>.*)\\)))", text)
|
||||||
if len(results) != 3 {
|
if len(results) != 3 {
|
||||||
|
|
|
@ -31,9 +31,19 @@ func TestGenerateHyperlinkWithUrl(t *testing.T) {
|
||||||
ShellName string
|
ShellName string
|
||||||
Expected string
|
Expected string
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
Text: "[google](http://www.google.be) [maps (2/2)](http://maps.google.be)",
|
||||||
|
ShellName: shell.FISH,
|
||||||
|
Expected: "\x1b]8;;http://www.google.be\x1b\\google\x1b]8;;\x1b\\ \x1b]8;;http://maps.google.be\x1b\\maps (2/2)\x1b]8;;\x1b\\",
|
||||||
|
},
|
||||||
{Text: "[google](http://www.google.be)", ShellName: shell.ZSH, Expected: "%{\x1b]8;;http://www.google.be\x1b\\%}google%{\x1b]8;;\x1b\\%}"},
|
{Text: "[google](http://www.google.be)", ShellName: shell.ZSH, Expected: "%{\x1b]8;;http://www.google.be\x1b\\%}google%{\x1b]8;;\x1b\\%}"},
|
||||||
{Text: "[google](http://www.google.be)", ShellName: shell.PWSH, Expected: "\x1b]8;;http://www.google.be\x1b\\google\x1b]8;;\x1b\\"},
|
{Text: "[google](http://www.google.be)", ShellName: shell.PWSH, Expected: "\x1b]8;;http://www.google.be\x1b\\google\x1b]8;;\x1b\\"},
|
||||||
{Text: "[google](http://www.google.be)", ShellName: shell.BASH, Expected: "\\[\x1b]8;;http://www.google.be\x1b\\\\\\]google\\[\x1b]8;;\x1b\\\\\\]"},
|
{Text: "[google](http://www.google.be)", ShellName: shell.BASH, Expected: "\\[\x1b]8;;http://www.google.be\x1b\\\\\\]google\\[\x1b]8;;\x1b\\\\\\]"},
|
||||||
|
{
|
||||||
|
Text: "[google](http://www.google.be) [maps](http://maps.google.be)",
|
||||||
|
ShellName: shell.FISH,
|
||||||
|
Expected: "\x1b]8;;http://www.google.be\x1b\\google\x1b]8;;\x1b\\ \x1b]8;;http://maps.google.be\x1b\\maps\x1b]8;;\x1b\\",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
a := Ansi{}
|
a := Ansi{}
|
||||||
|
|
Loading…
Reference in a new issue