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 <roo-code@z.ewheeler.org>
This commit is contained in:
Eric Wheeler 2025-03-11 20:53:41 -07:00
parent b73bc39c8d
commit a25f1d949d
2 changed files with 15 additions and 1 deletions

View file

@ -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

View file

@ -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