mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
parent
6ea196a5e2
commit
f02017352d
|
@ -5,7 +5,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/regex"
|
"github.com/jandedobbeleer/oh-my-posh/src/regex"
|
||||||
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
|
||||||
"github.com/mattn/go-runewidth"
|
"github.com/mattn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,61 +68,17 @@ func (w *Writer) replaceHyperlink(text string) string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkText := results["TEXT"]
|
||||||
|
|
||||||
// we only care about the length of the text part
|
// we only care about the length of the text part
|
||||||
w.length += runewidth.StringWidth(results["TEXT"])
|
w.length += runewidth.StringWidth(linkText)
|
||||||
|
|
||||||
if w.Plain {
|
if w.Plain {
|
||||||
return results["TEXT"]
|
return linkText
|
||||||
}
|
}
|
||||||
|
|
||||||
linkText := w.escapeLinkTextForFishShell(results["TEXT"])
|
|
||||||
// build hyperlink ansi
|
// build hyperlink ansi
|
||||||
hyperlink := fmt.Sprintf(w.hyperlink, results["URL"], linkText)
|
hyperlink := fmt.Sprintf(w.hyperlink, results["URL"], linkText)
|
||||||
// replace original text by the new ones
|
// replace original text by the new ones
|
||||||
return strings.Replace(text, results["ALL"], hyperlink, 1)
|
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