mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
parent
6ea196a5e2
commit
f02017352d
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue