fix(bash): escape rprompt

resolves #3347
This commit is contained in:
Jan De Dobbeleer 2023-01-11 15:29:50 +01:00 committed by Jan De Dobbeleer
parent 502c346d9b
commit 9cd20f2764

View file

@ -159,7 +159,7 @@ func (e *Engine) renderBlock(block *Block) {
}() }()
// when in bash, for rprompt blocks we need to write plain // when in bash, for rprompt blocks we need to write plain
// and wrap in escaped mode or the prompt will not render correctly // and wrap in escaped mode or the prompt will not render correctly
if e.Env.Shell() == shell.BASH && (block.Type == RPrompt || block.Alignment == Right) { if e.Env.Shell() == shell.BASH && block.Type == RPrompt {
block.InitPlain(e.Env, e.Config) block.InitPlain(e.Env, e.Config)
} else { } else {
block.Init(e.Env, e.Writer) block.Init(e.Env, e.Writer)
@ -214,18 +214,10 @@ func (e *Engine) renderBlock(block *Block) {
e.write(text) e.write(text)
return return
} }
// this can contain ANSI escape sequences prompt := e.Writer.CarriageForward()
writer := e.Writer prompt += e.Writer.GetCursorForRightWrite(length, block.HorizontalOffset)
if e.Env.Shell() == shell.BASH {
writer.Init(shell.GENERIC)
}
prompt := writer.CarriageForward()
prompt += writer.GetCursorForRightWrite(length, block.HorizontalOffset)
prompt += text prompt += text
e.currentLineLength = 0 e.currentLineLength = 0
if e.Env.Shell() == shell.BASH {
prompt = e.Writer.FormatText(prompt)
}
e.write(prompt) e.write(prompt)
case RPrompt: case RPrompt:
e.rprompt, e.rpromptLength = block.RenderSegments() e.rprompt, e.rpromptLength = block.RenderSegments()