summaryrefslogtreecommitdiff
path: root/core/ninep
diff options
context:
space:
mode:
Diffstat (limited to 'core/ninep')
-rw-r--r--core/ninep/ctl.zig28
-rw-r--r--core/ninep/pane.zig4
-rw-r--r--core/ninep/pty.zig34
-rw-r--r--core/ninep/screen.zig10
-rw-r--r--core/ninep/testing.zig6
5 files changed, 41 insertions, 41 deletions
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;
}