System.InvalidOperationException: 'Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
#80.695 aperta il 16 gen 2023
Metriche repository
- Star
- (17.886 star)
- Metriche merge PR
- (Merge medio 12g 11h) (661 PR mergiate in 30 g)
Descrizione
Description
I'm having the follow error when I resize the console height to zero or almost zero and pointing the mouse to the available console space:
System.InvalidOperationException: 'Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.'
This is happening on Windows and WSL using cmd, pwsh and conhost. As I'm reading escape sequences from Console.ReadKey (true) in a console with a height equal to zero causes the System.Console.dll crash. The problem is I can't force resizing the console. Do I still need to using for Windows the Win32 API Console by enabling ENABLE_VIRTUAL_TERMINAL_PROCESSING to be able to use escape sequences or does System.Console allows that feature? Another question is many escape sequences request are not available in Windows and WSL, is there any configuration I can use or is a limitation?
Reproduction Steps
To test this issue please clone the https://github.com/gui-cs/Terminal.Gui repo and run the UICatalog project with the argument -usc, which will use the NetDriver using the System.Console. Thanks.
Expected behavior
I expected the console doesn't crash if height is equal or almost equal to zero. With almost zero I mean when the height is less than one and greater than zero. If it can't read with this size then it must check first for its size and not try to read any keystroke or mouse movements.
Actual behavior
The console really crash and disappear from the desktop, causing the errors already mentioned and others like pipe error.
Regression?
No response
Known Workarounds
No response
Configuration
Net6.0, Net7.0 OS: Windows 11 Pro Version: 22H2 Compilation: 22621.1105 Architecture: x64
Other information
No response