Skip to content

Conversation

@Ashwinhegde19
Copy link

@Ashwinhegde19 Ashwinhegde19 commented Feb 6, 2026

Summary

Fixes GitHub Issue #151: 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 Kilo-Org#151
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.

1 participant