Skip to content

Moving cursor to end of buffer causes exception #1144

@msftrncs

Description

@msftrncs

Environment data

PS version: 5.1.19013.1
PSReadline version: 2.0.0-beta5
os: 10.0.19013.1 (WinBuild.160101.0800)
PS file version: 10.0.19013.1 (WinBuild.160101.0800)
HostName: ConsoleHost (Windows Terminal)
BufferWidth: 120
BufferHeight: 28

Steps to reproduce or exception report

Similar to #884, and is easiest in a limited buffer size terminal, such as the current Windows Terminal or VS Code's terminal, enter a long line of text on the last line of the buffer, but before filling it, arrow back one character, and then extend the line to the end of the buffer.

image

Then press END, and an exception will occur. I'm pretty sure it occurs because the desired cursor position is calculated to be the beginning of the next line, but that is beyond the end of the buffer, and no rendering event has occurred to be able to fix that.

Exception

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was 28.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.MoveCursor(Int32 newCursor)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

ReallyRender() handles landing in this position by forcing a newline, but MoveCursor() doesn't have any handling for that.

I was able to replicate this issue in ConsoleHost, if I filled up the 9000 line buffer first.

Interestingly, it appears that most these terminals support emitting text in to the last character of the last line without the cursor bumping up the lines. However, the SetCursorPosition, doesn't seem to allow moving the cursor in to this condition. Evidently VS Code's terminal does not support this (my error while testing), even though its a well known ANSI terminal feature from more than 20 years ago. It allows you to write the very last character cell on the screen without the screen scrolling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions