Skip to content

Clear terminal input buffer before sending Aspire commands#15863

Open
adamint wants to merge 2 commits intomicrosoft:mainfrom
adamint:fix/15587-clear-terminal-buffer-before-command
Open

Clear terminal input buffer before sending Aspire commands#15863
adamint wants to merge 2 commits intomicrosoft:mainfrom
adamint:fix/15587-clear-terminal-buffer-before-command

Conversation

@adamint
Copy link
Copy Markdown
Member

@adamint adamint commented Apr 3, 2026

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:

  • Unix (bash/zsh): Ctrl+U (\x15) — clears the current input line
  • Windows (PowerShell): Escape (\x1b) — clears the current input line

Fixes #15587

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

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.
Copilot AI review requested due to automatic review settings April 3, 2026 22:05
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15863

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15863"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VS Code Extension restart doesnt' work if terminal has pre-existing text

3 participants