fix(fish): do not fix fish bug for hyperlinks

This commit is contained in:
Jan De Dobbeleer 2023-01-02 20:03:24 +01:00 committed by Jan De Dobbeleer
parent 77d5c9ed95
commit e957e5f8cc
5 changed files with 12 additions and 16 deletions

View file

@ -48,7 +48,7 @@ type Ansi struct {
format string
}
func (a *Ansi) Init(shellName, goos string) {
func (a *Ansi) Init(shellName string) {
a.shell = shellName
switch shellName {
case shell.ZSH:
@ -125,6 +125,9 @@ func (a *Ansi) Init(shellName, goos string) {
a.colorTransparent = "\x1b[%s;49m\x1b[7m%s\x1b[0m"
a.escapeLeft = ""
a.escapeRight = ""
// when in fish on Linux, it seems hyperlinks ending with \\ print a \
// unlike on macOS. However, this is a fish bug, so do not try to fix it here:
// https://github.com/JanDeDobbeleer/oh-my-posh/pull/3288#issuecomment-1369137068
a.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
a.osc99 = "\x1b]9;9;\"%s\"\x1b\\"
@ -139,17 +142,10 @@ func (a *Ansi) Init(shellName, goos string) {
a.dimmed = "\x1b[2m%s\x1b[22m"
a.strikethrough = "\x1b[9m%s\x1b[29m"
}
// see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3287
// when in fish on Linux, it seems hyperlinks ending with \\ prints a \
// unlike on macOS
if shellName == shell.FISH && goos == "linux" {
a.hyperlink = "\x1b]8;;%s\x1b%s\x1b]8;;\x1b\\"
a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
}
}
func (a *Ansi) InitPlain() {
a.Init(shell.PLAIN, "")
a.Init(shell.PLAIN)
}
func (a *Ansi) GenerateHyperlink(text string) string {

View file

@ -20,7 +20,7 @@ func TestGenerateHyperlinkNoUrl(t *testing.T) {
}
for _, tc := range cases {
a := Ansi{}
a.Init(tc.ShellName, "")
a.Init(tc.ShellName)
hyperlinkText := a.GenerateHyperlink(tc.Text)
assert.Equal(t, tc.Expected, hyperlinkText)
}
@ -53,7 +53,7 @@ func TestGenerateHyperlinkWithUrl(t *testing.T) {
}
for _, tc := range cases {
a := Ansi{}
a.Init(tc.ShellName, "")
a.Init(tc.ShellName)
hyperlinkText := a.GenerateHyperlink(tc.Text)
assert.Equal(t, tc.Expected, hyperlinkText)
}
@ -71,7 +71,7 @@ func TestGenerateHyperlinkWithUrlNoName(t *testing.T) {
}
for _, tc := range cases {
a := Ansi{}
a.Init(tc.ShellName, "")
a.Init(tc.ShellName)
hyperlinkText := a.GenerateHyperlink(tc.Text)
assert.Equal(t, tc.Expected, hyperlinkText)
}
@ -115,7 +115,7 @@ func TestGenerateFileLink(t *testing.T) {
}
for _, tc := range cases {
a := Ansi{}
a.Init(shell.PWSH, "")
a.Init(shell.PWSH)
hyperlinkText := a.GenerateHyperlink(tc.Text)
assert.Equal(t, tc.Expected, hyperlinkText)
}

View file

@ -37,7 +37,7 @@ func TestMeasureText(t *testing.T) {
for _, shell := range shells {
for _, tc := range cases {
ansi := &Ansi{}
ansi.Init(shell, "")
ansi.Init(shell)
tmpl := &template.Text{
Template: tc.Template,
Env: env,

View file

@ -174,7 +174,7 @@ func TestWriteANSIColors(t *testing.T) {
for _, tc := range cases {
ansi := &Ansi{}
ansi.Init(shell.PWSH, "")
ansi.Init(shell.PWSH)
renderer := &AnsiWriter{
Ansi: ansi,
ParentColors: []*Color{tc.Parent},

View file

@ -26,7 +26,7 @@ func New(flags *platform.Flags) *Engine {
Ansi: ansi,
}
} else {
ansi.Init(env.Shell(), env.GOOS())
ansi.Init(env.Shell())
writerColors := cfg.MakeColors()
writer = &color.AnsiWriter{
Ansi: ansi,