fix(fish): remove hyperlink escaping

relates to #3288
This commit is contained in:
Jan De Dobbeleer 2023-01-08 11:51:11 +01:00 committed by Jan De Dobbeleer
parent 6ea196a5e2
commit f02017352d

View file

@ -5,7 +5,6 @@ import (
"strings"
"github.com/jandedobbeleer/oh-my-posh/src/regex"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
"github.com/mattn/go-runewidth"
)
@ -69,61 +68,17 @@ func (w *Writer) replaceHyperlink(text string) string {
return text
}
linkText := results["TEXT"]
// we only care about the length of the text part
w.length += runewidth.StringWidth(results["TEXT"])
w.length += runewidth.StringWidth(linkText)
if w.Plain {
return results["TEXT"]
return linkText
}
linkText := w.escapeLinkTextForFishShell(results["TEXT"])
// build hyperlink ansi
hyperlink := fmt.Sprintf(w.hyperlink, results["URL"], linkText)
// replace original text by the new ones
return strings.Replace(text, results["ALL"], hyperlink, 1)
}
func (w *Writer) escapeLinkTextForFishShell(text string) string {
if w.shell != shell.FISH {
return text
}
escapeChars := map[string]string{
`c`: `\c`,
`a`: `\a`,
`b`: `\b`,
`e`: `\e`,
`f`: `\f`,
`n`: `\n`,
`r`: `\r`,
`t`: `\t`,
`v`: `\v`,
`$`: `\$`,
`*`: `\*`,
`?`: `\?`,
`~`: `\~`,
`%`: `\%`,
`#`: `\#`,
`(`: `\(`,
`)`: `\)`,
`{`: `\{`,
`}`: `\}`,
`[`: `\[`,
`]`: `\]`,
`<`: `\<`,
`>`: `\>`,
`^`: `\^`,
`&`: `\&`,
`;`: `\;`,
`"`: `\"`,
`'`: `\'`,
`x`: `\x`,
`X`: `\X`,
`0`: `\0`,
`u`: `\u`,
`U`: `\U`,
}
if val, ok := escapeChars[text[0:1]]; ok {
return val + text[1:]
}
return text
}