-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
ReadConsoleInputStream demo #414
Conversation
The point of this is to make stream oriented work with VT sequences easier to do. This is the basis of my ongoing multiplexer project. |
I'm good with this, but I'd like at least one other person to look (we do a 2-other-eyes policy for our code, generally). @DHowett-MSFT, @adiviness, @zadjii-msft, can one of you three give it a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a demo that shows how we can have a stream-oriented view of characters from the console
while also listening to console events like mouse, menu, focus, buffer/viewport(1) resize events.
This has always been tricky to do because ReadConsoleW/A doesn't allow retrieving events.
Only ReadConsoleInputW/A returns events, but isn't stream-oriented. Using both doesn't work because
ReadConsoleW/A flushes the input queue, meaning calls to ReadConsoleInputW/A will wait forever.
I do this by deriving a new Stream class which wraps ReadConsoleInputW and accepts a provider/consumer implementation of BlockingCollection<Kernel32.INPUT_RECORD>. This allows asynchronous monitoring of console events while simultaneously streaming the character input. I also use Mark Gravell's great System.IO.Pipelines utility classes (2) and David Hall's excellent P/Invoke wrappers (3) to make this demo cleaner to read; both are pulled from NuGet.
(1) in versions of windows 10 prior to 1809, the buffer resize event only fires for enlarging
the viewport, as this would cause the buffer to be enlarged too. Now it fires even when
shrinking the viewport, which won't change the buffer size.
(2) https://github.com/mgravell/Pipelines.Sockets.Unofficial
https://www.nuget.org/packages/Pipelines.Sockets.Unofficial
(3) https://github.com/dahall/Vanara
https://www.nuget.org/packages/Vanara.Pinvoke.Kernel32
Oisin Grehan - 2019/4/21
https://twitter.com/oising
https://github.com/oising