Console: toggle terminal echo based on presence of interactive child processes (dotne...
authorTom Deseyn <tom.deseyn@gmail.com>
Sun, 31 Mar 2019 00:28:18 +0000 (01:28 +0100)
committerStephen Toub <stoub@microsoft.com>
Sun, 31 Mar 2019 00:28:18 +0000 (20:28 -0400)
commit294bb5b10419ccf5ce2810f0fe1af7ce771aecf5
tree7fc46991ea757ccf8e6bb68955eaac34e5455817
parent2971af39fa34c0f6eb8d42a9336f44dfb0376b96
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
13 files changed:
src/libraries/Common/src/Interop/Unix/System.Native/Interop.ConfigureTerminalForChildProcess.cs [new file with mode: 0644]
src/libraries/Common/src/Interop/Unix/System.Native/Interop.InitializeTerminalAndSignalHandling.cs [moved from src/libraries/Common/src/Interop/Unix/System.Native/Interop.InitializeConsole.cs with 79% similarity]
src/libraries/Common/src/Interop/Unix/System.Native/Interop.RegisterForSigChld.cs
src/libraries/Native/Unix/System.Native/pal_console.c
src/libraries/Native/Unix/System.Native/pal_console.h
src/libraries/Native/Unix/System.Native/pal_signal.c
src/libraries/Native/Unix/System.Native/pal_signal.h
src/libraries/System.Console/src/System.Console.csproj
src/libraries/System.Console/src/System/ConsolePal.Unix.cs
src/libraries/System.Console/src/System/IO/StdInReader.cs
src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs