Console: toggle terminal echo based on presence of interactive child processes (dotnet/corefx#35621)
* Console: toggle terminal echo based on presence of interactive child processes
.NET applications echo characters during a Console.Read. By default,
Unix terminals echo characters as the user is typing them.
When a .NET Core application launches an interactive application (e.g. 'vi')
that application expects to find the terminal in an echoing state.
To make both work, corefx was disabling echo during Console.Read operations,
and turning it back on when the read is done.
This changes to echoing while there are interactive applications and not echoing
when there are none.
This means we no longer need to toggle echo off/on for each Console.Read.
And the terminal will no longer echo when there is no Console.Read going on.
* Make some tcsetattr operations non-blocking
* Fix order between changing console settings and SetExited
* Fix unbalanced lock/unlocks
* Cache notty
* Prefer configuring the terminal for Console over child processes
* Update comments
* Rename some 'console' to 'terminal'
* Only decrement when child is using terminal
* Rename ConfigureTerminalForConsole back to In/UninitializeConsoleBefore/AfterRead
* Move some code to original place
* Add some extra comments
* PR feedback
* typo
Commit migrated from https://github.com/dotnet/corefx/commit/
007571b90c3cc555cd30f3b467b87c22f9f665e0