terminal/samples/ReadConsoleInputStream
pi1024e ff23be04fb
Optimize booleans (#6548)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Many places in this codebase has an equality comparison to the boolean FALSE. This adds unneeded complexity as C and C++ has a NOT operand for use of these in if statements. This makes the code more readable in those areas.

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> 
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [X] Tests added/passed
* [ ] Requires documentation to be updated
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments
One boolean being compared to FALSE was only used once, with the boolean name being "b", so it is better off not existing at all.

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Unit Testing passed, compiler refactoring
2020-06-22 21:51:34 +00:00
..
ConcurrentBoundedQueue.cs moved readconsoleinputstream to samples folder; added readme; updated root readme. 2019-04-29 14:50:38 -04:00
NativeMethods.cs moved readconsoleinputstream to samples folder; added readme; updated root readme. 2019-04-29 14:50:38 -04:00
Program.cs moved readconsoleinputstream to samples folder; added readme; updated root readme. 2019-04-29 14:50:38 -04:00
README.md Grammar fixes/improvements (#511) 2019-05-07 08:30:01 -07:00
ReadConsoleInputStream.cs Optimize booleans (#6548) 2020-06-22 21:51:34 +00:00
ReadConsoleInputStreamDemo.csproj moved readconsoleinputstream to samples folder; added readme; updated root readme. 2019-04-29 14:50:38 -04:00
ReadConsoleInputStreamDemo.sln moved readconsoleinputstream to samples folder; added readme; updated root readme. 2019-04-29 14:50:38 -04:00

README.md

ReadConsoleInputStream Demo

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 resize events. This is particularly useful when working with VT100 streams and ConPTY.

This has always been difficult to do because ReadConsoleW/A doesn't allow retrieving events. Only ReadConsoleInputW/A returns events, but is not stream-oriented. Using both does not work because ReadConsoleW/A flushes the input queue, meaning calls to ReadConsoleInputW/A will wait forever.

A workaround has been achieved 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. Mark Gravell's great System.IO.Pipelines utility classes and David Hall's excellent P/Invoke wrappers are also used to make this demo cleaner to read; both are pulled from NuGet.

Note:

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.

NuGet packages used (GitHub links):