Re-enable VT mode on Windows after running command in ConsoleHost (#14413)

This commit is contained in:
Steve Lee
2021-03-09 16:02:16 -08:00
committed by GitHub
parent 727785cd10
commit cbd97d0cab
2 changed files with 18 additions and 4 deletions
@@ -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;
@@ -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
}
/// <summary>