summaryrefslogtreecommitdiff
path: root/src/mouse.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:38:44 -0300
committerGabriel Schneider <[email protected]>2026-11-05 01:00:59 -0300
commit8b24617780e0f9d50b0bfd9cee1883802af24515 (patch)
treebf148fd6ddef4b29cb067869e541d7538c58cdaf /src/mouse.zig
parent3624c0e0bf0b455c4323fc8ba9f10a305f11afb2 (diff)
downloadpardes-8b24617780e0f9d50b0bfd9cee1883802af24515.tar.gz
pardes-8b24617780e0f9d50b0bfd9cee1883802af24515.zip
tests: the pty bytes a test drains are one test_api.ptyBytes (a pane's, or every pane's for null), where pardes.zig's drainWrites and mouse.zig's ptyWrites each drained them
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/mouse.zig')
-rw-r--r--src/mouse.zig43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/mouse.zig b/src/mouse.zig
index 1292c06f..426b7d8e 100644
--- a/src/mouse.zig
+++ b/src/mouse.zig
@@ -1999,15 +1999,6 @@ test "a chorded exec an event reader holds is told with its argument, and writte
_ = th.call(p, .{ .tag = 4, .op = .release, .node = event, .handle = h });
}
-/// Every byte the core wrote to pane 0's pty since the last call.
-fn ptyWrites(p: *Pardes, out: *std.ArrayList(u8)) ![]const u8 {
- out.clearRetainingCapacity();
- while (p.nextEffect()) |effect| {
- if (effect == .write and effect.write.pane == 0) try out.appendSlice(p.gpa, effect.write.bytes.slice());
- }
- return out.items;
-}
-
test "a wheel over a program that owns it is the program's, in the form it asked for; a shell's scrolls" {
if (comptime !panes.terminal.enabled) return error.SkipZigTest;
const gpa = std.testing.allocator;
@@ -2016,9 +2007,8 @@ test "a wheel over a program that owns it is the program's, in the form it asked
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- var out: std.ArrayList(u8) = .empty;
- defer out.deinit(gpa);
- _ = try ptyWrites(p, &out);
+ var out: [4096]u8 = undefined;
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
const pane = p.panes[0].?;
const r = p.rects[0];
// Grid cell 6,4 (1-based), as a program counts.
@@ -2047,9 +2037,9 @@ test "a wheel over a program that owns it is the program's, in the form it asked
};
for (cases) |case| {
p.update(.{ .output = .{ .pane = 0, .bytes = case.modes } });
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
p.update(.{ .mouse = .{ .button = case.button, .kind = .press, .col = col, .row = row, .ctrl = case.ctrl, .alt = case.alt, .shift = case.shift } });
- try std.testing.expectEqualStrings(case.sent, try ptyWrites(p, &out));
+ try std.testing.expectEqualStrings(case.sent, pardes.test_api.ptyBytes(p, 0, &out));
}
// A shell on the main screen: the wheel scrolls its scrollback, and
// the shell hears nothing.
@@ -2059,21 +2049,21 @@ test "a wheel over a program that owns it is the program's, in the form it asked
p.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } });
}
_ = try p.render(frame.allocator());
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
const was = pane.scroll();
p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = col, .row = row } });
- try std.testing.expectEqualStrings("", try ptyWrites(p, &out));
+ try std.testing.expectEqualStrings("", pardes.test_api.ptyBytes(p, 0, &out));
try std.testing.expect(pane.scroll() != was);
// A program tracking the mouse on the main screen: Shift and the
// wheel scroll the scrollback, the program hears nothing.
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1000h\x1b[?1006h" } });
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
const tracked = pane.scroll();
p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = col, .row = row, .shift = true } });
- try std.testing.expectEqualStrings("", try ptyWrites(p, &out));
+ try std.testing.expectEqualStrings("", pardes.test_api.ptyBytes(p, 0, &out));
try std.testing.expect(pane.scroll() != tracked);
p.update(.{ .mouse = .{ .button = .wheel_up, .kind = .press, .col = col, .row = row } });
- try std.testing.expectEqualStrings("\x1b[<64;6;4M", try ptyWrites(p, &out));
+ try std.testing.expectEqualStrings("\x1b[<64;6;4M", pardes.test_api.ptyBytes(p, 0, &out));
}
test "Alt-click is B2 and Super-click B3, kept from the press through the release; Ctrl-click stays B1" {
@@ -2113,9 +2103,8 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
var frame = std.heap.ArenaAllocator.init(gpa);
defer frame.deinit();
_ = try p.render(frame.allocator());
- var out: std.ArrayList(u8) = .empty;
- defer out.deinit(gpa);
- _ = try ptyWrites(p, &out);
+ var out: [4096]u8 = undefined;
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
const pane = p.panes[0].?;
try std.testing.expectEqual(.tty, pane.body.mode);
const r = p.rects[0];
@@ -2123,7 +2112,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
const row = p.bodyTop(pane, r) + 3;
const Ev = struct { button: Mouse.Button, kind: Mouse.Kind, dx: i32 = 0, dy: i32 = 0, shift: bool = false, alt: bool = false, ctrl: bool = false, super: bool = false };
const send = struct {
- fn f(pp: *Pardes, o: *std.ArrayList(u8), c: u16, rw: u16, e: Ev) ![]const u8 {
+ fn f(pp: *Pardes, o: []u8, c: u16, rw: u16, e: Ev) ![]const u8 {
pp.update(.{ .mouse = .{
.button = e.button,
.kind = e.kind,
@@ -2134,12 +2123,12 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
.ctrl = e.ctrl,
.super = e.super,
} });
- return ptyWrites(pp, o);
+ return pardes.test_api.ptyBytes(pp, 0, o);
}
}.f;
// htop's modes: clicks in SGR, a release its own `m`.
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } });
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
try std.testing.expect(p.drag == .none);
// 1000 has no drags; the release is reported where it lands.
@@ -2181,7 +2170,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
// codex's any-event tracking: a drag once per cell, carried past the
// grid's edge and clamped there, and bare moves.
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003h" } });
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[<35;9;4M", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 }));
try std.testing.expectEqualStrings("", try send(p, &out, col, row, .{ .button = .none, .kind = .motion, .dx = 3 }));
try std.testing.expectEqualStrings("\x1b[<0;6;4M", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
@@ -2205,7 +2194,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri
// Legacy X10 bytes: a release is button 3. (Turning 1003 off turns
// tracking off, as xterm's one tracking mode goes.)
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } });
- _ = try ptyWrites(p, &out);
+ _ = pardes.test_api.ptyBytes(p, 0, &out);
try std.testing.expectEqualStrings("\x1b[M &$", try send(p, &out, col, row, .{ .button = .left, .kind = .press }));
try std.testing.expectEqualStrings("\x1b[M#&$", try send(p, &out, col, row, .{ .button = .left, .kind = .release }));