From a25f1d949ddf0a0fc05b987dc7599cc77a56c77f Mon Sep 17 00:00:00 2001 From: Eric Wheeler Date: Tue, 11 Mar 2025 20:53:41 -0700 Subject: [PATCH] fix: add PowerShell-specific command handling PowerShell requires special handling for command output due to two issues: - A sleep delay is required to prevent the ]633;D marker from losing the original output - A counter is needed to work around a bug where identical commands are not executed Changes: - Add cmdCounter to Terminal class for unique command tracking - Add PowerShell detection via platform and default shell profile - Add sleep delay to ensure output is captured before command completion Signed-off-by: Eric Wheeler --- src/integrations/terminal/Terminal.ts | 1 + src/integrations/terminal/TerminalProcess.ts | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/integrations/terminal/Terminal.ts b/src/integrations/terminal/Terminal.ts index e768d79397..531300aab9 100644 --- a/src/integrations/terminal/Terminal.ts +++ b/src/integrations/terminal/Terminal.ts @@ -11,6 +11,7 @@ export class Terminal { private streamClosed: boolean public process?: TerminalProcess public taskId?: string + public cmdCounter: number = 0 public completedProcesses: TerminalProcess[] = [] private initialCwd: string diff --git a/src/integrations/terminal/TerminalProcess.ts b/src/integrations/terminal/TerminalProcess.ts index c5e1c901b5..468bfebabb 100644 --- a/src/integrations/terminal/TerminalProcess.ts +++ b/src/integrations/terminal/TerminalProcess.ts @@ -276,7 +276,20 @@ export class TerminalProcess extends EventEmitter { }) // Execute command - terminal.shellIntegration.executeCommand(command) + const defaultWindowsShellProfile = vscode.workspace + .getConfiguration("terminal.integrated.defaultProfile") + .get("windows") + const isPowerShell = + process.platform === "win32" && + (defaultWindowsShellProfile === null || + (defaultWindowsShellProfile as string)?.toLowerCase().includes("powershell")) + if (isPowerShell) { + terminal.shellIntegration.executeCommand( + `${command} ; ${this.terminalInfo.cmdCounter++} > $null; start-sleep -milliseconds 150`, + ) + } else { + terminal.shellIntegration.executeCommand(command) + } this.isHot = true // Wait for stream to be available