From 57e59688cb94ad182cf9505ccd4c96e51b668eec Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Sun, 18 Oct 2020 23:18:21 +0200 Subject: [PATCH 1/6] Fail gracefully if in remote session --- .../OutConsoleGridviewCmdletCommand.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 3f8a623..d00ef01 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Management.Automation; using System.Management.Automation.Internal; +using System.Management.Automation.Remoting; using OutGridView.Models; namespace OutGridView.Cmdlet @@ -57,6 +58,17 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing protected override void BeginProcessing() { + if (GetVariableValue("PSSenderInfo") is PSSenderInfo) + { + ErrorRecord error = new ErrorRecord( + new PSNotSupportedException("Not supported in remote sessions."), + EnvironmentNotSupportedForGridView, + ErrorCategory.NotImplemented, + null); + + ThrowTerminatingError(error); + } + if (Console.IsInputRedirected) { ErrorRecord error = new ErrorRecord( @@ -151,7 +163,10 @@ protected override void EndProcessing() public void Dispose() { - _consoleGui.Dispose(); + if (GetVariableValue("PSSenderInfo") is null) + { + _consoleGui.Dispose(); + } } } } From 910ca5842d134dd3f77ce84fc116eeeeefd60e13 Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Mon, 19 Oct 2020 08:29:59 +0200 Subject: [PATCH 2/6] Revert "Fail gracefully if in remote session" This reverts commit 57e59688cb94ad182cf9505ccd4c96e51b668eec. --- .../OutConsoleGridviewCmdletCommand.cs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index d00ef01..3f8a623 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Management.Automation; using System.Management.Automation.Internal; -using System.Management.Automation.Remoting; using OutGridView.Models; namespace OutGridView.Cmdlet @@ -58,17 +57,6 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable // This method gets called once for each cmdlet in the pipeline when the pipeline starts executing protected override void BeginProcessing() { - if (GetVariableValue("PSSenderInfo") is PSSenderInfo) - { - ErrorRecord error = new ErrorRecord( - new PSNotSupportedException("Not supported in remote sessions."), - EnvironmentNotSupportedForGridView, - ErrorCategory.NotImplemented, - null); - - ThrowTerminatingError(error); - } - if (Console.IsInputRedirected) { ErrorRecord error = new ErrorRecord( @@ -163,10 +151,7 @@ protected override void EndProcessing() public void Dispose() { - if (GetVariableValue("PSSenderInfo") is null) - { - _consoleGui.Dispose(); - } + _consoleGui.Dispose(); } } } From 6bdb9d5eace2c9112179b86f195c77024cb2d4f5 Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Mon, 19 Oct 2020 08:41:37 +0200 Subject: [PATCH 3/6] Prevent unexpected exit from remote session --- .../OutConsoleGridviewCmdletCommand.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 3f8a623..50840f7 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -151,7 +151,11 @@ protected override void EndProcessing() public void Dispose() { - _consoleGui.Dispose(); + // Only call Dispose when not in a remote session + if (Console.IsInputRedirected == false) + { + _consoleGui.Dispose(); + } } } } From d755c6d93e0e0cc04d077bb4dbfa2a8afd0b5eec Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:54:34 +0200 Subject: [PATCH 4/6] Revert "Prevent unexpected exit from remote session" This reverts commit 6bdb9d5eace2c9112179b86f195c77024cb2d4f5. --- .../OutConsoleGridviewCmdletCommand.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 50840f7..3f8a623 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -151,11 +151,7 @@ protected override void EndProcessing() public void Dispose() { - // Only call Dispose when not in a remote session - if (Console.IsInputRedirected == false) - { - _consoleGui.Dispose(); - } + _consoleGui.Dispose(); } } } From e3ea9197f2976778b4bcc01a8a5132c0b329be02 Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:58:35 +0200 Subject: [PATCH 5/6] Prevent unexpected exit from remote session Do not set cursor key to application mode if cmdlet is in remote session --- .../ConsoleGui.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index 00be36f..4ac506d 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -320,11 +320,14 @@ private void AddRows(Window win) public void Dispose() { - // By emitting this, we fix an issue where arrow keys don't work in the console - // because .NET requires application mode to support Arrow key escape sequences - // Esc[?1h - Set cursor key to application mode - // See http://ascii-table.com/ansi-escape-sequences-vt-100.php - Console.Write("\u001b[?1h"); + if (Console.IsInputRedirected == false) + { + // By emitting this, we fix an issue where arrow keys don't work in the console + // because .NET requires application mode to support Arrow key escape sequences + // Esc[?1h - Set cursor key to application mode + // See http://ascii-table.com/ansi-escape-sequences-vt-100.php + Console.Write("\u001b[?1h"); + } } } } From c6fc8da274f7d97a0677c2645bad4ab64f7e905c Mon Sep 17 00:00:00 2001 From: lahell <47929663+lahell@users.noreply.github.com> Date: Tue, 20 Oct 2020 07:46:01 +0200 Subject: [PATCH 6/6] Update src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs Co-authored-by: Tyler James Leonhardt --- src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index 4ac506d..a78f573 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -320,7 +320,7 @@ private void AddRows(Window win) public void Dispose() { - if (Console.IsInputRedirected == false) + if (!Console.IsInputRedirected) { // By emitting this, we fix an issue where arrow keys don't work in the console // because .NET requires application mode to support Arrow key escape sequences