From e75cff662ab7295abb3b1e89ef45f045ecabcaa1 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 25 May 2017 17:26:39 -0700 Subject: [PATCH] Make PSReadline render correct portion of prompt on Unix when it's a multi-line string (#3867) Check whether the prompt is multi-line or not. If it is, then only use the part that is shown in the input line. --- src/Microsoft.PowerShell.PSReadLine/ReadLine.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs index d221d698d..0282d7784 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ReadLine.cs @@ -560,6 +560,13 @@ namespace Microsoft.PowerShell #if UNIX // TODO: not necessary if ReadBufferLines worked, or if rendering worked on spans instead of complete lines string newPrompt = GetPrompt(); + int index = newPrompt.LastIndexOf('\n'); + if (index != -1) + { + // The prompt text could be a multi-line string, and in such case + // we only want the part of it that is shown on the input line. + newPrompt = newPrompt.Substring(index + 1); + } var bufferLineCount = (newPrompt.Length) / (_console.BufferWidth) + 1; _consoleBuffer = ReadBufferLines(_initialY, bufferLineCount);