From 195c1a934d66fd56f757b1235cc957e244b1c3bd Mon Sep 17 00:00:00 2001 From: jan De Dobbeleer Date: Wed, 8 Feb 2023 20:40:50 +0100 Subject: [PATCH] fix(pwsh): clear ANSI after print resolves #65 --- src/ansi/ansi_writer.go | 7 +++++++ src/engine/engine.go | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ansi/ansi_writer.go b/src/ansi/ansi_writer.go index e9e303d2..e56603a6 100644 --- a/src/ansi/ansi_writer.go +++ b/src/ansi/ansi_writer.go @@ -232,6 +232,13 @@ func (w *Writer) ConsolePwd(pwdType, userName, hostName, pwd string) string { } } +func (w *Writer) ClearAfter() string { + if w.Plain { + return "" + } + return w.clearLine + w.clearBelow +} + func (w *Writer) FormatTitle(title string) string { title = w.trimAnsi(title) if w.Plain { diff --git a/src/engine/engine.go b/src/engine/engine.go index 5d9cb6a0..9829f75a 100644 --- a/src/engine/engine.go +++ b/src/engine/engine.go @@ -153,6 +153,15 @@ func (e *Engine) getTitleTemplateText() string { } func (e *Engine) renderBlock(block *Block, cancelNewline bool) { + defer func() { + // when in PowerShell, we need to clear the line after the prompt + // to avoid the background being printed on the next line + // when at the end of the buffer. + // See https://github.com/JanDeDobbeleer/oh-my-posh/issues/65 + if e.Env.Shell() == shell.PWSH || e.Env.Shell() == shell.PWSH5 { + e.write(e.Writer.ClearAfter()) + } + }() // when in bash, for rprompt blocks we need to write plain // and wrap in escaped mode or the prompt will not render correctly if e.Env.Shell() == shell.BASH && block.Type == RPrompt {