Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
325 changes: 0 additions & 325 deletions packages/core/src/cmd/handle-csi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const Osc = @import("input/osc.zig").Osc;
const Dcs = @import("input/dcs.zig").Dcs;
const keys = @import("keys.zig");
const constants = @import("input/constants.zig");
const expectEvents = @import("./test-utils.zig").expectEvents;
const logger = @import("input/manager.zig").logger;
const TermKeyType = enum(i32) {
unicode,
Expand Down Expand Up @@ -910,57 +909,6 @@ pub fn interpretUnicodeKey(manager: *AnyInputManager, csi: RawCsi, raw: []const
// manager.emitCodepoint(@intCast(final_codepoint), modifiers, raw);
return .{ .match = raw.len };
}
const KittySequence = @import("keys.zig").KittySequence;
fn expectKittySequence(allocator: std.mem.Allocator, comptime seq: KittySequence, comptime expected: []const u8) !void {
var buf: [128]u8 = undefined;

const actual = try seq.encode(&buf);
// std.debug.print("actual: {s}\n", .{actual[1..]});
try expectEvents(
allocator,
actual[1..],
&.{actual},
&.{expected},
);
}
test "unicode" {
try expectKittySequence(std.testing.allocator, .{
.key = 'a',
.final = 'u',
.event = .press,
.mods = .{
.shift = true,
},
}, "[key 'a' 97 mod='shift']");

try expectKittySequence(std.testing.allocator, .{
.key = 'a',
.final = 'u',
.event = .press,
.mods = .{
.shift = true,
.ctrl = true,
},
}, "[key 'a' 97 mod='shift+ctrl']");

try expectKittySequence(std.testing.allocator, .{
.key = 'a',
.final = 'u',
.event = .press,
}, "[key 'a' 97]");

try expectKittySequence(std.testing.allocator, .{
.key = 'a',
.final = 'u',
.event = .release,
}, "[key .release 'a' 97]");

try expectKittySequence(std.testing.allocator, .{
.key = 'a',
.final = 'u',
.event = .repeat,
}, "[key .repeat 'a' 97]");
}

pub fn handleCsiCsi(manager: *AnyInputManager, buffer: []const u8, position: usize, intro_len: usize) Match {
logger.info("try handleCsiCsi", .{});
Expand Down Expand Up @@ -1117,279 +1065,6 @@ pub fn interpretCursorPositionReport(manager: *AnyInputManager, csi: RawCsi, raw
return .{ .match = raw.len };
}

test "interpretX10MouseEvent" {
try expectEvents(
std.testing.allocator,
"left",
&.{"\x1b[M" ++ [_]u8{ 32, 232, 232 }},
&.{"[mouse .left_press (x=200 y=200)]"},
);
try expectEvents(
std.testing.allocator,
"middle",
&.{"\x1b[M" ++ [_]u8{ 33, 232, 232 }},
&.{"[mouse .middle_press (x=200 y=200)]"},
);
try expectEvents(
std.testing.allocator,
"right",
&.{"\x1b[M" ++ [_]u8{ 34, 232, 232 }},
&.{"[mouse .right_press (x=200 y=200)]"},
);

try expectEvents(
std.testing.allocator,
"release",
&.{"\x1b[M" ++ [_]u8{ 35, 232, 232 }},
&.{"[mouse .release (x=200 y=200)]"},
);

// Test wheel mice events - note: keeping original names for normal tracking mode
try expectEvents(
std.testing.allocator,
"wheel forward",
&.{"\x1b[M" ++ [_]u8{ 32 + 64, 232, 232 }},
&.{"[mouse .wheel_forward (x=200 y=200)]"},
);
try expectEvents(
std.testing.allocator,
"wheel back",
&.{"\x1b[M" ++ [_]u8{ 33 + 64, 232, 232 }},
&.{"[mouse .wheel_back (x=200 y=200)]"},
);

// Test wheel tilt events
try expectEvents(
std.testing.allocator,
"wheel tilt right",
&.{"\x1b[M" ++ [_]u8{ 34 + 64, 232, 232 }},
&.{"[mouse .wheel_tilt_right (x=200 y=200)]"},
);
try expectEvents(
std.testing.allocator,
"wheel tilt left",
&.{"\x1b[M" ++ [_]u8{ 35 + 64, 232, 232 }},
&.{"[mouse .wheel_tilt_left (x=200 y=200)]"},
);

// Test higher buttons (8-11)
try expectEvents(
std.testing.allocator,
"button 8 (with 128 flag)",
&.{"\x1b[M" ++ [_]u8{ 32 + 128, 232, 232 }},
&.{"[mouse .left_press (x=200 y=200)]"},
);
try expectEvents(
std.testing.allocator,
"button 9 (with 128 flag)",
&.{"\x1b[M" ++ [_]u8{ 33 + 128, 232, 232 }},
&.{"[mouse .middle_press (x=200 y=200)]"},
);

// Test with modifiers
try expectEvents(
std.testing.allocator,
"left with shift",
&.{"\x1b[M" ++ [_]u8{ 32 + 4, 232, 232 }},
&.{"[mouse .left_press (x=200 y=200) mod='shift']"},
);
try expectEvents(
std.testing.allocator,
"wheel forward with ctrl",
&.{"\x1b[M" ++ [_]u8{ 32 + 64 + 16, 232, 232 }},
&.{"[mouse .wheel_forward (x=200 y=200) mod='ctrl']"},
);
}

test "interpretExtendedMouseEvents" {
// Test SGR protocol (1006)
try expectEvents(
std.testing.allocator,
"SGR left press",
&.{"\x1b[<0;100;100M"},
&.{"[mouse .extended .press .left (x=99 y=99)]"},
);
try expectEvents(
std.testing.allocator,
"SGR right press",
&.{"\x1b[<2;50;60M"},
&.{"[mouse .extended .press .right (x=49 y=59)]"},
);
try expectEvents(
std.testing.allocator,
"SGR left release",
&.{"\x1b[<0;25;30m"},
&.{"[mouse .extended .release .left (x=24 y=29)]"},
);
try expectEvents(
std.testing.allocator,
"SGR wheel up",
&.{"\x1b[<64;75;80M"},
&.{"[mouse .extended .wheel_up .wheel (x=74 y=79)]"},
);
try expectEvents(
std.testing.allocator,
"SGR wheel down",
&.{"\x1b[<65;45;50M"},
&.{"[mouse .extended .wheel_down .wheel (x=44 y=49)]"},
);
try expectEvents(
std.testing.allocator,
"SGR wheel left",
&.{"\x1b[<66;120;130M"},
&.{"[mouse .extended .wheel_left .wheel (x=119 y=129)]"},
);
try expectEvents(
std.testing.allocator,
"SGR wheel right",
&.{"\x1b[<67;90;95M"},
&.{"[mouse .extended .wheel_right .wheel (x=89 y=94)]"},
);
try expectEvents(
std.testing.allocator,
"SGR with shift modifier",
&.{"\x1b[<4;10;15M"},
&.{"[mouse .extended .press .left (x=9 y=14) mod='shift']"},
);
try expectEvents(
std.testing.allocator,
"SGR with ctrl modifier",
&.{"\x1b[<16;30;35M"},
&.{"[mouse .extended .press .left (x=29 y=34) mod='ctrl']"},
);
try expectEvents(
std.testing.allocator,
"SGR with alt modifier",
&.{"\x1b[<8;50;55M"},
&.{"[mouse .extended .press .left (x=49 y=54) mod='alt']"},
);

// Test motion events
try expectEvents(
std.testing.allocator,
"SGR motion with left button",
&.{"\x1b[<32;60;65M"},
&.{"[mouse .extended .motion .left (x=59 y=64)]"},
);
try expectEvents(
std.testing.allocator,
"SGR motion with right button",
&.{"\x1b[<34;70;75M"},
&.{"[mouse .extended .motion .right (x=69 y=74)]"},
);

// Test higher buttons
try expectEvents(
std.testing.allocator,
"SGR button 8",
&.{"\x1b[<128;40;45M"},
&.{"[mouse .extended .press .button8 (x=39 y=44)]"},
);
try expectEvents(
std.testing.allocator,
"SGR button 9",
&.{"\x1b[<129;50;55M"},
&.{"[mouse .extended .press .button9 (x=49 y=54)]"},
);

// Test URXVT protocol (1015)
try expectEvents(
std.testing.allocator,
"URXVT left press",
&.{"\x1b[0;100;100M"},
&.{"[mouse .extended .press .left (x=99 y=99)]"},
);
try expectEvents(
std.testing.allocator,
"URXVT right press",
&.{"\x1b[2;50;60M"},
&.{"[mouse .extended .press .right (x=49 y=59)]"},
);
try expectEvents(
std.testing.allocator,
"URXVT wheel up",
&.{"\x1b[64;75;80M"},
&.{"[mouse .extended .wheel_up .wheel (x=74 y=79)]"},
);
try expectEvents(
std.testing.allocator,
"URXVT with shift modifier",
&.{"\x1b[4;10;15M"},
&.{"[mouse .extended .press .left (x=9 y=14) mod='shift']"},
);
}

test "interpretCursorPositionReport" {
try expectEvents(
std.testing.allocator,
"Cursor position report",
&.{"\x1b[?10;20R"},
&.{"[mouse .cursor_report (row=9 col=19)]"},
);

try expectEvents(
std.testing.allocator,
"Cursor position with leading zero",
&.{"\x1b[?01;05R"},
&.{"[mouse .cursor_report (row=0 col=4)]"},
);

try expectEvents(
std.testing.allocator,
"Cursor position at origin",
&.{"\x1b[?1;1R"},
&.{"[mouse .cursor_report (row=0 col=0)]"},
);

try expectEvents(
std.testing.allocator,
"Cursor position with leading zero",
&.{"\x1b[?1;05R"},
&.{"[mouse .cursor_report (row=0 col=4)]"},
);
}

test "interpretModeStatusReport" {
// Test form 1: CSI?<mode>;<value>$y
// try expectEvents(
// std.testing.allocator,
// "Mode status report - with ? prefix",
// &.{"\x1b[?25;60$y"},
// &.{"[mode_report (mode=63 value1=25 value2=60)]"},
// );

// // Test form 2: CSI<mode>;<value>$y
// try expectEvents(
// std.testing.allocator,
// "Mode status report - standard form",
// &.{"\x1b[100;45$y"},
// &.{"[mode_report (mode=0 value1=100 value2=45)]"},
// );

// // Test with $ directly after parameter
// try expectEvents(
// std.testing.allocator,
// "Mode status report - $ after parameter",
// &.{"\x1b[100;45$y"},
// &.{"[mode_report (mode=0 value1=100 value2=45)]"},
// );

// // Test with space between parameter and $
// try expectEvents(
// std.testing.allocator,
// "Mode status report - space before $",
// &.{"\x1b[100;45 $y"},
// &.{"[mode_report (mode=0 value1=100 value2=45)]"},
// );

// // Test with larger values
// try expectEvents(
// std.testing.allocator,
// "Mode status report - with larger values",
// &.{"\x1b[1024;255$y"},
// &.{"[mode_report (mode=0 value1=1024 value2=255)]"},
// );
}

// test "interpretUnicodeKey" {
// // Test basic Unicode key with no modifiers
Expand Down
13 changes: 0 additions & 13 deletions packages/core/src/cmd/handle-term-info.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const std = @import("std");

const expectEvents = @import("test-utils.zig").expectEvents;
const AnyInputManager = @import("input/manager.zig").AnyInputManager;
const Match = @import("input/manager.zig").Match;
const Event = @import("input/manager.zig").Event;
Expand Down Expand Up @@ -237,15 +236,3 @@ pub fn handleTerminalInfo(manager: *AnyInputManager, buffer: []const u8, positio
return .partial;
}

test "term info" {
try expectEvents(
std.testing.allocator,
"xterm-ghostty",
&.{
"\x1b[1;3P",
},
&.{
"[.key_f1]",
},
);
}
Loading