Skip to content

fix(cli): restore terminal state after Ctrl+C in interactive commands#1407

Merged
Brooooooklyn merged 3 commits intomainfrom
claude/fix-issue-1143
Apr 17, 2026
Merged

fix(cli): restore terminal state after Ctrl+C in interactive commands#1407
Brooooooklyn merged 3 commits intomainfrom
claude/fix-issue-1143

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 17, 2026

When interrupting vp dev or vp preview with Ctrl+C on Unix terminals (particularly macOS/Ghostty), escape sequences appeared in the shell prompt. This occurred because Vite sets the terminal to raw mode for interactive features, and when SIGINT interrupted the child process, the terminal state wasn't restored before the parent exited.

Changes

  • crates/vite_command/src/lib.rs:

    • Added TerminalStateGuard RAII guard that saves terminal attributes via tcgetattr() on creation and restores via tcsetattr() on drop
    • Added execute_with_terminal_guard() wrapper function that applies the guard during command execution
    • Guard only activates when stdin is a TTY, safely ignoring pipes/redirects
  • packages/cli/binding/src/cli/execution.rs:

    • Modified resolve_and_execute() to detect interactive commands (Dev, Preview)
    • Routes interactive commands through terminal guard wrapper
    • Non-interactive commands use standard execution path unchanged
  • crates/vite_command/Cargo.toml:

    • Added "term" feature to nix dependency for terminal state APIs

Implementation

// Terminal state saved before spawning child
let _guard = TerminalStateGuard::save(STDIN_FILENO);

// Child runs with inherited stdio
let mut child = cmd.spawn()?;
child.wait().await?

// Guard's Drop impl automatically restores terminal on exit,
// even if interrupted by signal

The fix follows the same RAII pattern used in vite_shared/src/header.rs for raw mode management and only impacts interactive dev servers where terminal corruption can occur.

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 17, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit a751318
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/69e1f6ceeab5ea0008954bfd

@Brooooooklyn
Copy link
Copy Markdown
Member

@claude[agent]
CleanShot 2026-04-17 at 16 07 32@2x
CleanShot 2026-04-17 at 16 08 02@2x

- Make cmd mutable in execution.rs to allow spawning child process
- Move #[cfg(unix)] import to top of file for proper formatting

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
@Brooooooklyn Brooooooklyn marked this pull request as ready for review April 17, 2026 09:00
@Brooooooklyn Brooooooklyn merged commit 2e2c4c6 into main Apr 17, 2026
36 checks passed
@Brooooooklyn Brooooooklyn deleted the claude/fix-issue-1143 branch April 17, 2026 09:26
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.

2 participants