fix(pwd): do not print quotes

relates to #2515
This commit is contained in:
Jan De Dobbeleer 2023-01-08 12:10:44 +01:00 committed by Jan De Dobbeleer
parent f02017352d
commit 57bfb8a419
4 changed files with 19 additions and 17 deletions

View file

@ -134,8 +134,8 @@ func (w *Writer) Init(shellName string) {
w.escapeRight = "\\]" w.escapeRight = "\\]"
w.hyperlink = "\\[\x1b]8;;%s\x1b\\\\\\]%s\\[\x1b]8;;\x1b\\\\\\]" w.hyperlink = "\\[\x1b]8;;%s\x1b\\\\\\]%s\\[\x1b]8;;\x1b\\\\\\]"
w.hyperlinkRegex = `(?P<STR>\\\[\x1b\]8;;(.+)\x1b\\\\\\\](?P<TEXT>.+)\\\[\x1b\]8;;\x1b\\\\\\\])` w.hyperlinkRegex = `(?P<STR>\\\[\x1b\]8;;(.+)\x1b\\\\\\\](?P<TEXT>.+)\\\[\x1b\]8;;\x1b\\\\\\\])`
w.osc99 = "\\[\x1b]9;9;\"%s\"\x1b\\\\\\]" w.osc99 = "\\[\x1b]9;9;%s\x1b\\\\\\]"
w.osc7 = "\\[\x1b]7;\"file://%s/%s\"\x1b\\\\\\]" w.osc7 = "\\[\x1b]7;file://%s/%s\x1b\\\\\\]"
w.osc51 = "\\[\x1b]51;A;%s@%s:%s\x1b\\\\\\]" w.osc51 = "\\[\x1b]51;A;%s@%s:%s\x1b\\\\\\]"
case "zsh": case "zsh":
w.format = "%%{%s%%}" w.format = "%%{%s%%}"
@ -151,8 +151,8 @@ func (w *Writer) Init(shellName string) {
w.escapeRight = "%}" w.escapeRight = "%}"
w.hyperlink = "%%{\x1b]8;;%s\x1b\\%%}%s%%{\x1b]8;;\x1b\\%%}" w.hyperlink = "%%{\x1b]8;;%s\x1b\\%%}%s%%{\x1b]8;;\x1b\\%%}"
w.hyperlinkRegex = `(?P<STR>%{\x1b]8;;(.+)\x1b\\%}(?P<TEXT>.+)%{\x1b]8;;\x1b\\%})` w.hyperlinkRegex = `(?P<STR>%{\x1b]8;;(.+)\x1b\\%}(?P<TEXT>.+)%{\x1b]8;;\x1b\\%})`
w.osc99 = "%%{\x1b]9;9;\"%s\"\x1b\\%%}" w.osc99 = "%%{\x1b]9;9;%s\x1b\\%%}"
w.osc7 = "%%{\x1b]7;file:\"//%s/%s\"\x1b\\%%}" w.osc7 = "%%{\x1b]7;file://%s/%s\x1b\\%%}"
w.osc51 = "%%{\x1b]51;A%s@%s:%s\x1b\\%%}" w.osc51 = "%%{\x1b]51;A%s@%s:%s\x1b\\%%}"
default: default:
w.linechange = "\x1b[%d%s" 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 // https://github.com/JanDeDobbeleer/oh-my-posh/pull/3288#issuecomment-1369137068
w.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\" w.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
w.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)" w.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
w.osc99 = "\x1b]9;9;\"%s\"\x1b\\" w.osc99 = "\x1b]9;9;%s\x1b\\"
w.osc7 = "\x1b]7;\"file://%s/%s\"\x1b\\" w.osc7 = "\x1b]7;file://%s/%s\x1b\\"
w.osc51 = "\x1b]51;A%s@%s:%s\x1b\\" w.osc51 = "\x1b]51;A%s@%s:%s\x1b\\"
} }
} }

View file

