Skip to content

Moving cursor to end of buffer causes exception #1144

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

Closed
msftrncs opened this issue Nov 2, 2019 · 0 comments · Fixed by #1146
Closed

Moving cursor to end of buffer causes exception #1144

msftrncs opened this issue Nov 2, 2019 · 0 comments · Fixed by #1146

Comments

@msftrncs
Copy link
Collaborator

msftrncs commented Nov 2, 2019

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.

msftrncs added a commit to msftrncs/PSReadLine that referenced this issue Nov 2, 2019
Handle when `MoveCursor()` attempts to move the cursor to the end of the
terminal buffer, same as `Render()`, by issueing a line feed to force a
scroll.

Fixes PowerShell#1144.
msftrncs added a commit to msftrncs/PSReadLine that referenced this issue Nov 8, 2019
Handle when `MoveCursor()` attempts to move the cursor to the end of the
terminal buffer, same as `Render()`, by issueing a line feed to force a
scroll.

Fixes PowerShell#1144.
msftrncs added a commit to msftrncs/PSReadLine that referenced this issue Nov 8, 2019
Handle when `MoveCursor()` attempts to move the cursor to the end of the
terminal buffer, same as `Render()`, by issueing a line feed to force a
scroll.

Fixes PowerShell#1144.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant