Skip to content

Commit

Permalink
Fix rendering when continuation prompt is an empty string (#2875)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw authored Sep 20, 2021
1 parent 118b9e5 commit 078a2b3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
14 changes: 12 additions & 2 deletions PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,11 @@ void RenderOneChar(char charToRender, bool toEmphasize)
// the previous rendering string.
activeColor = string.Empty;

UpdateColorsIfNecessary(Options._continuationPromptColor);
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
if (Options.ContinuationPrompt.Length > 0)
{
UpdateColorsIfNecessary(Options._continuationPromptColor);
_consoleBufferLines[currentLogicalLine].Append(Options.ContinuationPrompt);
}

if (inSelectedRegion)
{
Expand Down Expand Up @@ -465,6 +468,13 @@ private bool RenderErrorPrompt(RenderData renderData, string defaultColor)
/// </summary>
private int PhysicalLineCount(int columns, bool isFirstLogicalLine, out int lenLastPhysicalLine)
{
if (columns == 0)
{
// This could happen for a new logical line with an empty-string continuation prompt.
lenLastPhysicalLine = 0;
return 1;
}

int cnt = 1;
int bufferWidth = _console.BufferWidth;

Expand Down
59 changes: 59 additions & 0 deletions test/RenderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,65 @@ public void MultiLine()
_.Enter, CheckThat(() => AssertCursorLeftTopIs(0, 2))));
}

[SkippableFact]
public void MultiLine_ScreenCheck()
{
TestSetup(KeyMode.Cmd);

var defaultContinuationPrompt = PSConsoleReadLineOptions.DefaultContinuationPrompt;
var defaultContinuationPromptColors = Tuple.Create(_console.ForegroundColor, _console.BackgroundColor);

Test("@'\n\n hello\n\n world\n'@",
Keys(
"@'", _.Enter, _.Enter,
" hello", _.Enter, _.Enter,
" world", _.Enter, "'@",
CheckThat(() => AssertScreenIs(6,
TokenClassification.String, "@'",
NextLine,
defaultContinuationPromptColors, defaultContinuationPrompt,
NextLine,
defaultContinuationPromptColors, defaultContinuationPrompt,
TokenClassification.String, " hello",
NextLine,
defaultContinuationPromptColors, defaultContinuationPrompt,
NextLine,
defaultContinuationPromptColors, defaultContinuationPrompt,
TokenClassification.String, " world",
NextLine,
defaultContinuationPromptColors, defaultContinuationPrompt,
TokenClassification.String, "'@"))
));

string emptyLine = new string(' ', _console.BufferWidth);
// Set the continuation prompt to be an empty string.
var setOption = new SetPSReadLineOption { ContinuationPrompt = string.Empty };
PSConsoleReadLine.SetOptions(setOption);

try
{
Test("@'\n\n hello\n\n world\n'@",
Keys(
"@'", _.Enter, _.Enter,
" hello", _.Enter, _.Enter,
" world", _.Enter, "'@",
CheckThat(() => AssertScreenIs(6,
TokenClassification.String, "@'", NextLine,
TokenClassification.None, emptyLine,
TokenClassification.String, " hello", NextLine,
TokenClassification.None, emptyLine,
TokenClassification.String, " world", NextLine,
TokenClassification.String, "'@"))
));
}
finally
{
// Restore to the default continuation prompt.
setOption.ContinuationPrompt = defaultContinuationPrompt;
PSConsoleReadLine.SetOptions(setOption);
}
}

[SkippableFact]
public void LongLine()
{
Expand Down

0 comments on commit 078a2b3

Please sign in to comment.