fix(tcsh): escape special characters correctly

This commit is contained in:
L. Yeung 2024-09-17 03:16:41 +08:00 committed by Jan De Dobbeleer
parent a8f246064e
commit c7793a5f29
2 changed files with 13 additions and 9 deletions

View file

@ -108,17 +108,19 @@ func (e *Engine) pwd() {
}
func (e *Engine) getNewline() string {
// WARP terminal will remove \n from the prompt, so we hack a newline in.
if e.Plain || e.Env.Flags().Debug {
return "\n"
}
// Warp terminal will remove a newline character ('\n') from the prompt, so we hack it in.
// For Elvish, we do this to prevent cutting off a right-aligned block.
if e.isWarp() || e.Env.Shell() == shell.ELVISH {
return terminal.LineBreak()
}
// TCSH needs a space before the LITERAL newline character or it will not render correctly
// don't ask why, it be like that sometimes.
// https://unix.stackexchange.com/questions/99101/properly-defining-a-multi-line-prompt-in-tcsh#comment1342462_322189
// To avoid improper translations in Tcsh, we use an invisible word joiner character (U+2060) to separate a newline from possible preceding escape sequences.
if e.Env.Shell() == shell.TCSH {
return ` \n`
return "\u2060\\n"
}
return "\n"

View file

@ -73,6 +73,9 @@ func GetFormats(shell string) *Formats {
ITermPromptMark: "%{$(iterm2_prompt_mark)%}",
ITermCurrentDir: "%%{\x1b]1337;CurrentDir=%s\x07%%}",
ITermRemoteHost: "%%{\x1b]1337;RemoteHost=%s@%s\x07%%}",
EscapeSequences: map[rune]string{
'%': "%%",
},
}
default:
formats = &Formats{
@ -98,10 +101,9 @@ func GetFormats(shell string) *Formats {
}
}
if shell == ZSH {
formats.EscapeSequences = map[rune]string{
'%': "%%",
}
if shell == TCSH {
formats.EscapeSequences['\\'] = `\\`
formats.EscapeSequences['!'] = `\!`
}
return formats