spectre.console
spectre.console copied to clipboard
Detect non-interactive console via Console.IsInputRedirected instead of Environment.UserInteractive
Environment.UserInteractive is false for SSH sessions on Windows, even though they are interactive. Detecting non-interactive sessions via redirected stdin instead seems more robust.
@bastianeicher Could you rebase this PR against the main branch?
Sure thing. :) Rebased.
@bastianeicher The code in this PR does not compile.
The type or namespace name 'IsInputRedirected' does not exist in the namespace 'Spectre.Console'
I was thinking, perhaps it would be better adding an SSH enriched, and checking whether or not SSH_CLIENT, SSH_CONNECTION or SSH_TTY environment variables are defined.
@bastianeicher The code in this PR does not compile.
Sorry about that. It did compile before the rebase but I didn't check it after. Fixed by replacing Console with System.Console.
I was thinking, perhaps it would be better adding an SSH enriched, and checking whether or not
SSH_CLIENT,SSH_CONNECTIONorSSH_TTYenvironment variables are defined.
SSH on Windows is not the only case where Environment.UserInteractive doesn't return a reliable value. For example, on non-Windows platforms the value is simply hardcoded to true. So I still think checking System.Console.IsInputRedirected here is a better option.