mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
feat(shell): osc51 support
working directory OSC for emacs-libvterm
This commit is contained in:
parent
389262edd0
commit
1c7db480f9
|
@ -12,6 +12,7 @@ const (
|
||||||
|
|
||||||
OSC99 string = "osc99"
|
OSC99 string = "osc99"
|
||||||
OSC7 string = "osc7"
|
OSC7 string = "osc7"
|
||||||
|
OSC51 string = "osc51"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ansi struct {
|
type Ansi struct {
|
||||||
|
@ -34,6 +35,7 @@ type Ansi struct {
|
||||||
hyperlinkRegex string
|
hyperlinkRegex string
|
||||||
osc99 string
|
osc99 string
|
||||||
osc7 string
|
osc7 string
|
||||||
|
osc51 string
|
||||||
bold string
|
bold string
|
||||||
italic string
|
italic string
|
||||||
underline string
|
underline string
|
||||||
|
@ -68,6 +70,7 @@ func (a *Ansi) Init(shellName string) {
|
||||||
a.hyperlinkRegex = `(?P<STR>%{\x1b]8;;(.+)\x1b\\%}(?P<TEXT>.+)%{\x1b]8;;\x1b\\%})`
|
a.hyperlinkRegex = `(?P<STR>%{\x1b]8;;(.+)\x1b\\%}(?P<TEXT>.+)%{\x1b]8;;\x1b\\%})`
|
||||||
a.osc99 = "%%{\x1b]9;9;\"%s\"\x1b\\%%}"
|
a.osc99 = "%%{\x1b]9;9;\"%s\"\x1b\\%%}"
|
||||||
a.osc7 = "%%{\x1b]7;file:\"//%s/%s\"\x1b\\%%}"
|
a.osc7 = "%%{\x1b]7;file:\"//%s/%s\"\x1b\\%%}"
|
||||||
|
a.osc51 = "%%{\x1b]51;A%s@%s:%s\x1b\\%%}"
|
||||||
a.bold = "%%{\x1b[1m%%}%s%%{\x1b[22m%%}"
|
a.bold = "%%{\x1b[1m%%}%s%%{\x1b[22m%%}"
|
||||||
a.italic = "%%{\x1b[3m%%}%s%%{\x1b[23m%%}"
|
a.italic = "%%{\x1b[3m%%}%s%%{\x1b[23m%%}"
|
||||||
a.underline = "%%{\x1b[4m%%}%s%%{\x1b[24m%%}"
|
a.underline = "%%{\x1b[4m%%}%s%%{\x1b[24m%%}"
|
||||||
|
@ -96,6 +99,7 @@ func (a *Ansi) Init(shellName string) {
|
||||||
a.hyperlinkRegex = `(?P<STR>\\\[\x1b\]8;;(.+)\x1b\\\\\\\](?P<TEXT>.+)\\\[\x1b\]8;;\x1b\\\\\\\])`
|
a.hyperlinkRegex = `(?P<STR>\\\[\x1b\]8;;(.+)\x1b\\\\\\\](?P<TEXT>.+)\\\[\x1b\]8;;\x1b\\\\\\\])`
|
||||||
a.osc99 = "\\[\x1b]9;9;\"%s\"\x1b\\\\\\]"
|
a.osc99 = "\\[\x1b]9;9;\"%s\"\x1b\\\\\\]"
|
||||||
a.osc7 = "\\[\x1b]7;\"file://%s/%s\"\x1b\\\\\\]"
|
a.osc7 = "\\[\x1b]7;\"file://%s/%s\"\x1b\\\\\\]"
|
||||||
|
a.osc51 = "\\[\x1b]51;A;%s@%s:%s\x1b\\\\\\]"
|
||||||
a.bold = "\\[\x1b[1m\\]%s\\[\x1b[22m\\]"
|
a.bold = "\\[\x1b[1m\\]%s\\[\x1b[22m\\]"
|
||||||
a.italic = "\\[\x1b[3m\\]%s\\[\x1b[23m\\]"
|
a.italic = "\\[\x1b[3m\\]%s\\[\x1b[23m\\]"
|
||||||
a.underline = "\\[\x1b[4m\\]%s\\[\x1b[24m\\]"
|
a.underline = "\\[\x1b[4m\\]%s\\[\x1b[24m\\]"
|
||||||
|
@ -124,6 +128,7 @@ func (a *Ansi) Init(shellName string) {
|
||||||
a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
|
a.hyperlinkRegex = "(?P<STR>\x1b]8;;(.+)\x1b\\\\\\\\?(?P<TEXT>.+)\x1b]8;;\x1b\\\\)"
|
||||||
a.osc99 = "\x1b]9;9;\"%s\"\x1b\\"
|
a.osc99 = "\x1b]9;9;\"%s\"\x1b\\"
|
||||||
a.osc7 = "\x1b]7;\"file://%s/%s\"\x1b\\"
|
a.osc7 = "\x1b]7;\"file://%s/%s\"\x1b\\"
|
||||||
|
a.osc51 = "\x1b]51;A%s@%s:%s\x1b\\"
|
||||||
a.bold = "\x1b[1m%s\x1b[22m"
|
a.bold = "\x1b[1m%s\x1b[22m"
|
||||||
a.italic = "\x1b[3m%s\x1b[23m"
|
a.italic = "\x1b[3m%s\x1b[23m"
|
||||||
a.underline = "\x1b[4m%s\x1b[24m"
|
a.underline = "\x1b[4m%s\x1b[24m"
|
||||||
|
@ -303,13 +308,15 @@ func (a *Ansi) ChangeLine(numberOfLines int) string {
|
||||||
return fmt.Sprintf(a.linechange, numberOfLines, position)
|
return fmt.Sprintf(a.linechange, numberOfLines, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Ansi) ConsolePwd(pwdType, hostName, pwd string) string {
|
func (a *Ansi) ConsolePwd(pwdType, userName, hostName, pwd string) string {
|
||||||
if strings.HasSuffix(pwd, ":") {
|
if strings.HasSuffix(pwd, ":") {
|
||||||
pwd += "\\"
|
pwd += "\\"
|
||||||
}
|
}
|
||||||
switch pwdType {
|
switch pwdType {
|
||||||
case OSC7:
|
case OSC7:
|
||||||
return fmt.Sprintf(a.osc7, hostName, pwd)
|
return fmt.Sprintf(a.osc7, hostName, pwd)
|
||||||
|
case OSC51:
|
||||||
|
return fmt.Sprintf(a.osc51, userName, hostName, pwd)
|
||||||
case OSC99:
|
case OSC99:
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -85,7 +85,7 @@ func (e *Engine) printPWD() {
|
||||||
cwd := e.Env.Pwd()
|
cwd := e.Env.Pwd()
|
||||||
// Backwards compatibility for deprecated OSC99
|
// Backwards compatibility for deprecated OSC99
|
||||||
if e.Config.OSC99 {
|
if e.Config.OSC99 {
|
||||||
e.writeANSI(e.Ansi.ConsolePwd(color.OSC99, "", cwd))
|
e.writeANSI(e.Ansi.ConsolePwd(color.OSC99, "", "", cwd))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Allow template logic to define when to enable the PWD (when supported)
|
// Allow template logic to define when to enable the PWD (when supported)
|
||||||
|
@ -97,8 +97,9 @@ func (e *Engine) printPWD() {
|
||||||
if err != nil || len(pwdType) == 0 {
|
if err != nil || len(pwdType) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
user := e.Env.User()
|
||||||
host, _ := e.Env.Host()
|
host, _ := e.Env.Host()
|
||||||
e.writeANSI(e.Ansi.ConsolePwd(pwdType, host, cwd))
|
e.writeANSI(e.Ansi.ConsolePwd(pwdType, user, host, cwd))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Engine) newline() {
|
func (e *Engine) newline() {
|
||||||
|
|
|
@ -54,6 +54,7 @@ func TestPrintPWD(t *testing.T) {
|
||||||
{Case: "Empty PWD"},
|
{Case: "Empty PWD"},
|
||||||
{Case: "OSC99", PWD: color.OSC99, Expected: "\x1b]9;9;\"pwd\"\x1b\\"},
|
{Case: "OSC99", PWD: color.OSC99, Expected: "\x1b]9;9;\"pwd\"\x1b\\"},
|
||||||
{Case: "OSC7", PWD: color.OSC7, Expected: "\x1b]7;\"file://host/pwd\"\x1b\\"},
|
{Case: "OSC7", PWD: color.OSC7, Expected: "\x1b]7;\"file://host/pwd\"\x1b\\"},
|
||||||
|
{Case: "OSC51", PWD: color.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\\"},
|
||||||
|
@ -63,6 +64,7 @@ func TestPrintPWD(t *testing.T) {
|
||||||
env := new(mock.MockedEnvironment)
|
env := new(mock.MockedEnvironment)
|
||||||
env.On("Pwd").Return("pwd")
|
env.On("Pwd").Return("pwd")
|
||||||
env.On("Shell").Return("shell")
|
env.On("Shell").Return("shell")
|
||||||
|
env.On("User").Return("user")
|
||||||
env.On("Host").Return("host", nil)
|
env.On("Host").Return("host", nil)
|
||||||
env.On("TemplateCache").Return(&platform.TemplateCache{
|
env.On("TemplateCache").Return(&platform.TemplateCache{
|
||||||
Env: make(map[string]string),
|
Env: make(map[string]string),
|
||||||
|
|
|
@ -70,6 +70,7 @@ const (
|
||||||
left = "left"
|
left = "left"
|
||||||
osc99 = "osc99"
|
osc99 = "osc99"
|
||||||
osc7 = "osc7"
|
osc7 = "osc7"
|
||||||
|
osc51 = "osc51"
|
||||||
lineChange = "linechange"
|
lineChange = "linechange"
|
||||||
consoleTitle = "title"
|
consoleTitle = "title"
|
||||||
link = "link"
|
link = "link"
|
||||||
|
@ -197,6 +198,7 @@ func (ir *ImageRenderer) Init(config string) {
|
||||||
left: `^(?P<STR>\x1b\[(\d{1,3})D)`,
|
left: `^(?P<STR>\x1b\[(\d{1,3})D)`,
|
||||||
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
|
osc99: `^(?P<STR>\x1b\]9;9;(.+)\x1b\\)`,
|
||||||
osc7: `^(?P<STR>\x1b\]7;(.+)\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),
|
||||||
|
@ -504,7 +506,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, lineChange, consoleTitle:
|
case strikethrough, strikethroughReset, left, osc99, osc7, osc51, lineChange, consoleTitle:
|
||||||
return false
|
return false
|
||||||
case color16:
|
case color16:
|
||||||
ir.setBase16Color(match[bc])
|
ir.setBase16Color(match[bc])
|
||||||
|
|
|
@ -2869,7 +2869,7 @@
|
||||||
},
|
},
|
||||||
"pwd": {
|
"pwd": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"title": "Enable OSC99/7",
|
"title": "Enable OSC99/7/51",
|
||||||
"description": "https://ohmyposh.dev/docs/configuration/overview#general-settings",
|
"description": "https://ohmyposh.dev/docs/configuration/overview#general-settings",
|
||||||
"default": ""
|
"default": ""
|
||||||
},
|
},
|
||||||
|
|
|
@ -129,7 +129,7 @@ For example, the following is a valid `--config` flag:
|
||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| --------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `final_space` | `boolean` | when true adds a space at the end of the prompt |
|
| `final_space` | `boolean` | when true adds a space at the end of the prompt |
|
||||||
| `pwd` | `string` | notify terminal of current working directory, values can be `osc99` or `osc7` depending on your terminal |
|
| `pwd` | `string` | notify terminal of current working directory, values can be `osc99`, `osc7`, or `osc51` depending on your terminal |
|
||||||
| `terminal_background` | `string` | [color][colors] - terminal background color, set to your terminal's background color when you notice black elements in Windows Terminal or the Visual Studio Code integrated terminal |
|
| `terminal_background` | `string` | [color][colors] - terminal background color, set to your terminal's background color when you notice black elements in Windows Terminal or the Visual Studio Code integrated terminal |
|
||||||
| `accent_color` | `string` | [color][colors] - accent color, used as a fallback when the `accent` [color][accent] is not supported |
|
| `accent_color` | `string` | [color][colors] - accent color, used as a fallback when the `accent` [color][accent] is not supported |
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue