diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/Addon.zig | 8 | ||||
| -rw-r--r-- | core/Core.zig | 128 | ||||
| -rw-r--r-- | core/Effect.zig | 88 | ||||
| -rw-r--r-- | core/Event.zig | 13 | ||||
| -rw-r--r-- | core/File.zig | 8 | ||||
| -rw-r--r-- | core/Jump.zig | 4 | ||||
| -rw-r--r-- | core/Kind.zig | 4 | ||||
| -rw-r--r-- | core/Plumb.zig | 2 | ||||
| -rw-r--r-- | core/Query.zig | 2 | ||||
| -rw-r--r-- | core/builtins.zig | 18 | ||||
| -rw-r--r-- | core/dump.zig | 4 | ||||
| -rw-r--r-- | core/echo.zig | 4 | ||||
| -rw-r--r-- | core/edit.zig | 6 | ||||
| -rw-r--r-- | core/exec.zig | 6 | ||||
| -rw-r--r-- | core/fs.zig | 4 | ||||
| -rw-r--r-- | core/keys.zig | 2 | ||||
| -rw-r--r-- | core/look.zig | 8 | ||||
| -rw-r--r-- | core/lsp/Ask.zig | 4 | ||||
| -rw-r--r-- | core/mouse.zig | 14 | ||||
| -rw-r--r-- | core/ninep/ctl.zig | 28 | ||||
| -rw-r--r-- | core/ninep/pane.zig | 4 | ||||
| -rw-r--r-- | core/ninep/pty.zig | 34 | ||||
| -rw-r--r-- | core/ninep/screen.zig | 10 | ||||
| -rw-r--r-- | core/ninep/testing.zig | 6 | ||||
| -rw-r--r-- | core/panes.zig | 8 | ||||
| -rw-r--r-- | core/replica.zig | 57 | ||||
| -rw-r--r-- | core/root.zig | 2 | ||||
| -rw-r--r-- | core/views.zig | 2 |
28 files changed, 241 insertions, 237 deletions
diff --git a/core/Addon.zig b/core/Addon.zig index e84b122b..cb3dbf54 100644 --- a/core/Addon.zig +++ b/core/Addon.zig @@ -69,7 +69,7 @@ pub fn perform(p: *Pardes, op: Op, pane: u8, arg: []const u8) void { var words: [64]LoadedWord = undefined; var why: Why = .{}; const l = readLoaded(arg, &words, &why); - p.update(.{ .addon = .{ .op = op, .pane = pane, .kind = &l } }); + p.update(.{ .addon = .{ .op = op, .pane = .at(pane), .kind = &l } }); } /// What a load reads off the library at `path` (held): the `addon` @@ -727,12 +727,12 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { const dir = std.mem.trimEnd(u8, if (p.panes[id]) |pane| Pardes.paneDir(pane) else p.sessionDir(), "/"); const path = if (std.Io.Dir.path.isAbsolute(rest)) rest else std.fmt.bufPrint(&target, "{s}/{s}", .{ dir, rest }) catch return p.reportFailure(id, "Addon: that path is too long"); if (path.len > pardes.effect_path_cap) return p.reportFailure(id, "Addon: that path is too long"); - return p.emit(.{ .addon = .{ .op = .load, .pane = @intCast(id), .arg = .from(path) } }); + return p.emit(.{ .addon = .{ .op = .load, .pane = .at(id), .arg = .from(path) } }); } const k = p.kinds.byName(rest) orelse return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon {t}: no addon brought kind {s}", .{ op, rest }) catch takes); const e = &p.kinds.kinds[k]; if (op == .reload and std.mem.eql(u8, e.path.slice(), "builtin")) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon reload: {s} is built into this pardes", .{rest}) catch takes); - if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = @intCast(id), .arg = .from(e.path.slice()) } }); + if (op == .reload) return p.emit(.{ .addon = .{ .op = .reload, .pane = .at(id), .arg = .from(e.path.slice()) } }); const n = openPanes(p, rest); if (n > 0) return p.reportFailure(id, std.fmt.bufPrint(&said, "Addon unload: {d} {s} pane{s} open", .{ n, rest, if (n == 1) " is" else "s are" }) catch takes); const hash = e.hash; @@ -743,7 +743,7 @@ pub fn run(p: *Pardes, id: usize, arg: ?[]const u8) void { } fn release(p: *Pardes, hash: [32]u8) void { - p.emit(.{ .addon = .{ .op = .release, .pane = 0, .arg = .from(&hash) } }); + p.emit(.{ .addon = .{ .op = .release, .pane = .at(0), .arg = .from(&hash) } }); } pub fn openPanes(p: *const Pardes, name: []const u8) usize { diff --git a/core/Core.zig b/core/Core.zig index e3238a6e..282094b3 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -956,7 +956,7 @@ pub fn emitWrite(p: *Pardes, id: usize, bytes: []const u8) void { if (p.pending_write[id] == null) { while (off < bytes.len and p.effects_len < p.effects.len) { const n = @min(bytes.len - off, effect_write_cap); - p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(bytes[off .. off + n]) } }); + p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(bytes[off .. off + n]) } }); off += n; } } @@ -1278,7 +1278,7 @@ fn refillPendingWrites(p: *Pardes) void { // a copy's cursor and re-send the same chunk for ever. const pw = if (slot.*) |*live| live else break; const n = @min(pw.bytes.len - pw.off, effect_write_cap); - p.emit(.{ .write = .{ .pane = @intCast(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } }); + p.emit(.{ .write = .{ .pane = .at(id), .bytes = .from(pw.bytes[pw.off..][0..n]) } }); pw.off += n; p.pending_write_bytes -= n; if (pw.off == pw.bytes.len) { @@ -1324,17 +1324,17 @@ fn nextQueued(p: *Pardes) ?Event { pub fn hostForegroundName(p: *const Pardes, id: usize, buf: []u8) ?[]const u8 { const f = p.host.vtable.fg_name orelse return null; - return f(p.host.ctx, @intCast(id), buf); + return f(p.host.ctx, .at(id), buf); } pub fn hostTtyTaken(p: *const Pardes, id: usize) bool { const f = p.host.vtable.tty_taken orelse return false; - return f(p.host.ctx, @intCast(id)); + return f(p.host.ctx, .at(id)); } pub fn hostKillJob(p: *const Pardes, id: usize) bool { const f = p.host.vtable.kill_job orelse return false; - return f(p.host.ctx, @intCast(id)); + return f(p.host.ctx, .at(id)); } /// A terminal whose shell could not be started: said, and a run waiting @@ -1626,8 +1626,8 @@ fn updateInner(p: *Pardes, ev: Event) void { const hover_stays = switch (ev) { .tick, .search => true, .mouse => |m| m.button == .none and m.kind == .motion, - .output => |o| look.lookHoverPane(p) != o.pane, - .file_changed => |changed| look.lookHoverPane(p) != changed.pane, + .output => |o| look.lookHoverPane(p) != o.pane.index(), + .file_changed => |changed| look.lookHoverPane(p) != changed.pane.index(), else => false, }; if (!hover_stays) { @@ -1665,30 +1665,30 @@ fn updateInner(p: *Pardes, ev: Event) void { p.resize_count += 1; }, .output => |o| { - const pane = p.panes[o.pane] orelse return; + const pane = p.panes[o.pane.index()] orelse return; pane.shell_spoke = true; - ctlfs.events.notePtyOutput(p, o.pane, o.bytes); + ctlfs.events.notePtyOutput(p, o.pane.index(), o.bytes); pane.feedOutput(p, o.bytes); - ctlfs.pty.noteMarks(p, o.pane, pane); - exec.flushReplEnter(p, o.pane, true); + ctlfs.pty.noteMarks(p, o.pane.index(), pane); + exec.flushReplEnter(p, o.pane.index(), true); }, - .exited => |e| if (p.panes[e.pane]) |pane| { + .exited => |e| if (p.panes[e.pane.index()]) |pane| { if (pane.command == null) ctlfs.pty.shellExited(p, pane, e.status) else if (!pane.command_done) - pane.commandDone(p, e.pane, e.status); + pane.commandDone(p, e.pane.index(), e.status); }, - .eof => |e| if (p.panes[e.pane]) |pane| if (pane.command != null) { + .eof => |e| if (p.panes[e.pane.index()]) |pane| if (pane.command != null) { // Output is over; the command is over when its child exits. pane.command_pty = false; - } else p.removePane(e.pane, null) catch |err| { + } else p.removePane(e.pane.index(), null) catch |err| { pane.body.mode = .normal; - p.reportError(.at(e.pane), "terminal exited; Del retries close", err); + p.reportError(e.pane, "terminal exited; Del retries close", err); }, .lsp_resp => |r| @import("lsp/Ask.zig").lspResponse(p, r.id, r.rows), .pipe_resp => |r| Pipe.pipeResponse(p, r.id, r.success, r.outputs, r.failure), .search => |b| Stream.receive(p, &b), - .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane, fc.bytes), + .file_changed => |fc| _ = p.applyWatchedFileChanged(fc.pane.index(), fc.bytes), .key => |key| { p.can_ask = true; defer p.can_ask = false; @@ -1706,8 +1706,8 @@ fn updateInner(p: *Pardes, ev: Event) void { if (focused) if (p.host.vtable.newer_build) |f| if (f(p.host.ctx)) p.setMessage(.at(v.active), newer_build_words); }, .handed => |h| p.handover.finish(p, h.seq, h.to, h.failure), - .addon => |a| pardes.Addon.landed(p, a.op, a.pane, a.kind.*), - .job => |j| pardes.Kind.jobDone(p, j.pane, j.serial, j.token, j.gen, j.bytes), + .addon => |a| pardes.Addon.landed(p, a.op, a.pane.index(), a.kind.*), + .job => |j| pardes.Kind.jobDone(p, j.pane.index(), j.serial, j.token, j.gen, j.bytes), .frontend => |f| { v.frontend = f; }, @@ -1960,7 +1960,7 @@ pub fn sync(p: *Pardes) void { if (pane.isTerminal()) { pane.resizeGrid(cols, rows); p.shell_rows.markStale(pane); // reflow moved every row - p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } }); + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); pane.fs.winsize = null; } pane.cols = cols; @@ -1987,7 +1987,7 @@ pub fn sync(p: *Pardes) void { .wait => {}, .never => pane.greet = false, .now => { - p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = pane.cols, .rows = pane.rows } }); + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = pane.cols, .rows = pane.rows } }); p.emitWrite(id, "ls\r"); pane.greet = false; }, @@ -2333,7 +2333,8 @@ const FakeTtyQuery = struct { p.host = .{ .ctx = f, .vtable = &vtable }; } - fn answer(ctx: ?*anyopaque, pane: u8) bool { + fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + const pane = id.index(); const f: *FakeTtyQuery = @ptrCast(@alignCast(ctx.?)); f.asked += 1; return f.taken[pane]; @@ -2462,7 +2463,7 @@ test "pane-tag Exec prefers Term and argument builtins before shell fallback" { var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - try std.testing.expectEqual(@as(u8, 0), w.pane); + try std.testing.expectEqual(0, w.pane.index()); try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len); @memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice()); sent_len += w.bytes.slice().len; @@ -2684,7 +2685,7 @@ test "Term spawns a raw shell in the caller's directory" { var found = false; while (p.nextEffect()) |effect| switch (effect) { - .spawn => |s| if (@as(usize, s.pane) == free) { + .spawn => |s| if (s.pane.index() == free) { try std.testing.expectEqualStrings("/tmp/newtty-dir", s.cwd.slice()); found = true; }, @@ -2708,11 +2709,11 @@ test "a terminal respawned into a closed pane's slot hangs the old shell up firs var closed = false; var spawned = false; while (p.nextEffect()) |effect| switch (effect) { - .close_pty => |c| if (c.pane == slot) { + .close_pty => |c| if (c.pane.index() == slot) { try std.testing.expect(!spawned); closed = true; }, - .spawn => |s| if (s.pane == slot) { + .spawn => |s| if (s.pane.index() == slot) { spawned = true; }, else => {}, @@ -2784,7 +2785,7 @@ test "unknown Exec from a document runs as a command pane in its directory, type var spawned = false; while (p.nextEffect()) |effect| switch (effect) { .write => return error.TypedIntoATerminal, - .spawn => |sp| if (sp.pane == dst) { + .spawn => |sp| if (sp.pane.index() == dst) { try std.testing.expectEqualStrings("/tmp/pardes-image-dir", sp.cwd.slice()); spawned = true; }, @@ -2815,7 +2816,7 @@ test "Exec in a terminal whose tty is taken runs as a command pane instead of ty var spawned = false; while (p.nextEffect()) |effect| switch (effect) { .write => return error.WroteACommandLineIntoATerminal, - .spawn => |sp| if (sp.pane == dst) { + .spawn => |sp| if (sp.pane.index() == dst) { // ...in the directory the command was about, the taken pane's own try std.testing.expectEqualStrings("/tmp/pardes-taken", sp.cwd.slice()); spawned = true; @@ -2843,7 +2844,7 @@ test "a command of several lines keeps its tag one row, and its echo does not st var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); _ = try p.render(frame.allocator()); - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 0 } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 0 } }); _ = exec.execute(p, 1, two); while (p.nextEffect()) |_| {} _ = try p.render(frame.allocator()); @@ -2863,7 +2864,8 @@ test "a spawn is for the pane it was made for, not whatever took the slot since" var command: [32]u8 = undefined; var core: *Pardes = undefined; const vtable: Host.VTable = .{ .spawn = spawn }; - fn spawn(_: ?*anyopaque, pane: u8, _: []const u8) void { + fn spawn(_: ?*anyopaque, id: pardes.Pane.Id, _: []const u8) void { + const pane = id.index(); spawns += 1; const line = core.panes[pane].?.command.?; @memcpy(command[0..line.len], line); @@ -2901,8 +2903,8 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe spawned = false; while (pp.nextEffect()) |effect| switch (effect) { .write => |w| { - @memcpy(to[w.pane][len[w.pane]..][0..w.bytes.slice().len], w.bytes.slice()); - len[w.pane] += w.bytes.slice().len; + @memcpy(to[w.pane.index()][len[w.pane.index()]..][0..w.bytes.slice().len], w.bytes.slice()); + len[w.pane.index()] += w.bytes.slice().len; }, .spawn => spawned = true, else => {}, @@ -2960,12 +2962,12 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe try std.testing.expectEqualStrings("a = 1\rb = [201~2\r", Sent.said(1)); // Into a REPL that takes a bracketed paste (3.13's), the Enter waits // for the REPL to answer the paste: read with it, it would be part of it. - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004h" } }); Sent.drain(p); _ = exec.executeFrom(p, 0, "print(1)", true); Sent.drain(p); try std.testing.expectEqualStrings("\x1b[200~print(1)\x1b[201~", Sent.said(1)); - p.update(.{ .output = .{ .pane = 1, .bytes = "print(1)" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "print(1)" } }); Sent.drain(p); // Python's echo only restarts a short wait: the Enter goes once the // echo of the whole paste has gone quiet. @@ -2991,7 +2993,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe p.update(.tick); Sent.drain(p); try std.testing.expectEqualStrings("\r", Sent.said(1)); - p.update(.{ .output = .{ .pane = 1, .bytes = "\x1b[?2004l" } }); + p.update(.{ .output = .{ .pane = .at(1), .bytes = "\x1b[?2004l" } }); Sent.len[1] = 0; // A block left open by its indented last line gets the blank line that // ends it: a second Enter. @@ -3095,7 +3097,7 @@ test "a REPL bound for a language takes the exec made on a body in it; tags, Exe _ = try pardes.panes.newCommand(p, cmd, "", "python3"); try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python")); try std.testing.expect(p.panes[cmd].?.repl != null); - p.update(.{ .exited = .{ .pane = @intCast(cmd), .status = 0 } }); + p.update(.{ .exited = .{ .pane = .at(cmd), .status = 0 } }); try std.testing.expect(p.panes[cmd].?.repl == null); try std.testing.expect(p.executeBuiltinLine(cmd, "Repl python")); try std.testing.expect(p.panes[cmd].?.repl == null); @@ -3203,32 +3205,32 @@ test "a command pane shows how its command ended, and the next command there run const other = exec.execute(p, 1, "ls") orelse return error.NoCommandPane; try std.testing.expect(other != dst); while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "compiled\r\n" } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "compiled\r\n" } }); // Its exit comes first, a job it left still printing: done, and not // the next command's until its pty closes. - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); try std.testing.expect(pane.command_done and pane.command_pty); const busy = exec.execute(p, 1, "true") orelse return error.NoCommandPane; try std.testing.expect(busy != dst); while (p.nextEffect()) |_| {} // Its output ending: now it may be reused. - p.update(.{ .eof = .{ .pane = @intCast(dst) } }); + p.update(.{ .eof = .{ .pane = .at(dst) } }); try std.testing.expect(p.panes[dst] == pane and !pane.command_pty); try std.testing.expect(p.panes[dst] == pane); try std.testing.expect(pane.command_done); try std.testing.expect(std.mem.endsWith(u8, try tagline.tagPrefix(p, pane), "(make -j8) exit 2")); // Kill leaves a finished one be. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); - while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) return error.SignalledAFinishedCommand; + while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) return error.SignalledAFinishedCommand; // A program that crashed out of its full screen leaves the emulator // in its modes; the next command starts clear of them. - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "\x1b[?1049h\x1b[?2004h\x1b[?1000h" } }); try std.testing.expect(pardes.Term.modes(pane.terminal).bracketed_paste); // Done, the directory's next command runs there, below what it showed. try std.testing.expectEqual(@as(?usize, dst), exec.execute(p, 1, "make test")); try std.testing.expect(!pardes.Term.modes(pane.terminal).bracketed_paste); var respawned = false; - while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane == dst) { + while (p.nextEffect()) |effect| if (effect == .spawn and effect.spawn.pane.index() == dst) { respawned = true; }; try std.testing.expect(respawned); @@ -3242,7 +3244,7 @@ test "a command pane shows how its command ended, and the next command there run // Kill stops a running one: its whole process group, SIGTERM. try std.testing.expect(p.executeBuiltinLine(0, "Kill make")); var signalled = false; - while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane == dst) { + while (p.nextEffect()) |effect| if (effect == .signal_pty and effect.signal_pty.pane.index() == dst) { try std.testing.expectEqual(PtySignal.term, effect.signal_pty.sig); signalled = true; }; @@ -3260,7 +3262,7 @@ test "a command pane shows how its command ended, and the next command there run const Count = struct { var signals: usize = 0; const vtable: Host.VTable = .{ .pty_signal = signal }; - fn signal(_: ?*anyopaque, _: u8, _: PtySignal) void { + fn signal(_: ?*anyopaque, _: pardes.Pane.Id, _: PtySignal) void { signals += 1; } }; @@ -3300,7 +3302,7 @@ test "a terminal its program gave back takes command lines again" { var sent_len: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - try std.testing.expectEqual(@as(u8, 0), w.pane); + try std.testing.expectEqual(0, w.pane.index()); try std.testing.expect(w.bytes.slice().len <= sent.len - sent_len); @memcpy(sent[sent_len..][0..w.bytes.slice().len], w.bytes.slice()); sent_len += w.bytes.slice().len; @@ -3360,7 +3362,7 @@ test "a host with no methods at all is a complete in-process pardes" { // the absent child is SILENT: the bytes are dropped, and nothing appears // on the pane's screen to suggest a program answered const before = pardes.Term.grid(p.panes[0].?.terminal).cursor_y; - p.perform(.{ .write = .{ .pane = 0, .bytes = .from("ls\r") } }); + p.perform(.{ .write = .{ .pane = .at(0), .bytes = .from("ls\r") } }); try std.testing.expectEqual(before, pardes.Term.grid(p.panes[0].?.terminal).cursor_y); // the clipboard round-trips through the in-process one @@ -3374,11 +3376,11 @@ test "a host with no methods at all is a complete in-process pardes" { for (p.panes, 0..) |slot, i| if (slot == doc) { doc_id = @intCast(i); }; - p.perform(.{ .save_file = .{ .pane = doc_id } }); + p.perform(.{ .save_file = .{ .pane = .at(doc_id) } }); try std.testing.expectEqualStrings("body\n", p.fallback.files.get(doc.file.?.path).?); // a language backend nobody supplied answers nothing rather than hanging - p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = doc_id, .offset = 0, .arg = .{} } }); + p.perform(.{ .lsp = .{ .id = 7, .kind = .hover, .pane = .at(doc_id), .offset = 0, .arg = .{} } }); p.perform(.quit); try std.testing.expect(p.quit); @@ -3775,7 +3777,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .tty; - p.update(.{ .output = .{ .pane = 0, .bytes = "abc" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abc" } }); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const visible = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; @@ -3784,7 +3786,7 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" try std.testing.expectEqual(rect.x + config.GUTTER + 3, visible.x); try std.testing.expectEqual(body_y, visible.y); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } }); try std.testing.expect((try p.render(frame.allocator())).cursor == null); pane.body.mode = .normal; pane.body.cur_pinned = true; @@ -3800,13 +3802,13 @@ test "raw terminal cursor obeys visibility without hiding modal and tag cursors" pane.body.mode = .tty; try std.testing.expect((try p.render(frame.allocator())).cursor == null); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25h\x1b[?1049h\x1b[2;5H" } }); const alternate = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(rect.x + config.GUTTER + 4, alternate.x); try std.testing.expectEqual(body_y + 1, alternate.y); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?25l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?25l" } }); try std.testing.expect((try p.render(frame.allocator())).cursor == null); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1049l\x1b[?25h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049l\x1b[?25h" } }); const returned = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; try std.testing.expectEqual(visible.x, returned.x); try std.testing.expectEqual(visible.y, returned.y); @@ -3820,8 +3822,8 @@ test "raw terminal cursor follows its active row only while that row is visible" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; pane.body.mode = .tty; - for (0..60) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "row\r\n" } }); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3;4H" } }); + for (0..60) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "row\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3;4H" } }); var frame = std.heap.ArenaAllocator.init(gpa); defer frame.deinit(); const live = (try p.render(frame.allocator())).cursor orelse return error.MissingCursor; @@ -3881,7 +3883,7 @@ test "tty output follows only from the bottom" { for (0..60) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); const bottom = pardes.Term.grid(sp.terminal).offset; @@ -3894,7 +3896,7 @@ test "tty output follows only from the bottom" { try std.testing.expect(parked < bottom); for (60..70) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); try std.testing.expectEqual(parked, pardes.Term.grid(sp.terminal).offset); @@ -3906,7 +3908,7 @@ test "tty output follows only from the bottom" { // ...and from there output follows again. const live = pardes.Term.grid(sp.terminal).offset; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = "tail\r\n" } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = "tail\r\n" } }); p.sync(); try std.testing.expect(pardes.Term.grid(sp.terminal).offset > live); } @@ -3976,7 +3978,7 @@ test "a bracketed paste larger than the ring still closes its bracket" { _ = test_api.ptyBytes(p, null, buf); pardes.keys.enterTty(p, 0); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); try std.testing.expect(pardes.Term.modes(p.panes[0].?.terminal).bracketed_paste); const text = try gpa.alloc(u8, 1536 * 1024); defer gpa.free(text); @@ -4007,7 +4009,7 @@ test "a terminal's answer to its program waits behind the paste still queued for // host takes one write off, and the program asks where its cursor is. const taken = p.nextEffect().?; const off = if (taken == .write) taken.write.bytes.len else 0; - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[6n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[6n" } }); const got = test_api.ptyBytes(p, null, buf); // The whole paste first, then the answer, `CSI row ; col R`, whole. try std.testing.expectEqualSlices(u8, text[off..], got[0 .. text.len - off]); @@ -4047,7 +4049,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { // Exactly what an OSC 133 shell draws: prompt, then the marker that says // the rest of this row is the user's, then what they typed. One grid row. p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\grep -rn TODO src/", } }); p.sync(); @@ -4091,7 +4093,7 @@ test "leaving tty hides the prompt and keeps the command typed at it" { // ...and a prompt with nothing typed at it yet is all chrome, so the whole // row goes, which is what it has always done. p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\r\n\x1b]133;A\x1b\\user@box ~/src $ \x1b]133;B\x1b\\", } }); p.sync(); @@ -4109,7 +4111,7 @@ test "entering tty walks the shell cursor to the column clicked past the prompt" const shell = p.view().active; const sp = p.panes[shell].?; p.update(.{ .output = .{ - .pane = @intCast(shell), + .pane = .at(shell), .bytes = "\x1b]133;A;cl=line\x1b\\prompt> \x1b]133;B\x1b\\0123456789", } }); p.sync(); diff --git a/core/Effect.zig b/core/Effect.zig index f0e18335..7166294f 100644 --- a/core/Effect.zig +++ b/core/Effect.zig @@ -37,29 +37,29 @@ pub const Effect = union(enum) { /// A child for the pane in slot `pane` -- the one whose serial is /// `serial`: a pane closed and its slot taken before the effect is /// performed is not the one it was for (perform). - spawn: struct { pane: u8, serial: u32, cwd: Buf(effect_path_cap) }, - write: struct { pane: u8, bytes: Buf(effect_write_cap) }, - resize_pty: struct { pane: u8, cols: u16, rows: u16 }, + spawn: struct { pane: Pane.Id, serial: u32, cwd: Buf(effect_path_cap) }, + write: struct { pane: Pane.Id, bytes: Buf(effect_write_cap) }, + resize_pty: struct { pane: Pane.Id, cols: u16, rows: u16 }, /// For the pane whose serial is `serial`, as `spawn` is (perform). - signal_pty: struct { pane: u8, serial: u32, sig: PtySignal }, + signal_pty: struct { pane: Pane.Id, serial: u32, sig: PtySignal }, /// The terminal pane in this slot is gone: the shell hangs up its pty /// and ends the shell, rather than leave it running with nobody to read. - close_pty: struct { pane: u8 }, + close_pty: struct { pane: Pane.Id }, open_link: Buf(256), /// A program a plumbing rule starts (Plumb.run): its directory, then /// its argv, each ended by a NUL. A failure to start it is said at /// pane `pane`. - start: struct { pane: u8, line: Buf(effect_path_cap) }, + start: struct { pane: Pane.Id, line: Buf(effect_path_cap) }, /// write this pane's file content to its path; the shell reads both off /// the core (content is unbounded, effects are fixed-size values) - save_file: struct { pane: u8 }, - save_text: struct { pane: u8, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, + save_file: struct { pane: Pane.Id }, + save_text: struct { pane: Pane.Id, serial: u32, path: Buf(effect_path_cap), promote: bool = false }, write_dump, set_clipboard, read_clipboard, /// `arg` up to 128 bytes, or for `explain` the query it explains, /// `<kind> <arg>`. - lsp: struct { id: u32, kind: lsp.Kind, pane: u8, offset: u32, arg: Buf(160) }, + lsp: struct { id: u32, kind: lsp.Kind, pane: Pane.Id, offset: u32, arg: Buf(160) }, /// Snapshot the matching request with pipeRequest(id), then run it away /// from the UI/event loop and answer with pipe_resp. pipe: struct { id: u32 }, @@ -71,19 +71,19 @@ pub const Effect = union(enum) { hand_over: struct { seq: u32 }, /// Write what an Edit's `w` took (`Pipe.writes`), in order. edit_write, - watch: struct { pane: u8, on: bool, mode: WatchMode = .reconcile }, + watch: struct { pane: Pane.Id, on: bool, mode: WatchMode = .reconcile }, theme_file: struct { generation: u32, on: bool }, /// Write the build-time theme ring below the per-user config directory. /// The pane receives the completion/error message from the native host. - dump_themes: struct { pane: u8 }, - detach: struct { pane: u8 }, + dump_themes: struct { pane: Pane.Id }, + detach: struct { pane: Pane.Id }, /// An addon loaded, let go, or let go and loaded again (Addon.zig): /// `arg` its path, or for unload its kind's name. Answered by an /// `addon` event. - addon: struct { op: @import("Addon.zig").Op, pane: u8, arg: Buf(effect_path_cap) }, + addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, arg: Buf(effect_path_cap) }, /// A kind's job for the host's workers (host_io.Job), answered by a /// `job` event. - job: struct { pane: u8, serial: u32, token: u32 }, + job: struct { pane: Pane.Id, serial: u32, token: u32 }, quit, pub fn Buf(comptime n: usize) type { @@ -120,8 +120,8 @@ fn performInner(p: *Pardes, e: Effect) void { switch (e) { // The host reads the pane (its command, its shell) as it forks, // so the slot must still hold the pane the spawn was for. - .spawn => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane] orelse "") else s.cwd.slice()) else { - p.fallback.spawned[s.pane] = true; + .spawn => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.spawn) |f| f(p.host.ctx, s.pane, if (s.cwd.len == 0) (p.spawn_dirs[s.pane.index()] orelse "") else s.cwd.slice()) else { + p.fallback.spawned[s.pane.index()] = true; }, // A pane with no child is silent: nothing invents output on its // screen, and the bytes are dropped rather than transcribed. @@ -129,7 +129,7 @@ fn performInner(p: *Pardes, e: Effect) void { .resize_pty => |r| if (v.pty_resize) |f| f(p.host.ctx, r.pane, r.cols, r.rows), // A signal for a pane that closed, its slot retaken in the same // step, would reach another pane's child. - .signal_pty => |s| if (if (p.panes[s.pane]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), + .signal_pty => |s| if (if (p.panes[s.pane.index()]) |pane| pane.serial != s.serial else true) {} else if (v.pty_signal) |f| f(p.host.ctx, s.pane, s.sig), .close_pty => |c| if (v.close_pty) |f| f(p.host.ctx, c.pane), // The view's frontend opens it, yanks and pastes, on its own // machine (View.yanks); the host here only for a view no client @@ -149,17 +149,17 @@ fn performInner(p: *Pardes, e: Effect) void { _ = words.next(); // its directory const prog = words.next() orelse ""; var said: pardes.Kind.Buf(160) = .{}; - p.reportFailure(st.pane, said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); + p.reportFailure(st.pane.index(), said.print("plumb start: {s}: {s}", .{ prog[0..@min(64, prog.len)], w })); }, .save_file => |sf| { - const pane = p.panes[sf.pane] orelse return; + const pane = p.panes[sf.pane.index()] orelse return; const f = if (pane.file) |*file| file else return; const was = f.saved_revision; f.saved_revision = f.revision; // A save the host could not do (saveFailed) is its err // record alone, not a `save`, and changes nothing: a clean // file stays clean. - const saved_pane = writeChecked(p, sf.pane, pane.serial, f.path, f.content, was) orelse return; + const saved_pane = writeChecked(p, sf.pane.index(), pane.serial, f.path, f.content, was) orelse return; const saved = if (saved_pane.file) |*file| file else return; // Edited while it was written: what is on disk is not this. if (saved.saved_revision != saved.revision) return; @@ -174,19 +174,19 @@ fn performInner(p: *Pardes, e: Effect) void { p.emit(.{ .watch = .{ .pane = sf.pane, .on = true } }); }, .save_text => |st| { - const pane = p.panes[st.pane] orelse return; + const pane = p.panes[st.pane.index()] orelse return; if (pane.serial != st.serial) return; // a recycled slot: not ours if (pane.file) |*f| { // Failed, it changes nothing: not the name, not dirty. - const after = writeChecked(p, st.pane, st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; + const after = writeChecked(p, st.pane.index(), st.serial, st.path.slice(), f.content, f.saved_revision) orelse return; if (after.file == null) return; - if (st.promote) promoteSaved(p, st.pane, st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); + if (st.promote) promoteSaved(p, st.pane.index(), st.path.slice()) else ctlfs.events.noteLogAs(p, .save, after, st.path.slice()); return; } if (!pane.isTerminal()) return; - const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(.at(st.pane), "Save", err); + const text = pardes.Term.scrollback(pane.terminal, p.gpa) catch |err| return p.reportError(st.pane, "Save", err); defer p.gpa.free(text); - if (writeChecked(p, st.pane, st.serial, st.path.slice(), text, 0)) |still| + if (writeChecked(p, st.pane.index(), st.serial, st.path.slice(), text, 0)) |still| ctlfs.events.noteLogAs(p, .save, still, st.path.slice()); }, .write_dump => { @@ -249,22 +249,22 @@ fn performInner(p: *Pardes, e: Effect) void { }, .watch => |w| if (v.watch_file) |f| { // What a watch is about: a real file, or a kind's (a PDF's). - const path: []const u8 = if (p.panes[w.pane]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; + const path: []const u8 = if (p.panes[w.pane.index()]) |pane| (if (pane.file) |file| (if (file.output == null) file.path else "") else if (pane.addon) |k| k.path else "") else ""; f(p.host.ctx, w.pane, path, w.on, w.mode); } else { - p.fallback.watched[w.pane] = w.on; + p.fallback.watched[w.pane.index()] = w.on; }, .theme_file => |t| if (v.watch_theme) |f| f(p.host.ctx, t.generation, t.on), .dump_themes => |d| if (v.dump_themes) |f| f(p.host.ctx, d.pane), .detach => |d| if (v.detach) |f| f(p.host.ctx) else - p.reportError(.at(d.pane), "detach", error.NotAttached), + p.reportError(d.pane, "detach", error.NotAttached), // dlopen is the same on every host, so none has a method of its // own; a replica's core holds no library (what it brought comes in // the event this taped). - .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane, a.arg.slice()), - .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane, j.serial, j.token), + .addon => |a| if (!tape.replaying()) @import("Addon.zig").perform(p, a.op, a.pane.index(), a.arg.slice()), + .job => |j| if (v.job) |f| f(p.host.ctx, j.pane, j.serial, j.token) else if (!tape.replaying()) host_io.KindJob.runHere(p, j.pane.index(), j.serial, j.token), // the loop's own condition; a host tears down after its own loop .quit => p.endSession(), } @@ -282,7 +282,7 @@ pub fn writeChecked(p: *Pardes, id: u8, serial: u32, path: []const u8, bytes: [] if (filesystem.localPath(path)) |local| filesystem.makeDirs(p.tape, std.Io.Dir.path.dirname(local) orelse "/"); // The in-process filesystem reports the same way a real host does, // so an OOM there leaves the pane dirty rather than looking saved. - if (p.host.vtable.write_file) |f| f(p.host.ctx, id, path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); + if (p.host.vtable.write_file) |f| f(p.host.ctx, .at(id), path, bytes) else if (!p.fallback.writeFile(path, bytes)) p.saveFailed(.at(id), path, error.OutOfMemory); const pane = p.panes[id] orelse return null; if (pane.serial != serial) return null; if (p.fs.failures == failures) return pane; @@ -312,7 +312,7 @@ fn promoteSaved(p: *Pardes, id: u8, path: []const u8) void { ctlfs.events.noteLog(p, .save, pane); p.recent.opened(p.recentGpa(), f.path); if (filesystem.localPath(f.path) != null) - p.emit(.{ .watch = .{ .pane = id, .on = true } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } fn drainForSavePath(p: *Pardes, buf: []u8) ?[]const u8 { @@ -343,7 +343,7 @@ test "Detach asks the host to let its terminal go, and says so when there is not .detach => |d| break d, else => {}, } else return error.NoDetachAsked; - try std.testing.expectEqual(@as(u8, 0), asked.pane); + try std.testing.expectEqual(0, asked.pane.index()); p.perform(.{ .detach = asked }); const pane = p.panes[0].?; @@ -376,7 +376,7 @@ test "Save on a scratch asks for a path in its inherited dir and makes it a file // The write asked for, the pane is the file once it is done. var saved = false; while (p.nextEffect()) |effect| { - if (effect == .save_text and @as(usize, effect.save_text.pane) == id) saved = true; + if (effect == .save_text and effect.save_text.pane.index() == id) saved = true; p.perform(effect); } try std.testing.expect(saved); @@ -392,7 +392,7 @@ test "Save on a terminal writes its plaintext scrollback and stays a terminal" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-tty-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "hello scrollback\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello scrollback\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(p.executeBuiltinLine(0, "Save")); @@ -474,7 +474,7 @@ test "Save takes the path as an argument, relative to the pane's own directory" while (p.nextEffect()) |_| {} const pane = p.panes[0].?; p.setCwd(.at(0), "/tmp/pardes-arg-save"); - p.update(.{ .output = .{ .pane = 0, .bytes = "typed and gone\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "typed and gone\r\n" } }); while (p.nextEffect()) |_| {} var buf: [256]u8 = undefined; @@ -510,9 +510,9 @@ test "Save takes the path as an argument, relative to the pane's own directory" test "a save the host could not do leaves the pane dirty" { const gpa = std.testing.allocator; const Refusing = struct { - fn writeFile(ctx: ?*anyopaque, pane: u8, _: []const u8, _: []const u8) void { + fn writeFile(ctx: ?*anyopaque, id: pardes.Pane.Id, _: []const u8, _: []const u8) void { const core: *Pardes = @ptrCast(@alignCast(ctx.?)); - core.saveFailed(.at(pane), "/x/y.txt", error.PermissionDenied); + core.saveFailed(id, "/x/y.txt", error.PermissionDenied); } }; const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 }); @@ -577,7 +577,7 @@ test "saves armed in one batch stay with their own panes" { const tty_id = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(tty_id, "/tmp/pardes-batch"); p.setCwd(.at(tty_id), "/tmp/pardes-batch"); - p.update(.{ .output = .{ .pane = @intCast(tty_id), .bytes = "shell text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(tty_id), .bytes = "shell text\r\n" } }); const file = try p.setTestFile("file text\n"); const file_id = panes.paneIdOf(p, file) orelse return error.MissingFilePane; try std.testing.expect(shell.isTerminal()); @@ -606,7 +606,7 @@ test "a save whose pane is gone before the drain writes nothing" { const doomed = p.freeSlot() orelse return error.NoPaneSlots; const shell = try p.newShell(doomed, "/tmp/pardes-gone"); - p.update(.{ .output = .{ .pane = @intCast(doomed), .bytes = "doomed text\r\n" } }); + p.update(.{ .output = .{ .pane = .at(doomed), .bytes = "doomed text\r\n" } }); while (p.nextEffect()) |_| {} try std.testing.expect(shell.isTerminal()); @@ -687,19 +687,19 @@ test "a Save the host could not do logs no save record" { const Failing = struct { core: *Pardes, const vtable: Host.VTable = .{ .write_file = write }; - fn write(ctx: ?*anyopaque, pane: u8, path: []const u8, _: []const u8) void { + fn write(ctx: ?*anyopaque, id: pardes.Pane.Id, path: []const u8, _: []const u8) void { const f: *@This() = @ptrCast(@alignCast(ctx.?)); - f.core.saveFailed(.at(pane), path, error.AccessDenied); + f.core.saveFailed(id, path, error.AccessDenied); } }; var host: Failing = .{ .core = p }; p.host = .{ .ctx = &host, .vtable = &Failing.vtable }; _ = th.wr(p, ctlfs.Node.of(p.panes[0].?.serial, .body), "more\n"); - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(!th.logHas(p, "\nsave ")); try std.testing.expect(p.panes[0].?.file.?.saved_revision != p.panes[0].?.file.?.revision); // With the host's write done, it is logged. p.host = .{}; - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try std.testing.expect(th.logHas(p, "\nsave ")); } diff --git a/core/Event.zig b/core/Event.zig index faea73cc..9988eede 100644 --- a/core/Event.zig +++ b/core/Event.zig @@ -3,6 +3,7 @@ const config = @import("config.zig"); const selection_pipe = @import("selection_pipe.zig"); const Stream = @import("Stream.zig"); +const Pane = @import("panes.zig").Pane; const Layer = @import("Layer.zig"); const RowMetrics = Layer.Metrics; const TagHit = Layer.TagHit; @@ -78,14 +79,14 @@ pub const Event = union(enum) { cell_pixels: CellPixels = .{}, row_metrics: ?RowMetrics = null, }, - output: struct { pane: u8, bytes: []const u8 }, + output: struct { pane: Pane.Id, bytes: []const u8 }, /// The pane's pty reached end of file: its output is over. An /// interactive terminal closes; a command pane waits for `exited`. - eof: struct { pane: u8, status: ?u8 = null }, + eof: struct { pane: Pane.Id, status: ?u8 = null }, /// A command pane's child exited, with this status (null: unknown). It /// is the command's end, whatever still holds its pty (a job it left in /// the background prints on until end of file). - exited: struct { pane: u8, status: ?u8 }, + exited: struct { pane: Pane.Id, status: ?u8 }, lsp_resp: struct { id: u32, rows: ?[]const u8 }, pipe_resp: struct { id: u32, @@ -93,7 +94,7 @@ pub const Event = union(enum) { outputs: []const []const u8, failure: ?selection_pipe.Failure = null, }, - file_changed: struct { pane: u8, bytes: []const u8 }, + file_changed: struct { pane: Pane.Id, bytes: []const u8 }, /// A disk search's batch (Stream.zig), borrowed for the step. search: Stream.Batch, paste: []const u8, @@ -112,10 +113,10 @@ pub const Event = union(enum) { frontend: Frontend, /// What the host's `addon` effect read off a library, or why not /// (Addon.landed). Borrowed for the step. - addon: struct { op: @import("Addon.zig").Op, pane: u8, kind: *const @import("Kind.zig").Loaded }, + addon: struct { op: @import("Addon.zig").Op, pane: Pane.Id, kind: *const @import("Kind.zig").Loaded }, /// A kind's job answered (host_io.Job), at its kind's generation then. /// Borrowed for the step. - job: struct { pane: u8, serial: u32, token: u32, gen: u32, bytes: []const u8 }, + job: struct { pane: Pane.Id, serial: u32, token: u32, gen: u32, bytes: []const u8 }, tick, }; diff --git a/core/File.zig b/core/File.zig index 8337b833..c336b1b8 100644 --- a/core/File.zig +++ b/core/File.zig @@ -581,13 +581,13 @@ pub fn open(p: *Pardes, id: usize, path: []const u8, line: usize) !*Pane { pane.body.cur_pinned = true; pane.body.cur_row = @intCast(scroll); p.installPane(id, pane); - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return pane; } pub fn deinit(p: *Pardes, pane: *Pane, file: *State) void { if (file.output == null) for (p.panes, 0..) |slot, id| { - if (slot == pane) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); + if (slot == pane) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); }; // A twin's text, undo and shared index stay with the twins left. var twins: [pardes.MAX_PANES]usize = undefined; @@ -991,7 +991,7 @@ pub fn zerox(p: *Pardes, from: usize, to: usize) !*Pane { pane.body.cur_row = src.body.cur_row; pane.body.cur_col = src.body.cur_col; pane.body.cur_pinned = true; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(to), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(to), .on = true } }); return pane; } @@ -1296,7 +1296,7 @@ fn restoreName(p: *Pardes, pane: *Pane, f: *State, snap: Text.Place) void { f.saved_revision = if (snap.clean) f.revision else f.revision -% 1; f.disk_newer = null; f.disk_newer_warned = false; - if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } pub fn restoreSnap(tab: u16, pane: *Pane, f: *State, snap: Text.Place) void { diff --git a/core/Jump.zig b/core/Jump.zig index 26b3c4d9..66dbd2b6 100644 --- a/core/Jump.zig +++ b/core/Jump.zig @@ -404,11 +404,11 @@ test "jump history terminal rectangle follows output and clears on reflow" { const p = try Pardes.init(std.testing.allocator, .{ .cols = 60, .rows = 12, .tty_only = true }); defer p.deinit(); const pane = p.panes[0].?; - p.update(.{ .output = .{ .pane = 0, .bytes = "alpha bravo\r\nsecond line\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "alpha bravo\r\nsecond line\r\n" } }); pane.sel[0] = .{ .state = .done, .c0 = 0, .c1 = 4, .r0 = BOX_H, .r1 = BOX_H }; try edit.capturePointerSelection(p, pane, 0); try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0])); - for (0..40) |_| p.update(.{ .output = .{ .pane = 0, .bytes = "more output\r\n" } }); + for (0..40) |_| p.update(.{ .output = .{ .pane = .at(0), .bytes = "more output\r\n" } }); try std.testing.expectEqualStrings("alpha", try edit.selectionText(p, pane, pane.sel[0])); pane.resizeGrid(pane.cols - 1, pane.rows); try std.testing.expect(pane.pointerSelection(pane.sel[0]) == null); diff --git a/core/Kind.zig b/core/Kind.zig index 05a813f3..7641c2d1 100644 --- a/core/Kind.zig +++ b/core/Kind.zig @@ -278,7 +278,7 @@ pub fn open(p: *Pardes, id: usize, k: u8, path: ?[]const u8, bytes: ?[]const u8) _ = reopen(p, id, s, bytes); // Its file watched, as a text's is: changed on disk, it opens again // from it (fileChanged); retirePane lets the watch go. - if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (s.path.len > 0 and @import("fs.zig").localPath(s.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return pane; } @@ -995,7 +995,7 @@ const Call = struct { for (o.jobs) |token| if (token != 0) { cl.slot.tokens = token; }; - if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } }); + if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = .at(cl.id), .serial = pane.serial, .token = token } }); for (o.cancels) |token| if (token != 0) { for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) { cl.slot.gpa.free(job.in); diff --git a/core/Plumb.zig b/core/Plumb.zig index 406e7dd8..aeebfc64 100644 --- a/core/Plumb.zig +++ b/core/Plumb.zig @@ -969,7 +969,7 @@ fn run(p: *Pardes, id: usize, wdir: []const u8, argv: []const []const u8) ?[]con start.data[start.len + w.len] = 0; start.len += @intCast(w.len + 1); }; - p.emit(.{ .start = .{ .pane = @intCast(id), .line = start } }); + p.emit(.{ .start = .{ .pane = .at(id), .line = start } }); return null; } diff --git a/core/Query.zig b/core/Query.zig index 784e6af4..dacc11a1 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1756,7 +1756,7 @@ fn promote(p: *Pardes, qid: usize, id: usize) void { f.syntax_dirty = true; pane.attached_to = null; if (f.on_disk) p.recent.opened(p.recentGpa(), f.path); - if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (filesystem.localPath(f.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); pardes.ctlfs.events.noteLog(p, .rename, pane); p.panes[qid].?.query.?.preview = 0; } diff --git a/core/builtins.zig b/core/builtins.zig index ca13bd59..6f37e86d 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -447,7 +447,7 @@ pub const Kill = struct { // the marks say is running is the one signalled, not whatever // runs by then. if (command != null) { - c.p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = .term } }); + c.p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = .term } }); stopped = true; } else if (c.p.hostKillJob(id)) stopped = true else jobless = true; } @@ -537,7 +537,7 @@ pub const Detach = struct { pub const scope: Scope = .session; pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { - c.p.emit(.{ .detach = .{ .pane = @intCast(c.id) } }); + c.p.emit(.{ .detach = .{ .pane = .at(c.id) } }); } }; @@ -548,7 +548,7 @@ pub const Adopt = struct { pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { const adopt = c.p.host.vtable.adopt orelse return c.p.reportFailure(c.id, "Adopt: no pardes daemon is keeping shells for this session"); - adopt(c.p.host.ctx, @intCast(c.id)); + adopt(c.p.host.ctx, .at(c.id)); } }; @@ -560,7 +560,7 @@ pub const Upgrade = struct { pub const enabled = pardes.can_attach; pub fn run(c: Ctx) void { const upgrade = c.p.host.vtable.upgrade orelse return c.p.reportFailure(c.id, "Upgrade: this pardes cannot move to another build in place"); - upgrade(c.p.host.ctx, @intCast(c.id)); + upgrade(c.p.host.ctx, .at(c.id)); } }; @@ -682,7 +682,7 @@ pub const DumpThemes = struct { c.p.reportError(.at(c.id), "dump themes", error.NoConfigDirectory); return; } - c.p.emit(.{ .dump_themes = .{ .pane = @intCast(c.id) } }); + c.p.emit(.{ .dump_themes = .{ .pane = .at(c.id) } }); } }; @@ -2011,7 +2011,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc const term = p.view().active; try std.testing.expect(p.panes[term].?.isTerminal()); const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = prompt } }); while (p.nextEffect()) |_| {} // The host the core asks: how many it was asked to stop, and whether // their shells run jobs in groups of their own. @@ -2019,7 +2019,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc var asked: usize = 0; var job_control = true; const vtable: pardes.Host.VTable = .{ .kill_job = answer }; - fn answer(_: ?*anyopaque, _: u8) bool { + fn answer(_: ?*anyopaque, _: pardes.Pane.Id) bool { asked += 1; return job_control; } @@ -2037,7 +2037,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc while (p.nextEffect()) |_| {} // Typed but not started yet (no C mark): not running. try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill")); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;C;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;C;aid=pardes\x07" } }); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill ls")); try std.testing.expectEqual(@as(usize, 1), killed.count(p, "Kill ls make")); @@ -2053,7 +2053,7 @@ test "Kill stops the commands pardes typed, bare all and by name those that matc p.fs.failure_len = 0; killed.job_control = true; // Ended (a D mark): nothing to stop again. - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;D;143;aid=pardes\x07" ++ prompt } }); while (p.nextEffect()) |_| {} try std.testing.expectEqual(@as(usize, 0), killed.count(p, "Kill")); } diff --git a/core/dump.zig b/core/dump.zig index 3b5ed421..1616f557 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -651,7 +651,7 @@ fn reviveSession(p: *Pardes, previous: ?*Pardes, resumed: bool) !void { /// the addon's). fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool) void { if (pane.addon) |slot| { - if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (slot.path.len > 0 and filesystem.localPath(slot.path) != null) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); return reviveSlot(p, id, slot); } if (pane.terminal != null) { @@ -690,7 +690,7 @@ fn revivePane(p: *Pardes, id: usize, pane: *pardes.panes.Pane, was_on_disk: bool f.content = text; } else |_| {} } - p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); // Its file gone from disk since the dump: its text is nowhere else, so // it is said deleted, and Del, Exit and Restore ask first. One never on // disk (a name not yet saved) comes back as it was. diff --git a/core/echo.zig b/core/echo.zig index 90dcfede..40200696 100644 --- a/core/echo.zig +++ b/core/echo.zig @@ -564,7 +564,7 @@ const Rig = struct { written: std.ArrayListUnmanaged(u8) = .empty, now: u64 = 1_000 * ms, - fn ptyWrite(ctx: ?*anyopaque, _: u8, bytes: []const u8) void { + fn ptyWrite(ctx: ?*anyopaque, _: pardes.Pane.Id, bytes: []const u8) void { const g: *Rig = @ptrCast(@alignCast(ctx.?)); g.written.appendSlice(testing.allocator, bytes) catch {}; } @@ -601,7 +601,7 @@ const Rig = struct { /// The shell prints `bytes`; the replica gets the unit and the delta. fn prints(g: *Rig, bytes: []const u8) !void { - g.a.output(.{ .output = .{ .pane = g.shell, .bytes = bytes } }); + g.a.output(.{ .output = .{ .pane = .at(g.shell), .bytes = bytes } }); try g.sync(); } diff --git a/core/edit.zig b/core/edit.zig index 214e83a8..0014f681 100644 --- a/core/edit.zig +++ b/core/edit.zig @@ -2352,7 +2352,7 @@ test "flat text replacement preserves a terminal fragment origin and direction" if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 60, .rows = 12 }); defer p.deinit(); - p.update(.{ .output = .{ .pane = 0, .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "first\r\nsecond\r\nthird\r\n界a\r\n" } }); const pane = p.panes[0].?; pane.body.mode = .normal; pane.body.cur_pinned = true; @@ -2487,7 +2487,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont fn f(pp: *Pardes, o: *std.ArrayList(u8)) ![]const u8 { o.clearRetainingCapacity(); while (pp.nextEffect()) |effect| { - if (effect == .write and effect.write.pane == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice()); + if (effect == .write and effect.write.pane.index() == 0) try o.appendSlice(pp.gpa, effect.write.bytes.slice()); } return o.items; } @@ -2496,7 +2496,7 @@ test "a paste into a terminal is xterm's: bracketed when the program asked, cont try std.testing.expectEqual(.tty, p.panes[0].?.body.mode); p.update(.{ .paste = "echo a\nb\x03\tc" }); try std.testing.expectEqualStrings("echo a\rb \tc", try take(p, &out)); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?2004h" } }); _ = try take(p, &out); p.update(.{ .paste = "x\x1b[201~y\n" }); try std.testing.expectEqualStrings("\x1b[200~x [201~y\n\x1b[201~", try take(p, &out)); diff --git a/core/exec.zig b/core/exec.zig index 6a8ef6d8..687faa98 100644 --- a/core/exec.zig +++ b/core/exec.zig @@ -322,7 +322,7 @@ pub fn saveFile(p: *Pardes, id: usize) void { } f.disk_newer = null; } - p.emit(.{ .save_file = .{ .pane = @intCast(id) } }); + p.emit(.{ .save_file = .{ .pane = .at(id) } }); } pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { @@ -347,7 +347,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { // Save that fails changes nothing, the name included. if (f.output != null and panes.Output.fileTraits(f.output).saves) { p.emit(.{ .save_text = .{ - .pane = @intCast(id), + .pane = .at(id), .serial = pane.serial, .path = Pardes.SavePath.from(full), .promote = true, @@ -361,7 +361,7 @@ pub fn saveTo(p: *Pardes, id: usize, path: []const u8) void { fn askWrite(p: *Pardes, id: usize, serial: u32, path: []const u8) void { p.emit(.{ .save_text = .{ - .pane = @intCast(id), + .pane = .at(id), .serial = serial, .path = Pardes.SavePath.from(path), } }); diff --git a/core/fs.zig b/core/fs.zig index a79aa55c..0a10825d 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -1138,7 +1138,7 @@ test "unmount refuses pane paths inherited directories and queued save targets" try std.testing.expectError(error.MountInUse, unmount(p, "peer")); p.setCwd(.at(slot), "/"); while (p.nextEffect()) |_| {} - p.emit(.{ .save_text = .{ .pane = 0, .serial = pane.serial, .path = .from("/n/peer/pending") } }); + p.emit(.{ .save_text = .{ .pane = .at(0), .serial = pane.serial, .path = .from("/n/peer/pending") } }); try std.testing.expectError(error.MountInUse, unmount(p, "peer")); while (p.nextEffect()) |_| {} try unmount(p, "peer"); @@ -1317,7 +1317,7 @@ test "bounded reads release terminal snapshots after success and size refusal" { const empty = try readLimit(p, path, 0); defer gpa.free(empty); try std.testing.expectEqual(@as(usize, 0), empty.len); - p.update(.{ .output = .{ .pane = 0, .bytes = "limited terminal output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "limited terminal output" } }); const expected = "limited terminal output\n"; // a line ends with its newline const bytes = try readLimit(p, path, expected.len); defer gpa.free(bytes); diff --git a/core/keys.zig b/core/keys.zig index 2f63d045..92e78b0e 100644 --- a/core/keys.zig +++ b/core/keys.zig @@ -543,7 +543,7 @@ test "Esc back into a tty leaves its view at the prompt" { // rides the view down and leaves that pin far up in the scrollback. for (0..60) |i| { var buf: [32]u8 = undefined; - p.update(.{ .output = .{ .pane = @intCast(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); + p.update(.{ .output = .{ .pane = .at(shell), .bytes = std.fmt.bufPrint(&buf, "line {d}\r\n", .{i}) catch unreachable } }); } p.sync(); const live = pardes.Term.grid(sp.terminal).offset; diff --git a/core/look.zig b/core/look.zig index b2a7b945..f7084079 100644 --- a/core/look.zig +++ b/core/look.zig @@ -1923,7 +1923,7 @@ test "Look hover waits without mutating the pane and input cancels it" { // Background traffic in another pane does not change the text or geometry // under this pointer and must not strand a stationary hover unarmed. - p.update(.{ .output = .{ .pane = @intCast(other_id), .bytes = "busy\r\n" } }); + p.update(.{ .output = .{ .pane = .at(other_id), .bytes = "busy\r\n" } }); try std.testing.expect(p.look_hover_preview != null); const seam_x = p.view().col_x[0] + p.view().col_w[0] - 1; @@ -2504,9 +2504,9 @@ test "LookNext in a command pane walks its own file:line places, whoever walked while (p.nextEffect()) |_| {} const dst = exec.execute(p, 0, "make") orelse return error.NoCommandPane; while (p.nextEffect()) |_| {} - p.update(.{ .output = .{ .pane = @intCast(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } }); - p.update(.{ .exited = .{ .pane = @intCast(dst), .status = 2 } }); - p.update(.{ .eof = .{ .pane = @intCast(dst) } }); + p.update(.{ .output = .{ .pane = .at(dst), .bytes = "x.c:3:1: error: bad\r\ny.c:2:1: warning: odd\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(dst), .status = 2 } }); + p.update(.{ .eof = .{ .pane = .at(dst) } }); const cmd = p.panes[dst].?; // A walk last made elsewhere, and another pane with places in it. try std.testing.expect(p.executeBuiltinLine(0, "New")); diff --git a/core/lsp/Ask.zig b/core/lsp/Ask.zig index df6a058a..376b093d 100644 --- a/core/lsp/Ask.zig +++ b/core/lsp/Ask.zig @@ -113,7 +113,7 @@ pub fn lspRequest(p: *Pardes, asked: usize, kind: lsp.Kind, arg_in: []const u8) p.emit(.{ .lsp = .{ .id = p.lsp_ask.seq, .kind = kind, - .pane = @intCast(id), + .pane = .at(id), .offset = @intCast(at), .arg = .from(sent), } }); @@ -445,7 +445,7 @@ test "Lspwhy after a Hover asks to explain that hover, in its file at its place, try std.testing.expectEqual(lsp.Kind.explain, e.lsp.kind); try std.testing.expectEqualStrings("hover ", e.lsp.arg.slice()); try std.testing.expectEqual(hover_at, e.lsp.offset); - try std.testing.expectEqual(@as(u8, 0), e.lsp.pane); + try std.testing.expectEqual(0, e.lsp.pane.index()); seen = true; }; try std.testing.expect(seen); diff --git a/core/mouse.zig b/core/mouse.zig index 0ff4c7e3..1ef348f8 100644 --- a/core/mouse.zig +++ b/core/mouse.zig @@ -1580,17 +1580,17 @@ test "a wheel over a program that owns it is the program's, in the form it asked .{ .modes = "\x1b[?1007l", .button = .wheel_up, .sent = "" }, }; for (cases) |case| { - p.update(.{ .output = .{ .pane = 0, .bytes = case.modes } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = case.modes } }); _ = 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, pardes.test_api.ptyBytes(p, 0, &out)); } // A shell on the main screen: the wheel scrolls its scrollback, and // the shell hears nothing. - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?1l\x1b[?1049l" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1l\x1b[?1049l" } }); for (0..40) |i| { var line: [16]u8 = undefined; - p.update(.{ .output = .{ .pane = 0, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); } _ = try p.render(frame.allocator()); _ = pardes.test_api.ptyBytes(p, 0, &out); @@ -1600,7 +1600,7 @@ test "a wheel over a program that owns it is the program's, in the form it asked 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" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1000h\x1b[?1006h" } }); _ = 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 } }); @@ -1671,7 +1671,7 @@ test "a program tracking the mouse gets its clicks, drags and moves over its gri } }.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" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1049h\x1b[?1h\x1b[?1006;1000h" } }); _ = 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.view().drag == .none); @@ -1713,7 +1713,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" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003h" } }); _ = 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 })); @@ -1737,7 +1737,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" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[?1003l\x1b[?1006l\x1b[?1000h" } }); _ = 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 })); diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index cf68fa76..302b916a 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -1282,7 +1282,7 @@ pub fn getFile(p: *Pardes, pane: *Pane, path: []const u8) GetError!void { f.disk_newer_warned = false; f.disk_gone = false; f.on_disk = fs.localPath(path) != null; - if (f.on_disk) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = true } }); + if (f.on_disk) p.emit(.{ .watch = .{ .pane = .at(id), .on = true } }); } /// What Get and Edit's `e` fail with, as their callers say it (the 9P @@ -1500,7 +1500,7 @@ test "a body write to a terminal is typed input, not a paste, even to a program const term = for (p.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break id; } else return error.SkipZigTest; - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b[?2004h" } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b[?2004h" } }); while (p.nextEffect()) |_| {} const w = wr(p, Node.of(p.panes[term].?.serial, .body), "ls\n"); try testing.expectEqual(Status.ok, w.reply.status); @@ -1513,7 +1513,7 @@ test "Save path of a file pane logs a save record naming that path" { const serial = serialOf(p); const saved = wr(p, Node.of(serial, .ctl), "Save /tmp/pardes-save-copy.txt\n"); try testing.expectEqual(Status.ok, saved.reply.status); - p.perform(.{ .save_text = .{ .pane = 0, .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } }); + p.perform(.{ .save_text = .{ .pane = .at(0), .serial = serial, .path = Pardes.SavePath.from("/tmp/pardes-save-copy.txt") } }); var want: [64]u8 = undefined; try testing.expect(th.logHas(p, try std.fmt.bufPrint(&want, "save {d} /tmp/pardes-save-copy.txt\n", .{serial}))); } @@ -1590,7 +1590,7 @@ test "exec Save writes the named file through the host" { const saved = wr(p, Node.of(serial, .exec), "Save\n"); try testing.expectEqual(Status.ok, saved.reply.status); try testing.expect(saved.saved); - p.perform(.{ .save_file = .{ .pane = 0 } }); + p.perform(.{ .save_file = .{ .pane = .at(0) } }); try testing.expect(!pane_files.dirtyOf(pane)); try testing.expectEqualStrings(pane.file.?.content, p.fallback.get("/tmp/renamed.txt").?); } @@ -1990,7 +1990,7 @@ test "a terminal told the directory it already goes by logs no rename" { const session = p.sessionDir(); p.setCwd(.at(term), session); try testing.expect(!th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} ", .{p.panes[term].?.serial}))); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "$ " } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "$ " } }); // Somewhere else is a rename. p.setCwd(.at(term), "/usr"); try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "rename {d} /usr", .{p.panes[term].?.serial}))); @@ -2001,13 +2001,13 @@ test "a terminal with text typed at its prompt is never typed into: a look at it defer p.deinit(); const term = p.paneBySerial(serialOf(p)).?; p.setCwd(.at(term), "/tmp"); - p.update(.{ .output = .{ .pane = @intCast(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); + p.update(.{ .output = .{ .pane = .at(term), .bytes = "\x1b]133;A;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07TYPED" } }); while (p.nextEffect()) |_| {} var count: usize = 0; for (p.panes) |slot| count += @intFromBool(slot != null); try testing.expectEqual(Status.ok, wr(p, @backingInt(tree.TopFile.look), "/tmp\n").reply.status); var typed_into = false; - while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) { + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) { typed_into = true; }; try testing.expect(!typed_into); @@ -2016,7 +2016,7 @@ test "a terminal with text typed at its prompt is never typed into: a look at it try testing.expectEqual(count + 1, after); // An exec at it runs in a pane of its own, not typed after TYPED. _ = wr(p, Node.of(serialOf(p), .exec), "echo hi\n"); - while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane == term) { + while (p.nextEffect()) |effect| if (effect == .write and effect.write.pane.index() == term) { typed_into = true; }; try testing.expect(!typed_into); @@ -2260,8 +2260,8 @@ test "a focus moved over 9P tells the programs that asked for focus reports, as }; try testing.expectEqual(@as(usize, 2), n); p.view().active = shells[0]; - p.update(.{ .output = .{ .pane = @intCast(shells[0]), .bytes = "\x1b[?1004h" } }); - p.update(.{ .output = .{ .pane = @intCast(shells[1]), .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(shells[0]), .bytes = "\x1b[?1004h" } }); + p.update(.{ .output = .{ .pane = .at(shells[1]), .bytes = "\x1b[?1004h" } }); while (p.nextEffect()) |_| {} var digits: [16]u8 = undefined; const moved = wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{p.panes[shells[1]].?.serial})); @@ -2344,7 +2344,7 @@ test "a new file saved shows in /recent, open, while it is" { const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)]; // A host that writes files, as the real ones do. const Writing = struct { - fn write(_: ?*anyopaque, _: u8, path: []const u8, bytes: []const u8) void { + fn write(_: ?*anyopaque, _: pardes.Pane.Id, path: []const u8, bytes: []const u8) void { std.Io.Dir.cwd().writeFile(testing.io, .{ .sub_path = path, .data = bytes }) catch {}; } }; @@ -2357,7 +2357,7 @@ test "a new file saved shows in /recent, open, while it is" { _ = wr(p, Node.of(made, .name), try std.fmt.bufPrint(&name, "{s}\n", .{path})); _ = wr(p, Node.of(made, .body), "fresh\n"); try testing.expectEqual(Status.ok, wr(p, Node.of(made, .ctl), "Save\n").reply.status); - p.perform(.{ .save_file = .{ .pane = @intCast(p.paneBySerial(made).?) } }); + p.perform(.{ .save_file = .{ .pane = .at(p.paneBySerial(made).?) } }); var want: [4300]u8 = undefined; try testing.expect(std.mem.indexOf(u8, rd(p, @backingInt(tree.TopFile.recent), 0, 8192).bytes, try std.fmt.bufPrint(&want, "open {s}\n", .{path})) != null); } @@ -2575,7 +2575,7 @@ test "a word written to a raw terminal's look is listed as in normal mode" { defer p.deinit(); const serial = serialOf(p); const id = p.paneBySerial(serial).?; - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one MARK two\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "one MARK two\r\n" } }); p.panes[id].?.body.mode = .tty; try testing.expectEqual(Status.ok, wr(p, Node.of(serial, .look), "MARK\n").reply.status); const said = std.mem.trimEnd(u8, rd(p, Node.of(serial, .look), 0, 64).bytes, "\n"); @@ -2588,7 +2588,7 @@ test "@p<terminal>:<address> takes any address over the terminal's lines, select defer p.deinit(); const serial = serialOf(p); const id = p.paneBySerial(serial).?; - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = "one\r\ntwo MARK three\r\n" } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = "one\r\ntwo MARK three\r\n" } }); const pane = p.panes[id].?; const root = @backingInt(tree.TopFile.look); var line: [64]u8 = undefined; diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index 76765535..8be26602 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -941,7 +941,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) ! f.context.revision = null; pane.geometry_key = 0; look.invalidateLookHover(p, id); - p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); + p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); events.noteLog(p, .rename, pane); // A name given: whether a file there is on disk is the disk's to say. f.on_disk = f.output == null and pardes.Pardes.recentKeeps(p.tape, f.path); @@ -1065,7 +1065,7 @@ test "a terminal's body stats as long as it reads" { while (p.nextEffect()) |_| {} const pane = p.panes[0].?; try testing.expect(pane.isTerminal()); - p.update(.{ .output = .{ .pane = 0, .bytes = "$ ls\r\nalpha beta\r\n$ " } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "$ ls\r\nalpha beta\r\n$ " } }); const body = Node.of(pane.serial, .body); const whole = rd(p, body, 0, 1 << 16); try testing.expect(whole.bytes.len > 0); diff --git a/core/ninep/pty.zig b/core/ninep/pty.zig index 96f2a6bf..6f3a8af0 100644 --- a/core/ninep/pty.zig +++ b/core/ninep/pty.zig @@ -96,14 +96,14 @@ fn verb(p: *Pardes, id: usize, line: []const u8, apply: bool) ?[]const u8 { // is refused, never quietly raised. if (rows < pty_rows_min) return e_winsize_rows; if (!apply) return null; - p.emit(.{ .resize_pty = .{ .pane = @intCast(id), .cols = cols, .rows = rows } }); + p.emit(.{ .resize_pty = .{ .pane = .at(id), .cols = cols, .rows = rows } }); pane.fs.winsize = .{ cols, rows }; }, .sig => { const which = signalNamed(words.next() orelse return e_bad_pty_ctl) orelse return e_bad_pty_ctl; if (words.next() != null) return e_bad_pty_ctl; if (!apply) return null; - p.emit(.{ .signal_pty = .{ .pane = @intCast(id), .serial = pane.serial, .sig = which } }); + p.emit(.{ .signal_pty = .{ .pane = .at(id), .serial = pane.serial, .sig = which } }); }, .exec => { if (words.next() != null) return e_bad_pty_ctl; @@ -709,7 +709,7 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = "unwatched" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "unwatched" } }); while (p.nextEffect()) |_| {} try testing.expectEqual(@as(usize, 0), p.panes[0].?.fs.pty_out.buf.items.len); try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); @@ -724,20 +724,20 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(@as(u16, 0), p.fs.listeners); try testing.expect(p.panes[0].?.fs.readers == 0); - p.update(.{ .output = .{ .pane = 0, .bytes = "hello" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "hello" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("hello", rd(p, data, 0, 64).bytes); try testing.expectEqual(Status.again, rd(p, data, 0, 64).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = "abcdef" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "abcdef" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("ab", rd(p, data, 0, 2).bytes); try testing.expectEqualStrings("cd", rd(p, data, 0, 2).bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "ghi" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "ghi" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("efghi", rd(p, data, 0, 64).bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "orphan" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "orphan" } }); while (p.nextEffect()) |_| {} _ = call(p, .{ .tag = 6, .op = .release, .node = data, .handle = reader.reply.handle }); try testing.expect(!p.panes[0].?.fs.pty_reader); @@ -750,7 +750,7 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqual(Status.err, second.reply.status); try testing.expectEqualStrings(tree.e_in_use, second.reply.ename); try testing.expect(p.panes[0].?.fs.pty_reader); - p.update(.{ .output = .{ .pane = 0, .bytes = "still" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "still" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("still", rd(p, data, 0, 64).bytes); } @@ -765,7 +765,7 @@ test "a run waiting for a new terminal's first prompt is the only line typed the const node = Node.of(serialOf(p), .pty_run); const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle; _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" }); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); var sent: [32]u8 = undefined; var len: usize = 0; while (p.nextEffect()) |e| if (e == .write) { @@ -783,7 +783,7 @@ test "run answers how its command ended once the shell is back at a prompt" { const node = Node.of(serialOf(p), .pty_run); const out = struct { fn put(pp: *Pardes, bytes: []const u8) void { - pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); while (pp.nextEffect()) |_| {} } }; @@ -801,7 +801,7 @@ test "run answers how its command ended once the shell is back at a prompt" { // A respawn before that prompt keeps it waiting for the new shell's. p.acknowledgeShell(.at(0), "/bin/sh", true); try testing.expectEqual(Status.again, call(p, .{ .tag = 3, .op = .read, .node = node, .handle = early.reply.handle, .size = 64 }).reply.status); - p.update(.{ .output = .{ .pane = 0, .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } }); var sent_late: [16]u8 = undefined; var sent_len: usize = 0; while (p.nextEffect()) |e| if (e == .write) { @@ -909,7 +909,7 @@ test "a shell that exits under a run answers its status, and the log says exit b const serial = serialOf(p); const node = Node.of(serial, .pty_run); const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - p.update(.{ .output = .{ .pane = 0, .bytes = prompt } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = prompt } }); while (p.nextEffect()) |_| {} const log = @backingInt(tree.TopFile.log); const f = call(p, .{ .tag = 1, .op = .open, .node = log }).reply.handle; @@ -918,9 +918,9 @@ test "a shell that exits under a run answers its status, and the log says exit b const r = call(p, .{ .tag = 4, .op = .open, .node = node }); _ = call(p, .{ .tag = 5, .op = .write, .node = node, .handle = r.reply.handle, .data = "echo bye; exit 3\n" }); - p.update(.{ .output = .{ .pane = 0, .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } }); - p.update(.{ .exited = .{ .pane = 0, .status = 3 } }); - p.update(.{ .eof = .{ .pane = 0 } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "echo bye; exit 3\r\n\x1b]133;C;aid=pardes\x07bye\r\n" } }); + p.update(.{ .exited = .{ .pane = .at(0), .status = 3 } }); + p.update(.{ .eof = .{ .pane = .at(0) } }); while (p.nextEffect()) |_| {} try testing.expect(p.paneBySerial(serial) == null); try testing.expectEqualStrings("exit 3\nbye\n", call(p, .{ .tag = 6, .op = .read, .node = node, .handle = r.reply.handle, .size = 64 }).bytes); @@ -969,7 +969,7 @@ test "a run's answer says cut when its output's start is gone, and reads a bound const pane = p.panes[0].?; const sh = struct { fn put(pp: *Pardes, bytes: []const u8) void { - pp.update(.{ .output = .{ .pane = 0, .bytes = bytes } }); + pp.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); while (pp.nextEffect()) |_| {} } fn send(pp: *Pardes, n: u64) u32 { @@ -1099,7 +1099,7 @@ test "a terminal's ctl counts its body, and a new directory is a rename in the l const p = try withTerm(gpa); defer p.deinit(); const serial = serialOf(p); - p.update(.{ .output = .{ .pane = 0, .bytes = "some history\r\nmore" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "some history\r\nmore" } }); while (p.nextEffect()) |_| {} const opened = call(p, .{ .tag = 1, .op = .open, .node = Node.of(serial, .body) }); const body_len = call(p, .{ .tag = 2, .op = .read, .node = Node.of(serial, .body), .handle = opened.reply.handle, .size = 1 << 16 }).bytes.len; diff --git a/core/ninep/screen.zig b/core/ninep/screen.zig index cd3c73b6..1e2791b1 100644 --- a/core/ninep/screen.zig +++ b/core/ninep/screen.zig @@ -124,7 +124,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" { const p = try withTerm(gpa); defer p.deinit(); const node = Node.of(serialOf(p), .body); - p.update(.{ .output = .{ .pane = 0, .bytes = "old caf\xc3\xa9\r\nold tail" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "old caf\xc3\xa9\r\nold tail" } }); while (p.nextEffect()) |_| {} const original = try pardes.Term.scrollback(p.panes[0].?.terminal, gpa); defer gpa.free(original); @@ -132,7 +132,7 @@ test "terminal body handles keep one history snapshot across fragmented reads" { try testing.expectEqual(Status.ok, opened.reply.status); const first = call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 3 }); try testing.expectEqualStrings(original[0..3], first.bytes); - p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "\x1b[3J\x1b[2J\x1b[Hnew output" } }); while (p.nextEffect()) |_| {} var offset: usize = 3; while (offset < original.len) { @@ -154,7 +154,7 @@ test "an empty terminal body snapshot stays empty while output continues" { const opened = call(p, .{ .tag = 1, .op = .open, .node = node }); try testing.expectEqualStrings("", call(p, .{ .tag = 2, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes); try testing.expect(p.fs.opens[opened.reply.handle - 1].what.snapshot != null); - p.update(.{ .output = .{ .pane = 0, .bytes = "new output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "new output" } }); while (p.nextEffect()) |_| {} try testing.expectEqualStrings("", call(p, .{ .tag = 3, .op = .read, .node = node, .handle = opened.reply.handle, .size = 32 }).bytes); _ = call(p, .{ .tag = 4, .op = .release, .node = node, .handle = opened.reply.handle }); @@ -182,7 +182,7 @@ test "terminal body snapshots are lazy bounded and released after the pane close const scratch = try th.newPane(p); const scratch_id = p.paneBySerial(scratch).?; try testing.expect(p.panes[scratch_id].?.file != null); - p.update(.{ .output = .{ .pane = 0, .bytes = "latest output" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = "latest output" } }); while (p.nextEffect()) |_| {} var failing = std.testing.FailingAllocator.init(gpa, .{ .fail_index = 0 }); p.gpa = failing.allocator(); @@ -298,7 +298,7 @@ test "a terminal's body is its logical lines: a row the terminal wrapped is join const pane = p.panes[0].?; const long = &@as([50]u8, @splat('w')) ++ &@as([150]u8, @splat('x')); // wider than the pane: it wraps try testing.expect(long.len > pane.cols); - p.update(.{ .output = .{ .pane = 0, .bytes = long ++ "\r\nnext" } }); + p.update(.{ .output = .{ .pane = .at(0), .bytes = long ++ "\r\nnext" } }); while (p.nextEffect()) |_| {} const node = Node.of(pane.serial, .body); const body = th.rd(p, node, 0, 4096).bytes; diff --git a/core/ninep/testing.zig b/core/ninep/testing.zig index 23a9199f..cf75d80d 100644 --- a/core/ninep/testing.zig +++ b/core/ninep/testing.zig @@ -153,15 +153,15 @@ pub fn nameAt(list: []const Dirent, want: []const u8) ?Dirent { /// none. pub const starting: pardes.Host.VTable = .{ .spawn = startNothing }; -fn startNothing(_: ?*anyopaque, _: u8, _: []const u8) void {} +fn startNothing(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} pub const FakeTty = struct { taken: bool, pub const vtable: pardes.Host.VTable = .{ .tty_taken = answer }; - fn answer(ctx: ?*anyopaque, pane: u8) bool { - _ = pane; + fn answer(ctx: ?*anyopaque, id: pardes.Pane.Id) bool { + _ = id; const f: *FakeTty = @ptrCast(@alignCast(ctx.?)); return f.taken; } diff --git a/core/panes.zig b/core/panes.zig index 7ea479b9..b928917a 100644 --- a/core/panes.zig +++ b/core/panes.zig @@ -1192,8 +1192,8 @@ pub fn retirePane(p: *Pardes, pane: *Pane) void { if (pane.file) |*file| panes.File.leaveTwins(p, file); const watched = (if (pane.file) |f| f.output == null else false) or (if (pane.addon) |k| k.path.len > 0 else false); for (p.panes, 0..) |slot, id| if (slot == pane) { - if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); - if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = @intCast(id) } }); + if (watched) p.emit(.{ .watch = .{ .pane = .at(id), .on = false } }); + if (pane.isTerminal()) p.emit(.{ .close_pty = .{ .pane = .at(id) } }); // Its pty's end and its emulator are the authority's: a replica's // speculation that closes a terminal waits for it. if (pane.terminal != null) tape.poison("close a terminal"); @@ -1294,7 +1294,7 @@ pub fn emitSpawn(p: *Pardes, id: usize, serial: u32, cwd: []const u8) void { if (p.spawn_dirs[id]) |old| p.gpa.free(old); p.spawn_dirs[id] = null; if (cwd.len > effect_path_cap) p.spawn_dirs[id] = p.gpa.dupe(u8, cwd) catch null; - p.emit(.{ .spawn = .{ .pane = @intCast(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } }); + p.emit(.{ .spawn = .{ .pane = .at(id), .serial = serial, .cwd = .from(if (cwd.len > effect_path_cap) "" else cwd) } }); } /// A command pane: a terminal whose child is `$SHELL -c line` rather @@ -1713,7 +1713,7 @@ test "owned cwd EOF failure retains the pane and Del retries its close" { p.sync(); while (p.nextEffect()) |_| {} allocator.fail_index = allocator.alloc_index; - p.update(.{ .eof = .{ .pane = 0 } }); + p.update(.{ .eof = .{ .pane = .at(0) } }); try std.testing.expectEqual(parent, p.panes[0].?); try std.testing.expectEqual(parent, child.cwd.inherited); try std.testing.expectEqual(Text.Mode.normal, parent.body.mode); diff --git a/core/replica.zig b/core/replica.zig index 625153d1..3f04b3bc 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -2278,7 +2278,7 @@ pub const Peers = struct { if (ps.next_id == 0) ps.next_id = 1; // The session's digest as dumped, for the joiner to check its load by. const digest = tape.digestOf(core); - peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = k, .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; + peer.welcome_len = (wire.encodeServer(&peer.welcome, .{ .welcome = .{ .pid = @intCast(libc.getpid()), .session = ps.name[0..@min(ps.name.len, wire.max_name)], .client = peer.id, .view = .at(k), .dump_len = whole, .gmtoff = gmtoff(), .digest = digest, .semantics = wire.semantics, .blobs = @intCast(blobs.items.len) } }) catch unreachable).len; if (ps.threads) peer.writer = std.Thread.spawn(.{}, Peer.writeLoop, .{peer}) catch null; if (ps.threads) peer.reader = std.Thread.spawn(.{}, Peer.readLoop, .{peer}) catch null; if (ps.threads and (peer.writer == null or peer.reader == null)) { @@ -2591,7 +2591,7 @@ fn joinOn(gpa: Allocator, fd: c_int, session: []const u8, why: []u8, have: ?*Hav .welcome => |w| { r.j.pid = w.pid; r.j.client = w.client; - r.j.view = w.view; + r.j.view = w.view.index(); r.j.gmtoff = w.gmtoff; r.j.digest = w.digest; r.j.semantics = w.semantics; @@ -3292,7 +3292,7 @@ const TestHost = struct { /// A host with ptys whose pump polls for a frame, as a client's does. const PtyHost = struct { - fn resized(_: ?*anyopaque, _: u8, _: u16, _: u16) void {} + fn resized(_: ?*anyopaque, _: pardes.Pane.Id, _: u16, _: u16) void {} fn poll(_: ?*anyopaque) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_resize = resized, .poll_frame = poll }; fn host() pardes.Host { @@ -3729,7 +3729,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st for (0..3) |round| { // The shell prints: its unit rolls the replica back and applies the // key again; then its delta lands, under the new copy. - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); r.confirm((try a.pending()).?); r.settle(); try std.testing.expect(r.copy.held); @@ -3751,7 +3751,7 @@ test "a delta applied under a speculation outlives its rollback: the terminal st r.confirm(try a.local(.{ .focus = false })); _ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); try key(r, 'x', &sent); - for (0..40) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); + for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -3875,7 +3875,7 @@ test "a terminal sized again by a client's key: the step reads the grid it had, // History the replica holds as holes, of lines a narrow grid wraps in // two, which a wider one unwraps. var line: [96]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); r.confirm((try a.pending()).?); // Out of terminal mode in the session's view, which sizes it; then a // client's own view (a copy of it), wider: its first key sizes the @@ -3954,7 +3954,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [64]u8 = undefined; - for (0..200) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); + for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); r.settle(); @@ -3977,7 +3977,7 @@ test "pardes's own keys over a terminal's history apply at once: its view moves // The shell prints while they wait: its unit, then its delta, which // sets the view the authority's (at the bottom still): what was applied // goes on top of it again. - for (0..5) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); + for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4043,7 +4043,7 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); var line: [96]u8 = undefined; - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); r.confirm((try a.pending()).?); try deliver(a, &screens, peer, r, .flush); // Out of the shell's tty mode, in the session's view: keys over its text. @@ -4061,8 +4061,8 @@ test "a unit kept over a copy taken ahead is never replayed over a delta that ca r.settle(); } // The program redraws the screen: other rows where those keys read. - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[H\x1b[2J" } }); - for (0..30) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } }); + for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); r.confirm((try a.pending()).?); r.settle(); try deliver(a, &screens, peer, r, .flush); @@ -4174,7 +4174,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &zon } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &zon } }); const r = try joinedNow(a, 1, 0); defer r.deinit(); try std.testing.expectEqual(digestOf(a), r.digest()); @@ -4703,7 +4703,7 @@ test "a step that reads a terminal's rows as the core keeps them sends a new cli } else return error.NoShell; a.core.view().active = shell; var line: [64]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); + for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } }); const out = try gpa.dupe(u8, (try a.pending()).?); defer gpa.free(out); for ([_]*Replica{ r1, r2 }) |r| r.confirm(out); @@ -4733,7 +4733,7 @@ test "a replica with no code for a kind whose state is not plain shows its pane // replica's core takes the kind's words, never its code. var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } })); r.confirm(try a.local(.{ .command = "Counter" })); try std.testing.expect(r.core().kinds.ops[r.core().kinds.n - 1] == null); try std.testing.expect(try shows(r.core(), "addon counter 1 does not run in this client")); @@ -4791,7 +4791,7 @@ test "a kind's place moved in a step of another view's: a replica's key that rea defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // The replica's view opens the kind's pane, and an Esc goes back to // the file (Last): view 0 has the file. const own = try a.openView(1); @@ -4845,7 +4845,7 @@ test "a client joined from a dump numbers a kind's next job as the session does" defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &jobber } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &jobber } }); _ = try a.local(.{ .command = "Jobber" }); for (0..3) |_| _ = try a.local(.{ .key = .{ .cp = 'x', .text = "x" } }); const id = a.core.view().active; @@ -4864,7 +4864,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } })); // Its replica has no code for the kind: the open's outcome (its place, // `1:0 0`) is the authority's to say. const msg = try gpa.dupe(u8, try r.input(.{ .command = "Placed" })); @@ -4883,7 +4883,7 @@ test "a client joined from a dump tells a kind each view's facts as the session defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &placed } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &placed } }); _ = try a.local(.{ .command = "Placed" }); // A message in its pane: a band over its body, in each view. _ = try a.local(.{ .command = "Placed x" }); @@ -4937,7 +4937,8 @@ const Asker = struct { const BusyHost = struct { var core: ?*Pardes = null; var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity }; - fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void { + fn job(_: ?*anyopaque, id: pardes.Pane.Id, serial: u32, token: u32) void { + const pane = id.index(); pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never); } fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void { @@ -4955,7 +4956,7 @@ test "a kind's job answered at once inside its host's call (no worker free) is t defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words); - r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } })); + r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &asker } })); // The client has its code (as a library of its own found by its scan). r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops; r.confirm(try a.local(.{ .command = "Asker" })); @@ -4981,7 +4982,7 @@ test "a closed terminal with a kitty image brought back on a client: its image d } else return error.NoShell; // A 2x2 picture in RGB (f=24): drawn, the emulator keeps it as RGBA // of its own (TerminalImages.converted). - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); r.confirm((try a.pending()).?); // Closed and brought back: the client loads the session's dump of it, // its image with it. @@ -5034,7 +5035,7 @@ test "a far client's own Del of a pane whose kind's state is not plain, rolled b defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &counter } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &counter } }); _ = try a.local(.{ .command = "Counter" }); // Joined from the dump: the kind's pane is a line here (no code), its // slot the dump's. @@ -5101,7 +5102,7 @@ const SeenHost = struct { of(ctx).linked += 1; } fn watchTheme(_: ?*anyopaque, _: u32, _: bool) void {} - fn watchFile(_: ?*anyopaque, _: u8, _: []const u8, _: bool, _: pardes.WatchMode) void {} + fn watchFile(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8, _: bool, _: pardes.WatchMode) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .set_clipboard = setClipboard, .read_clipboard = readClipboard, .open_link = openLink, .watch_theme = watchTheme, .watch_file = watchFile }; fn host(h: *SeenHost) pardes.Host { return .{ .ctx = h, .vtable = &vtable }; @@ -5256,7 +5257,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd))); var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); // The kind's pane, its +Search (a place a row, as a kind's `/` leaves // it), and a scratch whose words name files in the session's directory // (as a command's output would). @@ -5563,14 +5564,14 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' if (slot) |pane| if (pane.isTerminal()) break id; } else null; if (shell) |id| { - a.output(.{ .output = .{ .pane = @intCast(id), .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(id), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; } _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/mise.toml", .{dir}) }); const file = a.core.view().active; var words: [64]pardes.Kind.LoadedWord = undefined; const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); - _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &still } }); _ = try a.local(.{ .command = "Still" }); const kind = a.core.view().active; try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null); @@ -5670,7 +5671,7 @@ test "a far client's click into a shell whose program asked for focus events is const Told = struct { var bytes: [64]u8 = undefined; var len: usize = 0; - fn write(_: ?*anyopaque, _: u8, b: []const u8) void { + fn write(_: ?*anyopaque, _: pardes.Pane.Id, b: []const u8) void { @memcpy(bytes[len..][0..b.len], b); len += b.len; } @@ -5682,7 +5683,7 @@ test "a far client's click into a shell whose program asked for focus events is const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); } else return error.NoShell; - a.output(.{ .output = .{ .pane = shell, .bytes = "\x1b[?1004h$ " } }); + a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; _ = try a.local(.{ .command = "New" }); var screens: Screens = .init(gpa); diff --git a/core/root.zig b/core/root.zig index 706c833d..681be15d 100644 --- a/core/root.zig +++ b/core/root.zig @@ -221,7 +221,7 @@ pub const test_api = if (@import("builtin").is_test) struct { var n: usize = 0; while (p.nextEffect()) |effect| switch (effect) { .write => |w| { - if (pane != null and w.pane != pane.?) continue; + if (pane != null and w.pane.index() != pane.?) continue; const b = w.bytes.slice(); if (n + b.len > buf.len) break; @memcpy(buf[n..][0..b.len], b); diff --git a/core/views.zig b/core/views.zig index a8bf8e60..9985288d 100644 --- a/core/views.zig +++ b/core/views.zig @@ -859,7 +859,7 @@ test "a terminal shown in a view shorter than it keeps its cursor in sight" { defer out.deinit(gpa); for (1..rows) |i| try out.print(gpa, "row-{d}\r\n", .{i}); try out.appendSlice(gpa, "LAST$ "); - p.update(.{ .output = .{ .pane = @intCast(id), .bytes = out.items } }); + p.update(.{ .output = .{ .pane = .at(id), .bytes = out.items } }); // Sized for the tall view, it fits there whole: nothing is passed over. try testing.expectEqual(@as(u16, 0), term.pan); p.toView(.at(0)); |
