Skip to content

fix: reset Windows terminal on exit to prevent ANSI corruption - #20377

Closed
ToastyTheBot wants to merge 1 commit into
anomalyco:devfrom
ToastyTheBot:fix/issue-20224-windows-terminal-ansi
Closed

ToastyTheBot wants to merge 1 commit into
anomalyco:devfrom
ToastyTheBot:fix/issue-20224-windows-terminal-ansi

Conversation

@ToastyTheBot

Copy link
Copy Markdown

Add win32ResetTerminal function that properly resets the terminal state on Windows before exiting. This prevents raw ANSI escape sequences from being printed to the terminal when Node processes are killed.

Problem

On Windows PowerShell, when OpenCode exits or kills Node processes, the terminal becomes corrupted with raw ANSI escape sequences like being printed directly instead of being interpreted.

Solution

Added win32ResetTerminal() that:

  • Clears output buffers using kernel32.dll
  • Restores proper console modes with ENABLE_VIRTUAL_TERMINAL_PROCESSING
  • Clears screen and resets cursor position (\x1b[2J\x1b[H)
  • Resets SGR attributes (\x1b[0m)
  • Disables alternate screen buffer (\x1b[?1049l)

Called on exit in both TUI app and attach command.

Test plan

  • Verify terminal is not corrupted after exiting on Windows
  • Verify ANSI sequences are properly handled after restart

🤖 Generated with Claude Code

Add win32ResetTerminal function that properly resets the terminal state
on Windows before exiting. This prevents raw ANSI escape sequences from
being printed to the terminal when Node processes are killed.

Changes:
- Added win32ResetTerminal() that clears output buffers and restores
  proper console modes with ENABLE_VIRTUAL_TERMINAL_PROCESSING
- Clears screen and resets cursor position
- Resets SGR attributes and disables alternate screen buffer
- Called on exit in both TUI app and attach command

Refs: anomalyco#20224
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

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

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant