From 776044b7167e2a07fdf4e1216c89d108d61fe5c3 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Fri, 16 Feb 2024 01:18:12 -0700 Subject: [PATCH] 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. --- .../ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs | 42 +------------------ UnitTests/Input/EscSeqUtilsTests.cs | 13 ------ 2 files changed, 1 insertion(+), 54 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs b/Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs index 403a42545..6181e32ec 100644 --- a/Terminal.Gui/ConsoleDrivers/EscSeqUtils/EscSeqUtils.cs +++ b/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; /// /// 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. - /// - /// Get the terminal that holds the console driver. - /// - /// The process. - /// If supported the executable console process, null otherwise. - 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; - } - /// /// Ensures a console key is mapped to one that works correctly with ANSI escape sequences. /// diff --git a/UnitTests/Input/EscSeqUtilsTests.cs b/UnitTests/Input/EscSeqUtilsTests.cs index 3d5e460dd..c8838b750 100644 --- a/UnitTests/Input/EscSeqUtilsTests.cs +++ b/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 () {