summaryrefslogtreecommitdiff
path: root/src/ninep/pane.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/pane.zig')
-rw-r--r--src/ninep/pane.zig60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index 61073a55..b07ee038 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -186,7 +186,7 @@ pub fn wholeUtf8(data: []const u8) usize {
return data.len;
}
-pub fn spliceBody(p: *Pardes, id: usize, pane: *Pane, q0: usize, q1: usize, bytes: []const u8) ?usize {
+pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const u8) ?usize {
const f = fileOf(pane) orelse return null;
const take = if (bytes.len == 0) 0 else wholeUtf8(bytes);
const lo = @min(q0, f.content.len);
@@ -195,7 +195,7 @@ pub fn spliceBody(p: *Pardes, id: usize, pane: *Pane, q0: usize, q1: usize, byte
@memcpy(new[0..lo], f.content[0..lo]);
@memcpy(new[lo..][0..take], bytes[0..take]);
@memcpy(new[lo + take ..], f.content[hi..]);
- if (!p.fs.panes[id].nomark) panes.File.pushUndo(p, pane);
+ if (!pane.fs.nomark) panes.File.pushUndo(p, pane);
panes.File.setContent(p, f, new);
return take;
}
@@ -208,7 +208,7 @@ pub const range_len: u64 = 24;
pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 {
const pane = p.panes[id] orelse return 0;
- const pf = &p.fs.panes[id];
+ const pf = &pane.fs;
return switch (f) {
.body, .data, .xdata => bodyOf(pane).len,
.tag => tagOf(p, pane).len,
@@ -265,7 +265,7 @@ pub fn indexLen(p: *Pardes) u64 {
// ---- reads ----
pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply {
- const pf = &p.fs.panes[id];
+ const pf = &pane.fs;
return switch (file) {
.name => name: {
const out = p.fs.stage(p.gpa);
@@ -379,10 +379,10 @@ pub fn write(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply
.body => writeBody(p, req, id, pane),
.tag => writeTag(p, req, pane),
.ctl => ctl.writePane(p, req, pane),
- .addr, .dot, .limit => writeRange(p, req, id, pane, file),
- .data, .xdata => writeData(p, req, id, pane),
- .sel => writeSel(p, req, id, pane),
- .dirty, .mark, .scroll => writeFlag(p, req, id, pane, file),
+ .addr, .dot, .limit => writeRange(req, pane, file),
+ .data, .xdata => writeData(p, req, pane),
+ .sel => writeSel(p, req, pane),
+ .dirty, .mark, .scroll => writeFlag(p, req, pane, file),
.look, .exec => ctl.command(p, req, pane.serial, file == .exec),
.event => events.writeEvent(p, req, id),
.errors => if (appendErrors(p, id, req.data)) |took|
@@ -404,9 +404,9 @@ fn writeBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
return .{ .tag = req.tag, .written = @intCast(take) };
}
const at = bodyOf(pane).len;
- const take = spliceBody(p, id, pane, at, at, req.data) orelse
+ const take = spliceBody(p, pane, at, at, req.data) orelse
return Reply.fail(req.tag, E.NOMEM);
- if (!p.fs.panes[id].noscroll) showOffset(pane, at + take);
+ if (!pane.fs.noscroll) showOffset(pane, at + take);
return .{ .tag = req.tag, .written = @intCast(take) };
}
@@ -422,14 +422,14 @@ fn writeTag(p: *Pardes, req: Req, pane: *Pane) Reply {
return .{ .tag = req.tag, .written = @intCast(take) };
}
-fn writeData(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
+fn writeData(p: *Pardes, req: Req, pane: *Pane) Reply {
if (fileOf(pane) == null) return Reply.fail(req.tag, E.INVAL);
- const pf = &p.fs.panes[id];
+ const pf = &pane.fs;
clampAddr(pf, bodyOf(pane).len);
const q0: usize = pf.addr.q0;
const q1: usize = @max(q0, @as(usize, pf.addr.q1));
const before = dotOf(pane);
- const take = spliceBody(p, id, pane, q0, q1, req.data) orelse
+ const take = spliceBody(p, pane, q0, q1, req.data) orelse
return Reply.fail(req.tag, E.NOMEM);
setDot(pane, shiftBy(before, clip(q0), clip(q1 - q0), clip(take)));
pf.addr = .{ .q0 = clip(q0 + take), .q1 = clip(q0 + take) };
@@ -437,12 +437,12 @@ fn writeData(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
return .{ .tag = req.tag, .written = @intCast(take) };
}
-fn writeSel(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply {
+fn writeSel(p: *Pardes, req: Req, pane: *Pane) Reply {
if (fileOf(pane) == null) return Reply.fail(req.tag, E.INVAL);
const d = dotOf(pane);
const q0: usize = d.q0;
const q1: usize = @max(q0, @as(usize, d.q1));
- const take = spliceBody(p, id, pane, q0, q1, req.data) orelse
+ const take = spliceBody(p, pane, q0, q1, req.data) orelse
return Reply.fail(req.tag, E.NOMEM);
setDot(pane, .{ .q0 = clip(q0 + take), .q1 = clip(q0 + take) });
return .{ .tag = req.tag, .written = @intCast(take) };
@@ -470,8 +470,8 @@ fn rangeOf(pf: *State, text: []const u8, data: []const u8) ?State.Range {
return if (a.i < expr.len) null else r;
}
-fn writeRange(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply {
- const pf = &p.fs.panes[id];
+fn writeRange(req: Req, pane: *Pane, file: PaneFile) Reply {
+ const pf = &pane.fs;
const text = bodyOf(pane);
clampAddr(pf, text.len);
const r = rangeOf(pf, text, req.data) orelse return tree.failText(req.tag, E.INVAL, tree.e_bad_addr);
@@ -495,9 +495,9 @@ fn flagOf(data: []const u8) ?bool {
return null;
}
-fn writeFlag(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply {
+fn writeFlag(p: *Pardes, req: Req, pane: *Pane, file: PaneFile) Reply {
const on = flagOf(req.data) orelse return Reply.fail(req.tag, E.INVAL);
- const pf = &p.fs.panes[id];
+ const pf = &pane.fs;
switch (file) {
.dirty => {
const f = fileOf(pane) orelse return Reply.fail(req.tag, E.INVAL);
@@ -569,13 +569,13 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize {
if (text.len == 0) return 0;
const pane = p.panes[id] orelse return null;
const dir = dirOf(pane);
- for (p.panes, 0..) |slot, i| {
+ for (p.panes) |slot| {
const q = slot orelse continue;
const qf = fileOf(q) orelse continue;
const o = qf.output orelse continue;
if (std.meta.activeTag(o.from) != .errors) continue;
if (!std.mem.eql(u8, std.fs.path.dirname(qf.path) orelse "", dir)) continue;
- return spliceBody(p, i, q, qf.content.len, qf.content.len, text);
+ return spliceBody(p, q, qf.content.len, qf.content.len, text);
}
const free = p.freeSlot() orelse return null;
const content = p.gpa.dupe(u8, text) catch return null;
@@ -590,11 +590,11 @@ pub fn appendErrors(p: *Pardes, id: usize, text: []const u8) ?usize {
/// Truncation empties whatever the file holds: the body, the tag's editable
/// tail (acme's `cleartag`), a range. Every other setattr just answers fresh
/// attributes.
-pub fn truncate(p: *Pardes, id: usize, pane: *Pane, file: PaneFile) tree.Status {
- const pf = &p.fs.panes[id];
+pub fn truncate(p: *Pardes, pane: *Pane, file: PaneFile) tree.Status {
+ const pf = &pane.fs;
switch (file) {
.body, .data, .xdata => if (fileOf(pane) != null) {
- _ = spliceBody(p, id, pane, 0, bodyOf(pane).len, "") orelse return .err;
+ _ = spliceBody(p, pane, 0, bodyOf(pane).len, "") orelse return .err;
pf.addr = .{};
setDot(pane, .{});
},
@@ -753,8 +753,8 @@ test "data and xdata read from addr, move it, and write through it" {
_ = wr(p, addr, "#0");
try testing.expectEqualStrings("one", rd(p, data, 0, 3).bytes);
- try testing.expectEqual(@as(u32, 3), p.fs.panes[0].addr.q0);
- try testing.expectEqual(@as(u32, 3), p.fs.panes[0].addr.q1);
+ try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q0);
+ try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1);
_ = wr(p, addr, "1");
try testing.expectEqualStrings("one\n", rd(p, xdata, 0, 100).bytes);
@@ -765,7 +765,7 @@ test "data and xdata read from addr, move it, and write through it" {
const w = wr(p, data, "ONE\n");
try testing.expectEqual(@as(u32, 4), w.reply.written);
try testing.expectEqualStrings("ONE\ntwo\n", p.panes[0].?.file.?.content);
- try testing.expectEqual(@as(u32, 4), p.fs.panes[0].addr.q0);
+ try testing.expectEqual(@as(u32, 4), p.panes[0].?.fs.addr.q0);
}
test "data never splits a grapheme, in either direction" {
@@ -802,8 +802,8 @@ test "sel reads the selection and writing sel replaces it" {
_ = wr(p, addr_node, "#0");
_ = wr(p, addr_node, " 0 3 ");
- try testing.expectEqual(@as(u32, 0), p.fs.panes[0].addr.q0);
- try testing.expectEqual(@as(u32, 3), p.fs.panes[0].addr.q1);
+ try testing.expectEqual(@as(u32, 0), p.panes[0].?.fs.addr.q0);
+ try testing.expectEqual(@as(u32, 3), p.panes[0].?.fs.addr.q1);
// A truncation empties dot; an address expression addresses it.
_ = call(p, .{ .tag = 9, .op = .setattr, .node = dot, .truncate = true });
@@ -823,7 +823,7 @@ test "the flag files read and write the state acme kept behind ctl verbs" {
defer p.deinit();
const serial = serialOf(p);
const pane = p.panes[0].?;
- const pf = &p.fs.panes[0];
+ const pf = &p.panes[0].?.fs;
const dirty = Node.of(serial, .dirty);
const mark = Node.of(serial, .mark);
const scroll = Node.of(serial, .scroll);