Clear terminal input buffer before sending Aspire commands#15863
Clear terminal input buffer before sending Aspire commands#15863adamint wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Fixes microsoft#15587. When the user has pre-existing text in the Aspire terminal input buffer, stop/restart/start commands get appended to it, making the resulting command invalid. Send a line-clearing control sequence (Ctrl+U on Unix, Escape on Windows) before each command to discard any buffered input.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15863Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15863" |
There was a problem hiding this comment.
Pull request overview
Fixes invalid Aspire CLI commands being appended to pre-existing text in the Aspire VS Code terminal by clearing the terminal input buffer before sending Stop/Restart/Start (and other) commands.
Changes:
- Clears any pre-existing input line content before sending an Aspire CLI command to the integrated terminal.
- Uses a platform-specific control sequence (Unix: Ctrl+U, Windows: Escape) prior to
sendText(command).
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
JamesNK
left a comment
There was a problem hiding this comment.
1 comment: potential platform gap with Ctrl+U on Windows PowerShell.
| extensionLogOutputChannel.info(`Sending command to Aspire terminal: ${command}`); | ||
|
|
||
| // Clear any pre-existing text in the terminal input buffer before sending the command. | ||
| // Use Ctrl+U to clear the current line without sending an ESC prefix that can alter |
There was a problem hiding this comment.
\x15 (Ctrl+U) is bound to UnixLineDiscard in PSReadLine's Emacs edit mode (default on Linux/macOS), but is not bound in PSReadLine's Windows edit mode (the default on Windows). Since the extension creates a terminal with no explicit shellPath, Windows users get their default shell — typically PowerShell in Windows edit mode.
This means:
- Unix/macOS (bash/zsh): Fix works as intended — Ctrl+U clears the line.
- Windows (PowerShell, default settings):
\x15is likely silently ignored by PSReadLine, so the original bug (VS Code Extension restart doesnt' work if terminal has pre-existing text #15587) may persist for Windows users.
Consider either: (a) adding a platform-specific branch (e.g., Escape (\x1b) works in PSReadLine's Windows mode to cancel/clear the line, and you could use process.platform === 'win32' to select), or (b) documenting this as a Unix-focused fix with Windows as a follow-up.
Description
When the Aspire terminal has pre-existing text in its input buffer (e.g., a partially typed command), clicking Stop, Restart, or Start on a code lens or tree view appends the Aspire CLI command to the existing text, producing an invalid command that fails.
This fix sends a line-clearing control sequence before each command:
Ctrl+U(\x15) — clears the current input lineEscape(\x1b) — clears the current input lineFixes #15587
Checklist
<remarks />and<code />elements on your triple slash comments?aspire.devissue: