Skip to content

Commit 078a2b3

Browse files
authored
Fix rendering when continuation prompt is an empty string (PowerShell#2875)
1 parent 118b9e5 commit 078a2b3

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

PSReadLine/Render.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ void RenderOneChar(char charToRender, bool toEmphasize)
205205
// the previous rendering string.
206206
activeColor = string.Empty;
207207

208-
UpdateColorsIfNecessary(Options._continuationPromptColor);
209-
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
208+
if (Options.ContinuationPrompt.Length > 0)
209+
{
210+
UpdateColorsIfNecessary(Options._continuationPromptColor);
211+
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
212+
}
210213

211214
if (inSelectedRegion)
212215
{
@@ -465,6 +468,13 @@ private bool RenderErrorPrompt(RenderData renderData, string defaultColor)
465468
/// </summary>
466469
private int PhysicalLineCount(int columns, bool isFirstLogicalLine, out int lenLastPhysicalLine)
467470
{
471+
if (columns == 0)
472+
{
473+
// This could happen for a new logical line with an empty-string continuation prompt.
474+
lenLastPhysicalLine = 0;
475+
return 1;
476+
}
477+
468478
int cnt = 1;
469479
int bufferWidth = _console.BufferWidth;
470480

test/RenderTest.cs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,65 @@ public void MultiLine()
203203
_.Enter, CheckThat(() => AssertCursorLeftTopIs(0, 2))));
204204
}
205205

206+
[SkippableFact]
207+
public void MultiLine_ScreenCheck()
208+
{
209+
TestSetup(KeyMode.Cmd);
210+
211+
var defaultContinuationPrompt = PSConsoleReadLineOptions.DefaultContinuationPrompt;
212+
var defaultContinuationPromptColors = Tuple.Create(_console.ForegroundColor, _console.BackgroundColor);
213+
214+
Test("@'\n\n hello\n\n world\n'@",
215+
Keys(
216+
"@'", _.Enter, _.Enter,
217+
" hello", _.Enter, _.Enter,
218+
" world", _.Enter, "'@",
219+
CheckThat(() => AssertScreenIs(6,
220+
TokenClassification.String, "@'",
221+
NextLine,
222+
defaultContinuationPromptColors, defaultContinuationPrompt,
223+
NextLine,
224+
defaultContinuationPromptColors, defaultContinuationPrompt,
225+
TokenClassification.String, " hello",
226+
NextLine,
227+
defaultContinuationPromptColors, defaultContinuationPrompt,
228+
NextLine,
229+
defaultContinuationPromptColors, defaultContinuationPrompt,
230+
TokenClassification.String, " world",
231+
NextLine,
232+
defaultContinuationPromptColors, defaultContinuationPrompt,
233+
TokenClassification.String, "'@"))
234+
));
235+
236+
string emptyLine = new string(' ', _console.BufferWidth);
237+
// Set the continuation prompt to be an empty string.
238+
var setOption = new SetPSReadLineOption { ContinuationPrompt = string.Empty };
239+
PSConsoleReadLine.SetOptions(setOption);
240+
241+
try
242+
{
243+
Test("@'\n\n hello\n\n world\n'@",
244+
Keys(
245+
"@'", _.Enter, _.Enter,
246+
" hello", _.Enter, _.Enter,
247+
" world", _.Enter, "'@",
248+
CheckThat(() => AssertScreenIs(6,
249+
TokenClassification.String, "@'", NextLine,
250+
TokenClassification.None, emptyLine,
251+
TokenClassification.String, " hello", NextLine,
252+
TokenClassification.None, emptyLine,
253+
TokenClassification.String, " world", NextLine,
254+
TokenClassification.String, "'@"))
255+
));
256+
}
257+
finally
258+
{
259+
// Restore to the default continuation prompt.
260+
setOption.ContinuationPrompt = defaultContinuationPrompt;
261+
PSConsoleReadLine.SetOptions(setOption);
262+
}
263+
}
264+
206265
[SkippableFact]
207266
public void LongLine()
208267
{

0 commit comments

Comments
 (0)