Browse Source

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 <[email protected]>
Eric Wheeler 11 months ago
parent
commit
a25f1d949d

+ 1 - 0
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
 

+ 14 - 1
src/integrations/terminal/TerminalProcess.ts

@@ -276,7 +276,20 @@ export class TerminalProcess extends EventEmitter<TerminalProcessEvents> {
 			})
 
 			// 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