fix: avoid error when duplicating wsl tab

use same osc escape code everywhere

detect wsl using env variable
This commit is contained in:
lnu 2021-02-15 08:26:52 +01:00 committed by Jan De Dobbeleer
parent 860eeb478a
commit 6add3bf2a0
6 changed files with 32 additions and 7 deletions

View file

@ -37,14 +37,14 @@ func (a *ansiFormats) init(shell string) {
a.clearEOL = "%{\x1b[K%}"
a.saveCursorPosition = "%{\x1b7%}"
a.restoreCursorPosition = "%{\x1b8%}"
a.title = "%%{\033]0;%s\007%%}"
a.title = "%%{\x1b]0;%s\007%%}"
a.colorSingle = "%%{\x1b[%sm%%}%s%%{\x1b[0m%%}"
a.colorFull = "%%{\x1b[%sm\x1b[%sm%%}%s%%{\x1b[0m%%}"
a.colorTransparent = "%%{\x1b[%s;49m\x1b[7m%%}%s%%{\x1b[m\x1b[0m%%}"
a.escapeLeft = "%{"
a.escapeRight = "%}"
a.hyperlink = "%%{\x1b]8;;%s\x1b\\%%}%s%%{\x1b]8;;\x1b\\%%}"
a.osc99 = "%%{\x1b]9;9;%s\x1b7%%}"
a.osc99 = "%%{\x1b]9;9;%s\x1b\\%%}"
case bash:
a.linechange = "\\[\x1b[%d%s\\]"
a.left = "\\[\x1b[%dC\\]"
@ -53,14 +53,14 @@ func (a *ansiFormats) init(shell string) {
a.clearEOL = "\\[\x1b[K\\]"
a.saveCursorPosition = "\\[\x1b7\\]"
a.restoreCursorPosition = "\\[\x1b8\\]"
a.title = "\\[\033]0;%s\007\\]"
a.title = "\\[\x1b]0;%s\007\\]"
a.colorSingle = "\\[\x1b[%sm\\]%s\\[\x1b[0m\\]"
a.colorFull = "\\[\x1b[%sm\x1b[%sm\\]%s\\[\x1b[0m\\]"
a.colorTransparent = "\\[\x1b[%s;49m\x1b[7m\\]%s\\[\x1b[m\x1b[0m\\]"
a.escapeLeft = "\\["
a.escapeRight = "\\]"
a.hyperlink = "\\[\x1b]8;;%s\x1b\\\\\\]%s\\[\x1b]8;;\x1b\\\\\\]"
a.osc99 = "\\[\x1b]9;9;%s\x1b7\\]"
a.osc99 = "\\[\x1b]9;9;%s\x1b\\\\\\]"
default:
a.linechange = "\x1b[%d%s"
a.left = "\x1b[%dC"
@ -69,14 +69,14 @@ func (a *ansiFormats) init(shell string) {
a.clearEOL = "\x1b[K"
a.saveCursorPosition = "\x1b7"
a.restoreCursorPosition = "\x1b8"
a.title = "\033]0;%s\007"
a.title = "\x1b]0;%s\007"
a.colorSingle = "\x1b[%sm%s\x1b[0m"
a.colorFull = "\x1b[%sm\x1b[%sm%s\x1b[0m"
a.colorTransparent = "\x1b[%s;49m\x1b[7m%s\x1b[m\x1b[0m"
a.escapeLeft = ""
a.escapeRight = ""
a.hyperlink = "\x1b]8;;%s\x1b\\%s\x1b]8;;\x1b\\"
a.osc99 = "\x1b]9;9;%s\x1b7"
a.osc99 = "\x1b]9;9;%s\x1b\\"
}
}

View file

@ -163,7 +163,15 @@ func (e *engine) render() {
if e.settings.FinalSpace {
e.renderer.write(" ")
}
e.renderer.osc99(e.env.getcwd())
cwd := e.env.getcwd()
// temp to fix 3.89 issue and add wsl support
if e.env.isWsl() {
// transform path
cwd, _ = e.env.runCommand("wslpath", "-m", cwd)
}
e.renderer.osc99(cwd)
e.print()
}

View file

@ -63,6 +63,7 @@ type environmentInfo interface {
getWindowTitle(imageName, windowTitleRegex string) (string, error)
doGet(url string) ([]byte, error)
hasParentFilePath(path string) (fileInfo *fileInfo, err error)
isWsl() bool
}
type commandCache struct {

View file

@ -18,3 +18,11 @@ func (env *environment) homeDir() string {
func (env *environment) getWindowTitle(imageName, windowTitleRegex string) (string, error) {
return "", errors.New("not implemented")
}
func (env *environment) isWsl() bool {
// one way to check
// version := env.getFileContent("/proc/version")
// return strings.Contains(version, "microsoft")
// using env variable
return env.getenv("WSL_DISTRO_NAME") != ""
}

View file

@ -53,3 +53,7 @@ func (env *environment) homeDir() string {
func (env *environment) getWindowTitle(imageName, windowTitleRegex string) (string, error) {
return getWindowTitle(imageName, windowTitleRegex)
}
func (env *environment) isWsl() bool {
return false
}

View file

@ -132,6 +132,10 @@ func (env *MockedEnvironment) hasParentFilePath(path string) (*fileInfo, error)
return args.Get(0).(*fileInfo), args.Error(1)
}
func (env *MockedEnvironment) isWsl() bool {
return false
}
const (
homeBill = "/home/bill"
homeJan = "/usr/home/jan"