Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

fix: disable mouse tracking on Windows terminal exit#153

Closed
Ashwinhegde19 wants to merge 1 commit intoKilo-Org:devfrom
Ashwinhegde19:fix/windows-mouse-tracking-exit
Closed

fix: disable mouse tracking on Windows terminal exit#153
Ashwinhegde19 wants to merge 1 commit intoKilo-Org:devfrom
Ashwinhegde19:fix/windows-mouse-tracking-exit

Conversation

@Ashwinhegde19
Copy link

@Ashwinhegde19 Ashwinhegde19 commented Feb 6, 2026

Summary

Fixes GitHub Issue Kilo-Org/kilocode#6328: After closing the CLI on Windows, mouse movement inserts raw escape sequences like [555;27;21M into the terminal. These are SGR mouse tracking events that should have been disabled on exit.

Solution

Added explicit terminal state reset sequences after renderer cleanup to ensure all mouse tracking modes are properly disabled, regardless of the exit path:

  1. New resetTerminalState() function that writes disable sequences for:

    • Normal mouse tracking (\x1b[?1000l)
    • Button-event mouse tracking (\x1b[?1002l)
    • Any-event mouse tracking (\x1b[?1003l)
    • SGR extended mouse mode (\x1b[?1006l)
    • RXVT mouse mode (\x1b[?1015l)
    • Kitty keyboard protocol (\x1b[<u)
    • Text attributes reset (\x1b[0m)
  2. Three exit path handlers:

    • Normal exit via ExitProvider (for /exit, quit, :q commands)
    • Error boundary Ctrl+C handler
    • process.on('exit') safety net for all other exit paths

Test Plan

  • Code follows contribution guidelines
  • Style matches codebase patterns (minimal, helpful comments only)
  • No excessive comments or over-engineering
  • All escape sequences verified against specification
  • Manual testing on Windows to verify mouse tracking is disabled post-exit

Test on your Windows machine by:

  1. Starting the CLI with bun dev
  2. Interact with the TUI and exit with Ctrl+C
  3. Move the mouse in the terminal — no escape sequence characters should appear
  4. Also test: /exit command, typing exit/quit/:q

Add explicit terminal state reset sequences after renderer cleanup to ensure
SGR mouse tracking is properly disabled on exit. On Windows, the terminal may
still report mouse events as raw escape sequences if mouse tracking wasn't
fully disabled. This fix adds:

1. resetTerminalState() function that writes disable sequences for:
   - Normal and button-event mouse tracking
   - Any-event mouse tracking (all movement)
   - SGR extended mouse mode
   - RXVT mouse mode
   - Kitty keyboard protocol
   - Text attributes

2. Calls resetTerminalState() in three exit paths:
   - Normal exit via ExitProvider (exit/quit/:q commands)
   - Error boundary Ctrl+C handler
   - process.on('exit') safety net for all other exits

Fixes #151
@markijbema
Copy link
Contributor

Hi! Thank you for taking the time to contribute to this project—we really appreciate it. 🙏

We are currently working on re-platforming the core of our VS Code and JetBrains extensions to be based on our new Kilo CLI, with a complete rebuild based on OpenCode as our new foundation, and the moment has come to promote this repository to become the main repository. To do that, we moved the code from this repository to the kilocode repository.

This unfortunately means we cannot merge this branch here anymore. Please add https://github.com/Kilo-Org/kilocode.git as a remote, and push your branch there and create a new PR in https://github.com/Kilo-Org/kilocode . We unfortunately cannot do this for you as then the PR would not be in your name anymore. If you need any help, feel free to ask on our Discord in #kilo-dev-contributors

Sorry for the inconvenience and thank you for contributing to Kilo!

@markijbema markijbema closed this Feb 22, 2026
@Ashwinhegde19
Copy link
Author

Can I get Champions Program credits for this PR?
Already completed before migration.

@markijbema
Copy link
Contributor

Hi @Ashwinhegde19 , without a review, the PR is not ready to merge. I'm sorry for causing the extra work, but you should be able to recreate these PRs on the kilocode repository without extra programming; just add the kilocode repository as a remote, push your branch, and create the PR again. Since that repository has the same git history as this one no rebasing/merging or whatever will even be necessary.

So locally in your branch:

# 1. Add the new repo as a remote (call it whatever you like, e.g. "kilocode")
git remote add kilocode https://github.com/Kilo-Org/kilocode.git

# 2. Fetch from it so you have its refs
git fetch kilocode

# 3. Push your current branch to the new remote
git push kilocode HEAD --no-verify

@github-actions
Copy link
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants