Skip to content

Fix rendering when continuation prompt is an empty string #2875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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