Skip to content

Commit

Permalink
Fix the resize and only use escape sequences if it's running on Windo…
Browse files Browse the repository at this point in the history
…ws Terminal.
  • Loading branch information
BDisp committed Sep 1, 2023
1 parent bbe3ea9 commit 19181dc
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion Terminal.Gui/ConsoleDrivers/WindowsDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,46 @@ public WindowsDriver ()
Clipboard = new FakeDriver.FakeClipboard ();
}

_isWindowsTerminal = Environment.GetEnvironmentVariable ("WT_SESSION") != null;
_isWindowsTerminal = GetParentProcessName () == "WindowsTerminal";
}

private 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<ManagementBaseObject> ().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<ManagementBaseObject> ().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
}

public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
Expand Down

0 comments on commit 19181dc

Please sign in to comment.