Browse Source

Remove this method and its test

It is unused
There's no guarantee at all that the parent process is the terminal.
There are good reasons, including that one, why there's no simple way to do it in .net.
It's also of course a windows-only thing, if using WMI.
Brandon Thetford 1 year ago
parent
commit
776044b716

+ 1 - 41
Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs

@@ -1,8 +1,4 @@
-using System.Diagnostics;
-using System.Management;
-using System.Runtime.InteropServices;
-
-namespace Terminal.Gui;
+namespace Terminal.Gui;
 
 /// <summary>
 ///     Provides a platform-independent API for managing ANSI escape sequences.
@@ -1019,42 +1015,6 @@ public static class EscSeqUtils
         //}
     }
 
-    // TODO: Move this out of here and into ConsoleDriver or somewhere else.
-    /// <summary>
-    ///     Get the terminal that holds the console driver.
-    /// </summary>
-    /// <param name="process">The process.</param>
-    /// <returns>If supported the executable console process, null otherwise.</returns>
-    public static Process GetParentProcess (Process process)
-    {
-        if (!RuntimeInformation.IsOSPlatform (OSPlatform.Windows))
-        {
-            return null;
-        }
-
-        string query = "SELECT ParentProcessId FROM Win32_Process WHERE ProcessId = " + process.Id;
-
-        using (var mos = new ManagementObjectSearcher (query))
-        {
-            foreach (ManagementObject mo in mos.Get ())
-            {
-                if (mo ["ParentProcessId"] is { })
-                {
-                    try
-                    {
-                        var id = Convert.ToInt32 (mo ["ParentProcessId"]);
-
-                        return Process.GetProcessById (id);
-                    }
-                    catch
-                    { }
-                }
-            }
-        }
-
-        return null;
-    }
-
     /// <summary>
     ///     Ensures a console key is mapped to one that works correctly with ANSI escape sequences.
     /// </summary>

+ 0 - 13
UnitTests/Input/EscSeqUtilsTests.cs

@@ -1142,19 +1142,6 @@ public class EscSeqUtilsTests
         Assert.Equal (new Point (1, 2), pos);
     }
 
-    [Fact]
-    public void GetParentProcess_Tests ()
-    {
-        if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows))
-        {
-            Assert.NotNull (EscSeqUtils.GetParentProcess (Process.GetCurrentProcess ()));
-        }
-        else
-        {
-            Assert.Null (EscSeqUtils.GetParentProcess (Process.GetCurrentProcess ()));
-        }
-    }
-
     [Fact]
     public void ResizeArray_ConsoleKeyInfo ()
     {