@ -57,6 +57,11 @@ Exports the config to an image file using customized output options.`,
env.Init() env.Init()
defer env.Close() defer env.Close()
cfg := engine.LoadConfig(env) cfg := engine.LoadConfig(env)
// set dsane defaults for things we don't print
cfg.ConsoleTitleTemplate = ""
cfg.PWD = ""
writerColors := cfg.MakeColors() writerColors := cfg.MakeColors()
writer := &ansi.Writer{ writer := &ansi.Writer{
TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground), TerminalBackground: shell.ConsoleBackgroundColor(env, cfg.TerminalBackground),
@ -68,7 +73,9 @@ Exports the config to an image file using customized output options.`,
Env: env, Env: env,
Writer: writer, Writer: writer,
} }
prompt := eng.PrintPrimary() prompt := eng.PrintPrimary()
imageCreator := &engine.ImageRenderer{ imageCreator := &engine.ImageRenderer{
AnsiString: prompt, AnsiString: prompt,
Author: author, Author: author,
@ -82,6 +89,7 @@ Exports the config to an image file using customized output options.`,
} }
imageCreator.Init(env.Flags().Config) imageCreator.Init(env.Flags().Config)
err := imageCreator.SavePNG() err := imageCreator.SavePNG()
if err != nil { if err != nil {
fmt.Print(err.Error()) fmt.Print(err.Error())
} }

View file

@ -52,12 +52,12 @@ func TestPrintPWD(t *testing.T) {
OSC99 bool OSC99 bool
}{ }{
{Case: "Empty PWD"}, {Case: "Empty PWD"},
{Case: "OSC99", PWD: ansi.OSC99, Expected: "\x1b]9;9;\"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: "OSC7", PWD: ansi.OSC7, Expected: "\x1b]7;file://host/pwd\x1b\\"},
{Case: "OSC51", PWD: ansi.OSC51, Expected: "\x1b]51;Auser@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 (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 { for _, tc := range cases {

View file

@ -69,9 +69,6 @@ const (
strikethroughReset = "strikethroughr" strikethroughReset = "strikethroughr"
color16 = "color16" color16 = "color16"
left = "left" left = "left"
osc99 = "osc99"
osc7 = "osc7"
osc51 = "osc51"
lineChange = "linechange" lineChange = "linechange"
consoleTitle = "title" consoleTitle = "title"
link = "link" link = "link"
@ -197,9 +194,6 @@ func (ir *ImageRenderer) Init(config string) {
strikethroughReset: `^(?P<STR>\x1b\[29m)`, strikethroughReset: `^(?P<STR>\x1b\[29m)`,
color16: `^(?P<STR>\x1b\[(?P<BC>[349][0-7]|10[0-7]|39)m)`, color16: `^(?P<STR>\x1b\[(?P<BC>[349][0-7]|10[0-7]|39)m)`,
left: `^(?P<STR>\x1b\[(\d{1,3})D)`, left: `^(?P<STR>\x1b\[(\d{1,3})D)`,
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
osc7: `^(?P<STR>\x1b\]7;(.+)\x1b\\)`,
osc51: `^(?P<STR>\x1b\]51;A(.+)\x1b\\)`,
lineChange: `^(?P<STR>\x1b\[(\d)[FB])`, lineChange: `^(?P<STR>\x1b\[(\d)[FB])`,
consoleTitle: `^(?P<STR>\x1b\]0;(.+)\007)`, consoleTitle: `^(?P<STR>\x1b\]0;(.+)\007)`,
link: fmt.Sprintf(`^%s`, regex.LINK), link: fmt.Sprintf(`^%s`, regex.LINK),
@ -507,7 +501,7 @@ func (ir *ImageRenderer) shouldPrint() bool {
case boldReset, italicReset, underlineReset, overlineReset: case boldReset, italicReset, underlineReset, overlineReset:
ir.style = "" ir.style = ""
return false return false
case strikethrough, strikethroughReset, left, osc99, osc7, osc51, lineChange, consoleTitle: case strikethrough, strikethroughReset, left, lineChange, consoleTitle:
return false return false
case color16: case color16:
ir.setBase16Color(match[bc]) ir.setBase16Color(match[bc])