From 57bfb8a419a5f7d5377247d1dd65b8fcbbc4aafe Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sun, 8 Jan 2023 12:10:44 +0100 Subject: [PATCH] fix(pwd): do not print quotes relates to #2515 --- src/ansi/ansi_writer.go | 12 ++++++------ src/cli/config_export_image.go | 8 ++++++++ src/engine/engine_test.go | 8 ++++---- src/engine/image.go | 8 +------- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go index c8f99e37..c33e3208 100644 --- a/src/ansi/ansi_writer.go +++ b/src/ansi/ansi_writer.go @@ -134,8 +134,8 @@ func (w *Writer) Init(shellName string) { w.escapeRight = "\\]" w.hyperlink = "\\[\x1b]8;;%s\x1b\\\\\\]%s\\[\x1b]8;;\x1b\\\\\\]" w.hyperlinkRegex = `(?P\\\[\x1b\]8;;(.+)\x1b\\\\\\\](?P.+)\\\[\x1b\]8;;\x1b\\\\\\\])` - w.osc99 = "\\[\x1b]9;9;\"%s\"\x1b\\\\\\]" - w.osc7 = "\\[\x1b]7;\"file://%s/%s\"\x1b\\\\\\]" + w.osc99 = "\\[\x1b]9;9;%s\x1b\\\\\\]" + w.osc7 = "\\[\x1b]7;file://%s/%s\x1b\\\\\\]" w.osc51 = "\\[\x1b]51;A;%s@%s:%s\x1b\\\\\\]" case "zsh": w.format = "%%{%s%%}" @@ -151,8 +151,8 @@ func (w *Writer) Init(shellName string) { w.escapeRight = "%}" w.hyperlink = "%%{\x1b]8;;%s\x1b\\%%}%s%%{\x1b]8;;\x1b\\%%}" w.hyperlinkRegex = `(?P%{\x1b]8;;(.+)\x1b\\%}(?P.+)%{\x1b]8;;\x1b\\%})` - w.osc99 = "%%{\x1b]9;9;\"%s\"\x1b\\%%}" - w.osc7 = "%%{\x1b]7;file:\"//%s/%s\"\x1b\\%%}" + w.osc99 = "%%{\x1b]9;9;%s\x1b\\%%}" + w.osc7 = "%%{\x1b]7;file://%s/%s\x1b\\%%}" w.osc51 = "%%{\x1b]51;A%s@%s:%s\x1b\\%%}" default: w.linechange = "\x1b[%d%s" @@ -168,8 +168,8 @@ func (w *Writer) Init(shellName string) { // https://github.com/JanDeDobbeleer/oh-my-posh/pull/3288#issuecomment-1369137068 w.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\" w.hyperlinkRegex = "(?P\x1b]8;;(.+)\x1b\\\\\\\\?(?P.+)\x1b]8;;\x1b\\\\)" - w.osc99 = "\x1b]9;9;\"%s\"\x1b\\" - w.osc7 = "\x1b]7;\"file://%s/%s\"\x1b\\" + w.osc99 = "\x1b]9;9;%s\x1b\\" + w.osc7 = "\x1b]7;file://%s/%s\x1b\\" w.osc51 = "\x1b]51;A%s@%s:%s\x1b\\" } } diff --git a/src/cli/config_export_image.go b/src/cli/config_export_image.go index 316ed4de..14d5abe3 100644 --- a/src/cli/config_export_image.go +++ b/src/cli/config_export_image.go @@ -57,6 +57,11 @@ Exports the config to an image file using customized output options.`, env.Init() defer env.Close() cfg := engine.LoadConfig(env) + + // set dsane defaults for things we don't print + cfg.ConsoleTitleTemplate = "" + cfg.PWD = "" + writerColors := cfg.MakeColors() writer := &ansi.Writer{ TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), @@ -68,7 +73,9 @@ Exports the config to an image file using customized output options.`, Env: env, Writer: writer, } + prompt := eng.PrintPrimary() + imageCreator := &engine.ImageRenderer{ AnsiString: prompt, Author: author, @@ -82,6 +89,7 @@ Exports the config to an image file using customized output options.`, } imageCreator.Init(env.Flags().Config) err := imageCreator.SavePNG() + if err != nil { fmt.Print(err.Error()) } diff --git a/src/engine/engine_test.go b/src/engine/engine_test.go index 0ec1e065..9d9d31f9 100644 --- a/src/engine/engine_test.go +++ b/src/engine/engine_test.go @@ -52,12 +52,12 @@ func TestPrintPWD(t *testing.T) { OSC99 bool }{ {Case: "Empty PWD"}, - {Case: "OSC99", PWD: ansi.OSC99, Expected: "\x1b]9;9;\"pwd\"\x1b\\"}, - {Case: "OSC7", PWD: ansi.OSC7, Expected: "\x1b]7;\"file://host/pwd\"\x1b\\"}, + {Case: "OSC99", PWD: ansi.OSC99, Expected: "\x1b]9;9;pwd\x1b\\"}, + {Case: "OSC7", PWD: ansi.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"}, {Case: "OSC51", PWD: ansi.OSC51, Expected: "\x1b]51;Auser@host:pwd\x1b\\"}, - {Case: "Deprecated OSC99", OSC99: true, Expected: "\x1b]9;9;\"pwd\"\x1b\\"}, + {Case: "Deprecated OSC99", OSC99: true, Expected: "\x1b]9;9;pwd\x1b\\"}, {Case: "Template (empty)", PWD: "{{ if eq .Shell \"pwsh\" }}osc7{{ end }}"}, - {Case: "Template (non empty)", PWD: "{{ if eq .Shell \"shell\" }}osc7{{ end }}", Expected: "\x1b]7;\"file://host/pwd\"\x1b\\"}, + {Case: "Template (non empty)", PWD: "{{ if eq .Shell \"shell\" }}osc7{{ end }}", Expected: "\x1b]7;file://host/pwd\x1b\\"}, } for _, tc := range cases { diff --git a/src/engine/image.go b/src/engine/image.go index 4a26187a..0d97ee74 100644 --- a/src/engine/image.go +++ b/src/engine/image.go @@ -69,9 +69,6 @@ const ( strikethroughReset = "strikethroughr" color16 = "color16" left = "left" - osc99 = "osc99" - osc7 = "osc7" - osc51 = "osc51" lineChange = "linechange" consoleTitle = "title" link = "link" @@ -197,9 +194,6 @@ func (ir *ImageRenderer) Init(config string) { strikethroughReset: `^(?P\x1b\[29m)`, color16: `^(?P\x1b\[(?P[349][0-7]|10[0-7]|39)m)`, left: `^(?P\x1b\[(\d{1,3})D)`, - osc99: `^(?P\x1b\]9;9;(.+)\x1b\\)`, - osc7: `^(?P\x1b\]7;(.+)\x1b\\)`, - osc51: `^(?P\x1b\]51;A(.+)\x1b\\)`, lineChange: `^(?P\x1b\[(\d)[FB])`, consoleTitle: `^(?P\x1b\]0;(.+)\007)`, link: fmt.Sprintf(`^%s`, regex.LINK), @@ -507,7 +501,7 @@ func (ir *ImageRenderer) shouldPrint() bool { case boldReset, italicReset, underlineReset, overlineReset: ir.style = "" return false - case strikethrough, strikethroughReset, left, osc99, osc7, osc51, lineChange, consoleTitle: + case strikethrough, strikethroughReset, left, lineChange, consoleTitle: return false case color16: ir.setBase16Color(match[bc])