diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index 9de877ba46..660e677433 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -2430,6 +2430,14 @@ namespace Microsoft.PowerShell while (!_parent.ShouldEndSession && !_shouldExit) { +#if !UNIX + if (ui.SupportsVirtualTerminal) + { + // need to re-enable VT mode if it was previously enabled as native commands may have turned it off + ui.TryTurnOnVtMode(); + } +#endif + try { _parent._isRunningPromptLoop = true; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 142d514c49..14425da82c 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -60,9 +60,14 @@ namespace Microsoft.PowerShell _parent = parent; _rawui = new ConsoleHostRawUserInterface(this); + SupportsVirtualTerminal = TryTurnOnVtMode(); + _isInteractiveTestToolListening = false; + } + internal bool TryTurnOnVtMode() + { #if UNIX - SupportsVirtualTerminal = true; + return true; #else try { @@ -76,15 +81,16 @@ namespace Microsoft.PowerShell // We only know if vt100 is supported if the previous call actually set the new flag, older // systems ignore the setting. m = ConsoleControl.GetMode(handle); - this.SupportsVirtualTerminal = (m & ConsoleControl.ConsoleModes.VirtualTerminal) != 0; + return (m & ConsoleControl.ConsoleModes.VirtualTerminal) != 0; } } catch { + // Do nothing if failed } -#endif - _isInteractiveTestToolListening = false; + return false; +#endif } ///