Skip to content
Merged
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
30 changes: 24 additions & 6 deletions PSReadLine/Render.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,12 @@ int PhysicalLineCount(int columns, bool isFirstLogicalLine, out int lenLastPhysi
{
// We're in the middle of a previous logical line, we
// need to clear to the end of the line.
lenToClear = bufferWidth - (lenLastLine % bufferWidth);
if (physicalLine == 1)
lenToClear -= _initialX;
if (lenLastLine < bufferWidth)
{
lenToClear = bufferWidth - (lenLastLine % bufferWidth);
if (physicalLine == 1)
lenToClear -= _initialX;
}
}

if (lenToClear > 0)
Expand All @@ -486,7 +489,8 @@ int PhysicalLineCount(int columns, bool isFirstLogicalLine, out int lenLastPhysi

while (previousPhysicalLine > physicalLine)
{
_console.Write("\n");
_console.SetCursorPosition(0, _initialY + physicalLine);

physicalLine += 1;
var lenToClear = physicalLine == previousPhysicalLine ? lenPrevLastLine : bufferWidth;
if (lenToClear > 0)
Expand All @@ -507,13 +511,27 @@ int PhysicalLineCount(int columns, bool isFirstLogicalLine, out int lenLastPhysi
// Reset the colors after we've finished all our rendering.
_console.Write("\x1b[0m");

if (_initialY + physicalLine >= _console.BufferHeight)
if (_initialY + physicalLine > bufferHeight)
{
// We had to scroll to render everything, update _initialY
_initialY = _console.BufferHeight - physicalLine;
_initialY = bufferHeight - physicalLine;
}

// Calculate the coord to place the cursor for the next input.
var point = ConvertOffsetToPoint(_current);

if (point.Y == bufferHeight)
{
// The cursor top exceeds the buffer height, so we need to
// scroll up the buffer by 1 line.
_console.Write("\n");

// Adjust the initial cursor position and the to-be-set cursor position
// after scrolling up the buffer.
_initialY -= 1;
point.Y -= 1;
}

_console.SetCursorPosition(point.X, point.Y);
_console.CursorVisible = true;

Expand Down