diff options
Diffstat (limited to 'src/ninep/cols.zig')
| -rw-r--r-- | src/ninep/cols.zig | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig index 20ee2e3e..74d1f668 100644 --- a/src/ninep/cols.zig +++ b/src/ninep/cols.zig @@ -20,8 +20,8 @@ const E = tree.E; /// else the active pane's. Null when the workspace tag has it and no pane /// is active. pub fn activeColumn(p: *const Pardes) ?usize { - if (p.headerColumn()) |c| return if (c < p.ncol) c else null; - const at = layout.findPane(p, p.active) orelse return null; + if (p.headerColumn()) |c| return if (c < p.view().ncol) c else null; + const at = layout.findPane(p, p.view().active) orelse return null; return at.col; } @@ -32,13 +32,14 @@ pub fn activeColumn(p: *const Pardes) ?usize { /// then `active <serial>`: the active column, where pane/new and a look /// place a pane next (acme's activecol), not always the keyboard's. pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) !void { + const v = p.view(); const active = activeColumn(p); - for (0..p.ncol) |c| { + for (0..p.view().ncol) |c| { try w.print("{d} {d} {d} {d} {s} {s}", .{ - layout.columnSerial(p, c), c, p.col_x[c], p.col_w[c], - if (active == c) "current" else "notcurrent", if (p.cols[c].n == 0) "empty" else "full", + layout.columnSerial(p, c), c, v.col_x[c], v.col_w[c], + if (active == c) "current" else "notcurrent", if (v.cols[c].n == 0) "empty" else "full", }); - for (p.cols[c].panes[0..p.cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial}); + for (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial}); try w.writeByte('\n'); } if (layout.activeColumn(p) orelse active) |c| try w.print("active {d}\n", .{layout.columnSerial(p, c)}) else try w.writeAll("active -\n"); @@ -51,7 +52,7 @@ const Header = struct { text: *Text, col: ?usize }; fn header(p: *Pardes, serial: ?u32) ?Header { const s = serial orelse return .{ .text = &p.global_tag, .col = null }; const c = layout.columnBySerial(p, s) orelse return null; - return .{ .text = &p.col_tags[c], .col = c }; + return .{ .text = &p.view().col_tags[c], .col = c }; } pub fn headerText(p: *Pardes, serial: ?u32) ?[]const u8 { @@ -174,7 +175,7 @@ pub fn writeCtl(p: *Pardes, req: Req, serial: u32) Reply { defer p.exec_column = null; p.exec_header = true; defer p.exec_header = false; - if (pardes.ctlfs.ctl.runBuiltin(p, req, p.active, line)) |refusal| return refusal; + if (pardes.ctlfs.ctl.runBuiltin(p, req, p.view().active, line)) |refusal| return refusal; } return .{ .tag = req.tag, .written = @intCast(req.data.len) }; } @@ -206,7 +207,7 @@ pub fn writeExec(p: *Pardes, req: Req, serial: ?u32) Reply { defer p.exec_column = null; p.exec_header = true; defer p.exec_header = false; - if (pardes.ctlfs.ctl.captured(p, req, p.active, true, line, true)) |refusal| return refusal; + if (pardes.ctlfs.ctl.captured(p, req, p.view().active, true, line, true)) |refusal| return refusal; } return .{ .tag = req.tag, .written = @intCast(req.data.len) }; } @@ -220,7 +221,7 @@ test "New written to a column's exec makes its scratch in the session's director const serial = layout.columnSerial(p, 0); const exec_node = tree.Node.ofCol(serial, .exec); try testing.expectEqual(tree.Status.ok, th.wr(p, exec_node, "New\n").reply.status); - try testing.expectEqualStrings("/project/src/+New", p.panes[p.active].?.file.?.path); + try testing.expectEqualStrings("/project/src/+New", p.panes[p.view().active].?.file.?.path); } test "Joincol is refused when the joined column cannot give each pane its tag and 2 rows" { @@ -237,15 +238,15 @@ test "Joincol is refused when the joined column cannot give each pane its tag an var digits: [16]u8 = undefined; _ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{b})); _ = try th.newPane(p); - try testing.expectEqual(@as(usize, 2), p.ncol); - try testing.expect(p.cols[0].n >= 2 and p.cols[1].n >= 2); + try testing.expectEqual(@as(usize, 2), p.view().ncol); + try testing.expect(p.view().cols[0].n >= 2 and p.view().cols[1].n >= 2); // Focus in the left column: joined, four panes want 12 rows of 10. - const left = p.panes[p.cols[0].panes[0]].?.serial; + const left = p.panes[p.view().cols[0].panes[0]].?.serial; _ = th.wr(p, focus, try std.fmt.bufPrint(&digits, "{d}\n", .{left})); const r = th.wr(p, ctl, "Joincol\n"); try testing.expectEqual(tree.Status.err, r.reply.status); try testing.expect(std.mem.indexOf(u8, r.reply.ename, "tag and 2 rows") != null); - try testing.expectEqual(@as(usize, 2), p.ncol); + try testing.expectEqual(@as(usize, 2), p.view().ncol); try testing.expect(pardes.layout.minimaFit(p)); } @@ -253,7 +254,7 @@ test "pane/new takes rows from a pane in another column before refusing ENOSPC" const p = try pardes.Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 160, .rows = 16 }); defer p.deinit(); while (p.nextEffect()) |_| {} - const first = p.panes[p.active].?.serial; + const first = p.panes[p.view().active].?.serial; // A second column holding one tall pane. try testing.expectEqual(tree.Status.ok, th.wr(p, @backingInt(tree.TopFile.ctl), "Newcol\n").reply.status); const tall = try th.newPane(p); @@ -311,12 +312,12 @@ test "a Newcol refused because the tags would not fit logs its err alone and spe const made = try th.newPane(p); const pane = p.panes[p.paneBySerial(made).?].?; const col = layout.findPane(p, p.paneBySerial(made).?).?.col; - for (p.cols[col].panes[0..p.cols[col].n]) |k| { + for (p.view().cols[col].panes[0..p.view().cols[col].n]) |k| { const each = p.panes[k].?; if (each.tag.own) |old| p.gpa.free(old); each.tag.own = try p.gpa.dupe(u8, std.mem.asBytes(&@as([60][5]u8, @splat("word ".*)))); } - try testing.expect(p.cols[col].n >= 2); + try testing.expect(p.view().cols[col].n >= 2); p.sync(); const ctl = @backingInt(tree.TopFile.ctl); const focus = @backingInt(tree.TopFile.focus); @@ -354,7 +355,7 @@ test "a tagexec word that makes, acts on and focuses no pane reads back nothing" const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec); try testing.expectEqual(tree.Status.ok, th.wr(p, col_exec, "New\n").reply.status); var want: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.active].?.serial}), th.rd(p, col_exec, 0, 64).bytes); + try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.view().active].?.serial}), th.rd(p, col_exec, 0, 64).bytes); } test "New written to a column's ctl reads back the new pane alone, as its exec does" { @@ -365,7 +366,7 @@ test "New written to a column's ctl reads back the new pane alone, as its exec d const ctl_node = tree.Node.ofCol(layout.columnSerial(p, 0), .ctl); try testing.expectEqual(tree.Status.ok, th.wr(p, ctl_node, "New\n").reply.status); var want: [16]u8 = undefined; - try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.active].?.serial}), th.rd(p, root_exec, 0, 64).bytes); + try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{p.panes[p.view().active].?.serial}), th.rd(p, root_exec, 0, 64).bytes); } /// Whether `line` names a builtin that acts on a pane (every one of pane @@ -412,7 +413,7 @@ test "Help and Find at /tagexec act in the session's directory, not the keyboard const tagexec = @backingInt(tree.TopFile.tagexec); for ([_][]const u8{ "Help\n", "Find needle\n" }) |line| { try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, line).reply.status); - const made = p.panes[p.active].?.file.?.path; + const made = p.panes[p.view().active].?.file.?.path; try testing.expectEqualStrings(session, std.fs.path.dirname(made).?); } } @@ -421,11 +422,11 @@ test "a shell command at /tagexec or a column's exec is a command pane in the se const p = try Pardes.init(testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 30 }); defer p.deinit(); while (p.nextEffect()) |_| {} - const term = p.panes[p.active].?; - try testing.expect(pardes.exec.takesCommandLine(p, p.active)); + const term = p.panes[p.view().active].?; + try testing.expect(pardes.exec.takesCommandLine(p, p.view().active)); const col_exec = tree.Node.ofCol(layout.columnSerial(p, 0), .exec); for ([_]u64{ @backingInt(tree.TopFile.tagexec), col_exec }) |node| { - p.active = p.paneBySerial(term.serial).?; + p.view().active = p.paneBySerial(term.serial).?; const before = p.next_serial; const r = th.wr(p, node, "echo from-the-tag\n"); try testing.expectEqual(tree.Status.ok, r.reply.status); @@ -449,8 +450,8 @@ test "New and Term run at /tagexec and a column's exec, with no pane at all too" }; // Every pane gone: the workspace tag makes one all the same. for ([_][]const u8{ "New\n", "Term\n" }) |line| { - while (p.ncol > 0) { - const first = p.panes[p.cols[0].panes[0]].?.serial; + while (p.view().ncol > 0) { + const first = p.panes[p.view().cols[0].panes[0]].?.serial; _ = th.wr(p, tree.Node.of(first, .ctl), "delete\n"); if (panes.anyPane(p) == null) break; } @@ -495,7 +496,7 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in pub fn remove(p: *Pardes, req: Req, serial: u32, file: tree.ColFile) Reply { if (file != .dir) return Reply.fail(req.tag, E.PERM); const col = layout.columnBySerial(p, serial) orelse return Reply.fail(req.tag, E.NOENT); - if (p.cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl"); + if (p.view().cols[col].n > 0) return tree.failText(req.tag, E.NOTEMPTY, "column not empty: close its panes, or write Delcol to its ctl"); layout.removeColumn(p, col) catch return Reply.fail(req.tag, E.IO); return .{ .tag = req.tag }; } @@ -509,7 +510,7 @@ const Node = tree.Node; test "layout lists each column's place, panes and state, and the active one" { const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); - layout.newColumn(p, p.active); + layout.newColumn(p, p.view().active); p.sync(); const first_serial = layout.columnSerial(p, 0); const new_serial = layout.columnSerial(p, 1); @@ -517,7 +518,7 @@ test "layout lists each column's place, panes and state, and the active one" { const layout_node = @backingInt(tree.TopFile.layout); const text = th.rd(p, layout_node, 0, 4096).bytes; var want: [256]u8 = undefined; - const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.col_x[0], p.col_w[0], p.panes[0].?.serial }); + const first = try std.fmt.bufPrint(&want, "{d} 0 {d} {d} notcurrent full {d}\n", .{ first_serial, p.view().col_x[0], p.view().col_w[0], p.panes[0].?.serial }); try testing.expect(std.mem.startsWith(u8, text, first)); // Newcol gives the new, empty column's tag the keyboard. try testing.expect(std.mem.indexOf(u8, text, "current empty\n") != null); @@ -564,10 +565,10 @@ test "a focus write makes its pane's column the active one: layout says so and p const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const left = p.panes[0].?.serial; - layout.newColumn(p, p.active); - panes.newScratchFor(p, p.active, .fs); // fills the new, right column + layout.newColumn(p, p.view().active); + panes.newScratchFor(p, p.view().active, .fs); // fills the new, right column p.sync(); - try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.active).?.col); + try testing.expectEqual(@as(usize, 1), layout.findPane(p, p.view().active).?.col); var digits: [16]u8 = undefined; _ = th.wr(p, @backingInt(tree.TopFile.focus), try std.fmt.bufPrint(&digits, "{d}\n", .{left})); var want: [32]u8 = undefined; @@ -613,11 +614,11 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const first = layout.columnSerial(p, 0); - layout.newColumn(p, p.active); + layout.newColumn(p, p.view().active); const empty = layout.columnSerial(p, 1); // New on the empty column's ctl fills it, wherever the keyboard is. try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(empty, .ctl), "New\n").reply.status); - try testing.expectEqual(@as(usize, 1), p.cols[1].n); + try testing.expectEqual(@as(usize, 1), p.view().cols[1].n); try testing.expectEqual(E.INVAL, th.wr(p, Node.ofCol(empty, .ctl), "Exit\n").errno()); var rec: [64]u8 = undefined; try testing.expect(th.logHas(p, try std.fmt.bufPrint(&rec, "err - col/{d}/ctl: unknown control message \"Exit\"", .{empty}))); @@ -630,14 +631,14 @@ test "a column's ctl and exec act on it as its tag would, and rmdir closes it on try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(empty, .exec), "Delcol\n").reply.status); try testing.expectEqual(@as(?usize, null), layout.columnBySerial(p, empty)); // An empty column goes on rmdir. - layout.newColumn(p, p.active); + layout.newColumn(p, p.view().active); const made = layout.columnSerial(p, 1); try testing.expectEqual(tree.Status.ok, th.call(p, .{ .tag = 2, .op = .release, .node = Node.ofCol(made, .dir), .remove = true }).reply.status); try testing.expectEqual(@as(?usize, null), layout.columnBySerial(p, made)); try testing.expectEqual(first, layout.columnSerial(p, 0)); // Joincol folds a column into the one on its right, which keeps its own // serial and tag. - layout.newColumn(p, p.active); + layout.newColumn(p, p.view().active); const right = layout.columnSerial(p, 1); _ = th.wr(p, Node.ofCol(right, .tag), " Mine"); try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(first, .ctl), "Joincol\n").reply.status); @@ -654,7 +655,7 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back const tagexec = @backingInt(tree.TopFile.tagexec); try testing.expectEqual(tree.Status.ok, th.look_up(p, tree.root, "tagexec").reply.status); try testing.expectEqual(tree.Status.ok, th.wr(p, tagexec, "Newcol\n").reply.status); - try testing.expectEqual(@as(usize, 2), p.ncol); + try testing.expectEqual(@as(usize, 2), p.view().ncol); // Its announcement is the message row's, never logged; a pane's word // such as Msg is refused there. try testing.expect(!th.logHas(p, "msg - Newcol\n")); @@ -662,7 +663,7 @@ test "tagexec runs a word as a click in the workspace tag; exec files read back // A column's exec makes a pane there and reads it back. const right = layout.columnSerial(p, 1); try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(right, .exec), "New\n").reply.status); - const made = p.panes[p.cols[1].panes[0]].?.serial; + const made = p.panes[p.view().cols[1].panes[0]].?.serial; var want: [16]u8 = undefined; try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, Node.ofCol(right, .exec), 0, 64).bytes); try testing.expectEqualStrings(try std.fmt.bufPrint(&want, "{d}\n", .{made}), th.rd(p, tagexec, 0, 64).bytes); @@ -690,8 +691,8 @@ test "a word run from the workspace's or a column's tag runs in the session's di test "a command run from a column's tag gets its pane in that column, not the last" { const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); - layout.newColumn(p, p.active); - panes.newScratchFor(p, p.active, .fs); // fills the new, right column + layout.newColumn(p, p.view().active); + panes.newScratchFor(p, p.view().active, .fs); // fills the new, right column p.sync(); const left = layout.columnSerial(p, 0); try testing.expectEqual(tree.Status.ok, th.wr(p, Node.ofCol(left, .exec), "true\n").reply.status); @@ -716,7 +717,7 @@ test "a column's ctl refuses an unknown word and an argument as the other ctls d const extra = th.wr(p, ctl_node, "New extra\n"); try testing.expectEqual(E.INVAL, extra.errno()); try testing.expect(std.mem.startsWith(u8, extra.reply.ename, "wrong #args")); - try testing.expectEqual(@as(usize, 1), p.cols[0].n); + try testing.expectEqual(@as(usize, 1), p.view().cols[0].n); // A pane's bare answer and a winsize of no size say what they take. try testing.expectEqualStrings("answer takes a choice or -", th.wr(p, Node.of(p.panes[0].?.serial, .ctl), "answer\n").reply.ename); } |
