shibayan / Sharprompt

Interactive command-line based application framework for C#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArgumentOutOfRangeException when input exceeds console buffer

kimsey0 opened this issue · comments

When using Prompt.Input, if the user continues typing when the cursor reaches the last column of the last line in the buffer, Sharprompt crashes with:

Unhandled 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 'top')
Actual value was 9001.
   at System.ConsolePal.SetCursorPosition(Int32 left, Int32 top)
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Sharprompt.Drivers.DefaultConsoleDriver.SetCursorPosition(Int32 left, Int32 top)
   at Sharprompt.Internal.OffscreenBuffer.RenderToConsole()
   at Sharprompt.Internal.RenderScope.Dispose()
   at Sharprompt.Forms.FormRenderer.Render(Action`1 template)
   at Sharprompt.Forms.FormBase`1.Start()
   at Sharprompt.Prompt.Input[T](InputOptions`1 options)
   at Sharprompt.Prompt.Input[T](Action`1 configure)
   at Sharprompt.Prompt.Input[T](String message, Object defaultValue, String placeholder, IList`1 validators)
   at Program.<Main>$(String[] args) in C:\Projects\CommandLineCrash\Program.cs:line 6

A minimal program reproducing this problem:

for (var i = 0; i < Console.BufferHeight; i++)
{
    Console.WriteLine();
}

Sharprompt.Prompt.Input<string>("Type any character".PadRight(Console.BufferWidth - 5));

I can reproduce the problem in the Windows Console and in Windows Terminal running either cmd.exe or PowerShell, but not in any of them when running bash through WSL 2.

(If you paste a text snippet that is long enough to exceed the available space on the last line, this does not trigger the crash. Instead, it properly continues the prompt input on the next line, but still crashes if you then continue writing and reach the end of that new line.)

It is a renderer issue and will take time but will be fundamentally fixed.

Thanks!