input: extract mouse encoding to a pure, testable file

Move mouse event encoding logic from Surface.zig into a new
input/mouse_encode.zig file.

The new file encapsulates event filtering (shouldReport),
button code computation, viewport bounds checking, motion
deduplication, and all five wire formats (X10, UTF-8, SGR,
urxvt, SGR-pixels). This makes the encoding independently
testable and adds unit tests covering each format and edge
case.

Additionally, Surface `mouseReport` can no longer fail, since the only
failure mode is no buffer space which should be impossible. Updated
the signature to remove the error set.
This commit is contained in:
Mitchell Hashimoto
2026-03-15 07:43:34 -07:00
parent a7514d389b
commit ac5e57ce67
6 changed files with 839 additions and 217 deletions

View File

@@ -16,7 +16,7 @@ const MouseShape = @import("terminal/mouse_shape.zig").MouseShape;
physical_key: input.Key,
/// The mouse event tracking mode, if any.
mouse_event: terminal.Terminal.MouseEvents,
mouse_event: terminal.Terminal.MouseEvent,
/// The current terminal's mouse shape.
mouse_shape: MouseShape,