diff options
Diffstat (limited to 'test/panes.zig')
| -rw-r--r-- | test/panes.zig | 154 |
1 files changed, 77 insertions, 77 deletions
diff --git a/test/panes.zig b/test/panes.zig index 407f2c3c..dbdbec2f 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -453,7 +453,7 @@ const TtySelectionTests = struct { const pane = p.panes[0].?; pane.tty_filter = false; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha" } }); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -478,7 +478,7 @@ const TtySelectionTests = struct { pane.body.mode = .tty; pane.tty_filter = false; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = if (prompt) + p.update(.{ .output = .{ .pane = .at(0), .bytes = if (prompt) "\x1b]133;A\x07$ \x1b]133;B\x07abc" else "alpha\r\nbravo" } }); @@ -519,7 +519,7 @@ const TtySelectionTests = struct { try noChildInput(p); _ = try p.render(frame.allocator()); try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;C\x07" ++ std.mem.asBytes(&@as([30][12]u8, @splat("\r\nnew output".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;C\x07" ++ std.mem.asBytes(&@as([30][12]u8, @splat("\r\nnew output".*))) } }); _ = try p.render(frame.allocator()); try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); try std.testing.expectEqualStrings(expected, pardes.exec.heldSelection(p, 0).?); @@ -542,10 +542,10 @@ const TtySelectionTests = struct { } p.update(.tick); while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha\r\nbravo" } }); - p.update(.{ .output = .{ .pane = 1, .bytes = "target> " } }); - if (bracketed) p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004h" } }); - if (reports_mouse) p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?1000h\x1b[?1006h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha\r\nbravo" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "target> " } }); + if (bracketed) p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004h" } }); + if (reports_mouse) p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?1000h\x1b[?1006h" } }); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); @@ -569,7 +569,7 @@ const TtySelectionTests = struct { defer written.deinit(); while (p.nextEffect()) |effect| { if (effect == .write) { - try std.testing.expectEqual(@as(u8, 1), effect.write.pane); + try std.testing.expectEqual(1, effect.write.pane.index()); try written.writer.writeAll(effect.write.bytes.slice()); } } @@ -613,7 +613,7 @@ const TtySelectionTests = struct { defer p.deinit(); const pane = p.panes[0].?; try std.testing.expectEqual(panes.Text.Mode.tty, pane.body.mode); - if (bracketed) p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + if (bracketed) p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); try std.testing.expectEqual(bracketed, pardes.Term.modes(pane.terminal).bracketed_paste); try p.registers.put(p.gpa, '"', "one\ntwo", 0, 1, true); // what a `y` anywhere left behind var buf: [256]u8 = undefined; @@ -964,7 +964,7 @@ test "terminal overlay recoloring never materializes unrelated history" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - for (0..1000) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32mcaf\xc3\xa9 \xe7\x95\x8c\x1b[0m\r\n" } }); + for (0..1000) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[32mcaf\xc3\xa9 \xe7\x95\x8c\x1b[0m\r\n" } }); pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 1, .text = try p.gpa.dupe(u8, "edited history") }; var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -1009,7 +1009,7 @@ test "terminal output keeps following new rows after scrollback eviction" { var buf: [64]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "\x1b[32mrow-{d:0>5}\x1b[0m\r\n", .{n}); const previous = pages.scrollbar().total; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); if (pages.scrollbar().total < previous) evictions += 1; } try std.testing.expect(evictions > phase); @@ -1036,7 +1036,7 @@ test "terminal output keeps following new rows after scrollback eviction" { p.update(.{ .key = .{ .cp = 'f', .text = "f" } }); const effect = p.nextEffect() orelse return error.MissingTerminalInput; try std.testing.expectEqual(.write, std.meta.activeTag(effect)); - try std.testing.expectEqual(@as(u8, 0), effect.write.pane); + try std.testing.expectEqual(0, effect.write.pane.index()); try std.testing.expectEqualStrings("f", effect.write.bytes.slice()); try std.testing.expect(p.nextEffect() == null); } @@ -1055,7 +1055,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { while (next < 3000) { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{next}); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); next += 1; if (pages.scrollbar().total > pages.pages.first.?.rows() + pane.rows + 10) break; } @@ -1073,7 +1073,7 @@ test "terminal edit stays on its surviving row when old scrollback is evicted" { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{n}); const previous = pages.scrollbar().total; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); if (pages.scrollbar().total < previous) { removed = previous + 1 - pages.scrollbar().total; break; @@ -1099,8 +1099,8 @@ test "terminal edits and undo survive partial history clearing and whole-screen const pane = p.panes[0].?; pane.body.mode = .tty; if (action == .reset_alternate) - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049h" } }); - p.update(.{ .output = .{ .pane = 0, .bytes = std.mem.asBytes(&@as([40][9]u8, @splat("old row\r\n".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = std.mem.asBytes(&@as([40][9]u8, @splat("old row\r\n".*))) } }); const pages = &pardes.Term.emulatorOf(pane.terminal.?).vt.screens.active.pages; pages.limits.set(.bytes, 64 * 1024); const row: i32 = @as(i32, @intCast(pages.total_rows - pane.rows)) + @@ -1130,7 +1130,7 @@ test "terminal edits and undo survive partial history clearing and whole-screen .reset_primary, .reset_alternate => "\x1bc", .evict_all, .hidden_undo => std.mem.asBytes(&@as([4000][9]u8, @splat("new row\r\n".*))), }; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); const expected: i32 = if (action == .clear_history) 2 else 0; // The copy's top row was in the history ED 3 erased: the copy goes // with it (terminal.zig's rule for rows that are gone), and the @@ -1166,7 +1166,7 @@ test "terminal lower scroll regions do not move edits above them" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "top\r\nsecond\r\nthird" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "top\r\nsecond\r\nthird" } }); pane.ovl = .{ .row = 1, .rows = 1, .text = try gpa.dupe(u8, "unsent") }; pane.body.cur_row = 1; pane.body.cur_pinned = true; @@ -1174,8 +1174,8 @@ test "terminal lower scroll regions do not move edits above them" { const total = pardes.Term.grid(pane.terminal).total; var setup: [64]u8 = undefined; const bytes = try std.fmt.bufPrint(&setup, "\x1b[4;{d}r\x1b[{d};1H", .{ pane.rows, pane.rows }); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); - p.update(.{ .output = .{ .pane = 0, .bytes = std.mem.asBytes(&@as([50][6]u8, @splat("tail\r\n".*))) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = std.mem.asBytes(&@as([50][6]u8, @splat("tail\r\n".*))) } }); try std.testing.expectEqual(total, pardes.Term.grid(pane.terminal).total); try std.testing.expectEqual(@as(i32, 1), pane.ovl.?.row); try std.testing.expectEqual(@as(i32, 1), pane.body.cur_row); @@ -1198,7 +1198,7 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv while (next < 3000) { var buf: [32]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "row-{d:0>5}\r\n", .{next}); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); next += 1; if (pages.pages.first != pages.pages.last and pages.pages.last.?.rows() == pages.pages.last.?.capacity().rows) break; @@ -1214,7 +1214,7 @@ test "terminal eviction and lower-region scrolling in one read preserve a surviv const old_total = pages.total_rows; var buf: [128]u8 = undefined; const bytes = try std.fmt.bufPrint(&buf, "new\r\n\x1b[4;{d}r\x1b[{d};1Hregion\r\n", .{ pane.rows, pane.rows }); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); try std.testing.expectEqual(old_total + 1 - removed, pages.total_rows); try std.testing.expectEqual(@as(i32, 2), pane.ovl.?.row); try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row); @@ -1412,12 +1412,12 @@ test "Save rearms renamed file watches only after a successful write" { watches: usize = 0, err: ?anyerror = null, - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const h: *@This() = @ptrCast(@alignCast(ctx.?)); switch (h.result) { .success => {}, .failure => h.core.saveFailed(id, "save", error.PermissionDenied), - .edited => h.core.panes[id].?.file.?.revision +%= 1, + .edited => h.core.panes[id.index()].?.file.?.revision +%= 1, .replaced => { const replacement = h.core.setTestFile("replacement\n") catch |err| { h.err = err; @@ -1427,16 +1427,16 @@ test "Save rearms renamed file watches only after a successful write" { replacement.file.?.saved_revision -%= 1; }, .closed => { - pardes.panes.deinitPane(h.core, h.core.panes[id].?) catch |err| { + pardes.panes.deinitPane(h.core, h.core.panes[id.index()].?) catch |err| { h.err = err; return; }; - h.core.panes[id] = null; + h.core.panes[id.index()] = null; }, } } - fn watch(ctx: ?*anyopaque, _: u8, _: []const u8, on: bool, _: pardes.WatchMode) void { + fn watch(ctx: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, on: bool, _: pardes.WatchMode) void { const h: *@This() = @ptrCast(@alignCast(ctx.?)); if (on) h.watches += 1; } @@ -1484,7 +1484,7 @@ test "Save rearms renamed file watches only after a successful write" { test "Save on a scratch does not watch a path the host could not create" { const Refusing = struct { - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); p.saveFailed(id, "save", error.PermissionDenied); } @@ -1518,7 +1518,7 @@ test "Save on a scratch does not watch a path the host could not create" { test "a failed Save to another name leaves a clean named file clean" { const Refusing = struct { - fn write(ctx: ?*anyopaque, id: u8, _: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const p: *Pardes = @ptrCast(@alignCast(ctx.?)); p.saveFailed(id, "save", error.AccessDenied); } @@ -1544,14 +1544,14 @@ test "unplaced terminal panes keep their allocated grid until placement" { const id = p.freeSlot().?; const pane = try p.newShell(id, ""); try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]); - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "unplaced\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "unplaced\r\n" } }); try std.testing.expectEqual(pardes.Rect{}, p.view().rects[id]); try std.testing.expectEqual(@as(u16, 100), pane.cols); try std.testing.expectEqual(@as(u16, 30), pane.rows); try std.testing.expectEqual(pane.cols, pardes.Term.emulatorOf(pane.terminal.?).vt.cols); try std.testing.expectEqual(pane.rows, pardes.Term.emulatorOf(pane.terminal.?).vt.rows); while (p.nextEffect()) |effect| { - if (effect == .resize_pty and effect.resize_pty.pane == id) return error.ResizedUnplacedPane; + if (effect == .resize_pty and effect.resize_pty.pane.index() == id) return error.ResizedUnplacedPane; } pardes.layout.insert(p, 0, 1, id); p.update(.tick); @@ -1572,7 +1572,7 @@ test "document panes ignore terminal output without allocating terminal state" { const resizes = allocator.resize_index; allocator.fail_index = allocations; allocator.resize_fail_index = resizes; - p.update(.{ .output = .{ .pane = 0, .bytes = "unrelated PTY output\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "unrelated PTY output\r\n" } }); try std.testing.expect(!allocator.has_induced_failure); try std.testing.expectEqual(allocations, allocator.alloc_index); try std.testing.expectEqual(resizes, allocator.resize_index); @@ -2442,19 +2442,19 @@ const TerminalTests = struct { .write => return error.GreetedBeforeOutput, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "startup banner\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "startup banner\r\n" } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.GreetedBeforePrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;aid=pardes\x07prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;aid=pardes\x07prompt$ " } }); try std.testing.expect(!pardes.Term.prompt(pane.terminal).input_ready); while (p.nextEffect()) |effect| switch (effect) { .write => return error.GreetedDuringPrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;B;aid=pardes\x07" } }); try std.testing.expect(pardes.Term.prompt(pane.terminal).input_ready); var greeted = false; while (p.nextEffect()) |effect| switch (effect) { @@ -2477,9 +2477,9 @@ const TerminalTests = struct { const pane = p.panes[0].?; while (p.nextEffect()) |_| {} p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); - p.update(.{ .output = .{ .pane = 0, .bytes = output } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = output } }); // and a later, quiet prompt changes nothing - p.update(.{ .output = .{ .pane = 0, .bytes = "\r\n\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\r\n\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); while (p.nextEffect()) |effect| switch (effect) { .write => |write| if (std.mem.eql(u8, write.bytes.slice(), "ls\r")) return error.GreetedLate, else => {}, @@ -2500,18 +2500,18 @@ const TerminalTests = struct { else => {}, }; - p.acknowledgeShell(0, "/bin/bash", true); + p.acknowledgeShell(.at(0), "/bin/bash", true); while (p.nextEffect()) |effect| switch (effect) { .write => return error.CommandEscapedBeforePrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "startup\r\n\x1b]133;A\x07prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "startup\r\n\x1b]133;A\x07prompt$ " } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.CommandEscapedDuringPrompt, else => {}, }; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;B\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;B\x07" } }); var sent: [64]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { @@ -2533,10 +2533,10 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} try std.testing.expect(pane.greet); - p.acknowledgeShell(0, "/bin/sh", false); + p.acknowledgeShell(.at(0), "/bin/sh", false); try std.testing.expect(!pane.greet); try std.testing.expectEqual(.none, pane.pending_command.wait); - p.update(.{ .output = .{ .pane = 0, .bytes = "plain prompt$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "plain prompt$ " } }); while (p.nextEffect()) |effect| switch (effect) { .write => return error.UnmarkedGreetingEscaped, else => {}, @@ -2569,7 +2569,7 @@ const TerminalTests = struct { const effect = p.nextEffect() orelse return error.MissingWriteEffect; switch (effect) { .write => |write| { - try std.testing.expectEqual(@as(u8, 0), write.pane); + try std.testing.expectEqual(0, write.pane.index()); try std.testing.expectEqualStrings(expected, write.bytes.slice()); }, else => return error.UnexpectedEffect, @@ -2603,7 +2603,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2658,7 +2658,7 @@ const TerminalTests = struct { // grapheme for that cell, not one per stored codepoint: stepping twice ate // the `A`, and left every colour a cell to the left of its glyph with the // last one stranded on a blank. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A\x1b\\\x1b[32me\u{301}\x1b]133;B\x1b\\\x1b[31mA\x1b[34mB\x1b[35mC" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A\x1b\\\x1b[32me\u{301}\x1b]133;B\x1b\\\x1b[31mA\x1b[34mB\x1b[35mC" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2694,7 +2694,7 @@ const TerminalTests = struct { for (0..60) |i| { var buf: [32]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[4{d}mL{d:0>2}\x1b[0m\r\n", .{ (i % 6) + 1, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; pardes.Term.scroll(pane.terminal.?, -20); @@ -2745,7 +2745,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2782,7 +2782,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2821,7 +2821,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - p.update(.{ .output = .{ .pane = 0, .bytes = payload } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = payload } }); const diffs = try modeStyleDiffs(p, pane, testing.allocator, if (filter) "session filter=on" else "session filter=off"); try testing.expectEqual(@as(usize, 0), diffs); } @@ -2864,7 +2864,7 @@ const TerminalTests = struct { "\x1b]133;A\x1b\\\x1b[32m{s}$ \x1b]133;B\x1b\\\x1b[31mab\x1b[34mcd\x1b[0m", .{prompt}, ); - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -2923,7 +2923,7 @@ const TerminalTests = struct { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = filter; - p.update(.{ .output = .{ .pane = 0, .bytes = payload } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = payload } }); const diffs = try modeStyleDiffs(p, pane, testing.allocator, if (filter) "bg filter=on" else "bg filter=off"); try testing.expectEqual(@as(usize, 0), diffs); } @@ -2941,7 +2941,7 @@ const TerminalTests = struct { for (0..60) |i| { var buf: [40]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[3{d}mL{d:0>2}\x1b[0m\r\n", .{ (i % 6) + 1, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3004,7 +3004,7 @@ const TerminalTests = struct { p.sync(); pane.tty_filter = filter; pane.body.mode = mode; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[32m\u{754C}\x1b[41m\x1b[K\x1b[7G\x1b[44m\x1b[K\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[32m\u{754C}\x1b[41m\x1b[K\x1b[7G\x1b[44m\x1b[K\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3040,7 +3040,7 @@ const TerminalTests = struct { const pane = p.panes[0].?; pane.tty_filter = false; pane.body.mode = mode; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[41mzzzzzzzzzzzzz\u{754C}\x1b[0m\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[41mzzzzzzzzzzzzz\u{754C}\x1b[0m\r\n" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3070,7 +3070,7 @@ const TerminalTests = struct { for (0..40) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mline-{d:0>2}\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; @@ -3124,12 +3124,12 @@ const TerminalTests = struct { const tx = r.x + config.GUTTER; const body_y = bodyY(p, r); - p.update(.{ .output = .{ .pane = 0, .bytes = "plain text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "plain text\r\n" } }); p.shell_rows.stale = true; const before = try p.render(frame.allocator()); const plain = before.at(tx, body_y).style; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?5h" } }); p.shell_rows.stale = true; _ = frame.reset(.retain_capacity); const after = try p.render(frame.allocator()); @@ -3153,7 +3153,7 @@ const TerminalTests = struct { for (0..6) |i| { var buf: [40]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}\x1b[0m\r\n", .{ 16 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } var frame = std.heap.ArenaAllocator.init(testing.allocator); @@ -3192,7 +3192,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31m000\x1b[0m\r\n\x1b[32m111\x1b[0m\r\n\r\n\x1b[34m333\x1b[0m\r\n\x1b[35m444\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31m000\x1b[0m\r\n\x1b[32m111\x1b[0m\r\n\r\n\x1b[34m333\x1b[0m\r\n\x1b[35m444\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3228,7 +3228,7 @@ const TerminalTests = struct { pane.tty_filter = false; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[31mAAA\x1b[0m\r\n\x1b[32mBBB\x1b[0m\r\n\x1b[34mCCC\x1b[0m" } }); var frame = std.heap.ArenaAllocator.init(testing.allocator); defer frame.deinit(); @@ -3267,7 +3267,7 @@ const TerminalTests = struct { for (0..6) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d}-abcdefgh\x1b[0m\r\n", .{ 30 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } // One `Z` typed into the middle of row 3's own text. pane.ovl = .{ .row = 3, .rows = 1, .text = try p.gpa.dupe(u8, "row-3-abcZdefgh") }; @@ -3317,7 +3317,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } pane.ovl = .{ .row = 23, @@ -3376,7 +3376,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; @@ -3464,7 +3464,7 @@ const TerminalTests = struct { for (0..26) |i| { var buf: [64]u8 = undefined; const bytes = std.fmt.bufPrint(&buf, "\x1b[38;5;{d}mrow-{d:0>2}-xyzzy\x1b[0m\r\n", .{ 20 + i, i }) catch unreachable; - p.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } // A newline typed at column 0 of row 24, and `WW` typed on the blank row // below the output: the span covers rows 24, 25 and that blank row. @@ -3528,7 +3528,7 @@ test "cancelled normal gestures leave no count or subprefix through raw tty mode defer p.deinit(); const pane = p.panes[0].?; pane.body.mode = .normal; - p.update(.{ .output = .{ .pane = 0, .bytes = "abcdefghij\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abcdefghij\r\n" } }); for (keys) |cp| p.update(.{ .key = .{ .cp = cp } }); try std.testing.expect(!std.meta.eql(modal.Normal.State{}, pane.body.normal)); p.update(.{ .key = .{ .cp = p.opts.tty_toggle, .ctrl = true } }); @@ -3621,7 +3621,7 @@ test "terminal overlays preserve trailing blank styles without coloring inserted while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.tty_filter = false; - p.update(.{ .output = .{ .pane = 0, .bytes = "A\r\n\x1b[41m\x1b[2K\r\n\x1b[42m\x1b[2K\r\n\x1b[44m\x1b[2K\x1b[0m" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "A\r\n\x1b[41m\x1b[2K\r\n\x1b[42m\x1b[2K\r\n\x1b[44m\x1b[2K\x1b[0m" } }); pane.body.mode = .normal; pane.ovl = .{ .row = 0, .rows = 3, .text = try gpa.dupe(u8, "A\n\n") }; var frame = std.heap.ArenaAllocator.init(gpa); @@ -3713,7 +3713,7 @@ test "a terminal keeps its tag and two body rows through a squeeze, a drag and a p.sync(); try std.testing.expectEqual(floor, p.view().rects[term].h); var rows: ?u16 = null; - while (p.nextEffect()) |effect| if (effect == .resize_pty and effect.resize_pty.pane == term) { + while (p.nextEffect()) |effect| if (effect == .resize_pty and effect.resize_pty.pane.index() == term) { rows = effect.resize_pty.rows; }; try std.testing.expectEqual(@as(?u16, layout.min_body_rows), rows); @@ -3751,7 +3751,7 @@ const PdfAddon = struct { const j = pardes.host_io.KindJob.take(core, a.pane, a.serial, a.token) orelse continue; defer j.drop(); j.run(); - try land.step(.{ .job = .{ .pane = j.pane, .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); + try land.step(.{ .job = .{ .pane = .at(j.pane), .serial = j.serial, .token = j.token, .gen = j.gen, .bytes = j.out } }); } } @@ -3760,7 +3760,7 @@ const PdfAddon = struct { items: [16]Asked = undefined, n: usize = 0, fn append(q: *@This(), j: anytype) void { - if (q.n < q.items.len) q.items[q.n] = .{ .pane = j.pane, .serial = j.serial, .token = j.token }; + if (q.n < q.items.len) q.items[q.n] = .{ .pane = j.pane.index(), .serial = j.serial, .token = j.token }; q.n += @intFromBool(q.n < q.items.len); } fn pop(q: *@This()) ?Asked { @@ -3777,7 +3777,7 @@ const PdfAddon = struct { } }.f, .job = struct { - fn f(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn f(_: ?*anyopaque, pane: pardes.Pane.Id, serial: u32, token: u32) void { asked.append(.{ .pane = pane, .serial = serial, .token = token }); } }.f, @@ -3833,7 +3833,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); var buf: [4096]u8 = undefined; const real = try std.Io.Dir.cwd().realPathFile(std.testing.io, "docs/design.pdf", &buf); var line: [4200]u8 = undefined; @@ -3903,7 +3903,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(@import("test_addons").image, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "dot.ppm", .data = "P6\n1 1\n255\n\x01\x02\x03" }); @@ -4077,7 +4077,7 @@ const PdfAddon = struct { // Another file under its name (an outline's three pages): opened // again, on the page it can still be on, as height-fitted. try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "live.pdf", .data = try std.Io.Dir.cwd().readFileAlloc(std.testing.io, "test/pdf-fixtures/outline.pdf", p.scratch.allocator(), .unlimited) }); - try std.testing.expect(p.reloadWatchedFile(@intCast(id), &.{})); + try std.testing.expect(p.reloadWatchedFile(.at(id), &.{})); p.update(.tick); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); @@ -4202,7 +4202,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); const kind = a.core.kinds.n - 1; win.core().kinds.ops[kind] = a.core.kinds.ops[kind]; const id = try opened(a, land); @@ -4225,7 +4225,7 @@ const PdfAddon = struct { defer arena.deinit(); var at: [2][8][4]u32 = @splat(@splat(@splat(0))); for ([_]*Pardes{ a.core, win.core() }, [_]u8{ 0, k.view }, &at) |core, view, *rows| { - core.toView(view); + core.toView(.at(view)); var n: usize = 0; for ((try core.render(arena.allocator())).placements.items) |pl| if (pl.pane == id and pl.raster.w > 1 and n < rows.len) { rows[n] = if (pl.at) |x| .{ x.y, x.h, pl.src.y, pl.src.h } else .{ 0, 0, pl.src.y, pl.src.h }; @@ -4245,7 +4245,7 @@ const PdfAddon = struct { var words: [64]pardes.Kind.LoadedWord = undefined; var why: pardes.Kind.Buf(160) = .{}; const lib = pardes.Addon.readLoaded(pdf_lib, &words, &why); - try land.step(.{ .addon = .{ .op = .load, .pane = 0, .kind = &lib } }); + try land.step(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &lib } }); const kind = a.core.kinds.n - 1; win.core().kinds.ops[kind] = a.core.kinds.ops[kind]; const id = try opened(a, land); @@ -4285,7 +4285,7 @@ const PdfAddon = struct { try std.testing.expect(first.len > 0); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); - win.core().toView(c.view); + win.core().toView(.at(c.view)); const s = try win.core().render(arena.allocator()); const r = win.core().view().rects[c.id]; var row: [512]u8 = undefined; |
