diff --git a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs index b3a1061598..4d8d50c88a 100644 --- a/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/WindowsDriver.cs @@ -777,7 +777,7 @@ internal class WindowsDriver : ConsoleDriver { public WindowsConsole WinConsole { get; private set; } - public override bool SupportsTrueColor => _isWindowsTerminal && Environment.OSVersion.Version.Build >= 14931; + public override bool SupportsTrueColor => _runningUnitTests || (_isWindowsTerminal && Environment.OSVersion.Version.Build >= 14931); public override bool Force16Colors { get => base.Force16Colors; @@ -1452,7 +1452,11 @@ public override bool IsRuneSupported (Rune rune) public override void Init (Action terminalResized) { TerminalResized = terminalResized; - + + if (Environment.OSVersion.Platform == PlatformID.Unix) { + _runningUnitTests = true; + return; + } try { if (WinConsole != null) { var winSize = WinConsole.GetConsoleOutputWindow (out Point pos); @@ -1708,7 +1712,7 @@ public override void End () WinConsole?.Cleanup (); WinConsole = null; - if (_isWindowsTerminal) { + if (!_runningUnitTests && _isWindowsTerminal) { // Disable alternative screen buffer. Console.Out.Write (EscSeqUtils.CSI_RestoreAltBufferWithBackscroll); } @@ -1720,45 +1724,6 @@ public override void Suspend () throw new NotImplementedException (); } #endregion - - static string GetParentProcessName () - { -#pragma warning disable CA1416 // Validate platform compatibility - var myId = Process.GetCurrentProcess ().Id; - var query = string.Format ($"SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {myId}"); - var search = new ManagementObjectSearcher ("root\\CIMV2", query); - var queryObj = search.Get ().OfType ().FirstOrDefault (); - if (queryObj == null) { - return null; - } - var parentId = (uint)queryObj ["ParentProcessId"]; - var parent = Process.GetProcessById ((int)parentId); - var prevParent = parent; - - // Check if the parent is from other parent - while (queryObj != null) { - query = string.Format ($"SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = {parentId}"); - search = new ManagementObjectSearcher ("root\\CIMV2", query); - queryObj = search.Get ().OfType ().FirstOrDefault (); - if (queryObj == null) { - return parent.ProcessName; - } - parentId = (uint)queryObj ["ParentProcessId"]; - try { - parent = Process.GetProcessById ((int)parentId); - if (string.Equals (parent.ProcessName, "explorer", StringComparison.InvariantCultureIgnoreCase)) { - return prevParent.ProcessName; - } - prevParent = parent; - } catch (ArgumentException) { - - return prevParent.ProcessName; - } - } - - return parent.ProcessName; -#pragma warning restore CA1416 // Validate platform compatibility - } } /// diff --git a/testenvironments.json b/testenvironments.json index 898ac827de..9dbec7f4de 100644 --- a/testenvironments.json +++ b/testenvironments.json @@ -16,4 +16,5 @@ "wslDistribution": "Debian" } ] -} \ No newline at end of file +} + \ No newline at end of file