Skip to content

Conversation

@kofany
Copy link

@kofany kofany commented Dec 20, 2025

Summary

This PR implements mouse event handling to support terminal applications that use mouse input (e.g., Midnight Commander, htop, vim with mouse mode enabled).

Changes

  • MouseTrackingConfig interface - Configuration for mouse tracking callbacks
  • SGR (mode 1006) encoding - Modern mouse protocol with unlimited coordinates
  • X10 encoding - Legacy fallback for older applications
  • Event handlers - mousedown, mouseup, mousemove, and wheel support
  • Coordinate conversion - Pixel to terminal cell coordinate mapping
  • Modifier support - Shift, Ctrl, Meta keys in mouse events
  • Mode detection - Respects DECSET modes 1000, 1002, 1003, 1006

How it works

The implementation checks if the terminal application has enabled mouse tracking via DECSET escape sequences before sending mouse events. This ensures compatibility with both mouse-aware applications (mc, htop, vim) and traditional terminal applications.

Testing

Tested with:

  • mc (Midnight Commander) - mouse navigation works
  • htop - mouse clicking on processes works
  • vim with :set mouse=a - mouse positioning works

Test plan

  • Run bun run demo and open http://localhost:8000/demo/
  • Start mc and verify mouse clicks navigate panels
  • Start htop and verify mouse clicks select processes
  • Run vim with :set mouse=a and verify mouse positioning
  • Verify scroll wheel works in mouse-enabled applications
  • Verify text selection still works when mouse tracking is disabled

🤖 Generated with Claude Code

@kofany
Copy link
Author

kofany commented Dec 20, 2025

@codex review

@chatgpt-codex-connector
Copy link

To use Codex here, create a Codex account and connect to github.

kofany and others added 2 commits December 20, 2025 09:05
Implement mouse event handling to support terminal applications that use
mouse input (e.g., mc, htop, vim with mouse mode).

Changes:
- Add MouseTrackingConfig interface for mouse configuration
- Implement SGR (1006) and X10 mouse encoding formats
- Handle mousedown, mouseup, mousemove, and wheel events
- Convert pixel coordinates to terminal cell coordinates
- Support modifier keys (Shift, Ctrl, Meta) in mouse events
- Respect terminal mouse tracking modes (1000, 1002, 1003, 1006)

The implementation checks if the terminal application has enabled mouse
tracking via DECSET sequences before sending mouse events, ensuring
compatibility with both mouse-aware and traditional terminal applications.

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

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@kofany kofany force-pushed the feat/mouse-tracking branch from d903208 to 5e8e189 Compare December 20, 2025 08:24
Copy link
Member

@kylecarbs kylecarbs left a comment

Choose a reason for hiding this comment

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

Very cool - thank you!

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.

3 participants