summaryrefslogtreecommitdiff
path: root/src/ninep/cols.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/cols.zig')
-rw-r--r--src/ninep/cols.zig66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/ninep/cols.zig b/src/ninep/cols.zig
index 7eb08ba9..5218b937 100644
--- a/src/ninep/cols.zig
+++ b/src/ninep/cols.zig
@@ -36,7 +36,7 @@ pub fn writeLayout(p: *Pardes, w: *std.Io.Writer) std.Io.Writer.Error!void {
const active = activeColumn(p);
for (0..p.view().ncol) |c| {
try w.print("{d} {d} {d} {d} {s} {s}", .{
- layout.columnSerial(p, c), c, v.col_x[c], v.col_w[c],
+ 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 (v.cols[c].panes[0..p.view().cols[c].n]) |id| if (p.panes[id]) |pane| try w.print(" {d}", .{pane.serial});
@@ -212,6 +212,38 @@ pub fn writeExec(p: *Pardes, req: Req, serial: ?u32) Reply {
return .{ .tag = req.tag, .written = @intCast(req.data.len) };
}
+/// Whether `line` names a builtin that acts on a pane (every one of pane
+/// scope, Edit too, which the root's ctl takes at the active pane) and is
+/// not one of `own`, the words its tag holds by default: those a tag no
+/// pane owns refuses, never doing them at the pane with the keyboard.
+fn paneWord(line: []const u8, own: []const u8) bool {
+ const cmd = pardes.exec.commandText(line);
+ const word = cmd[0 .. std.mem.indexOfAny(u8, cmd, " \t+") orelse cmd.len];
+ const b = std.meta.stringToEnum(pardes.builtins.registry.Builtin(), word) orelse return false;
+ if (pardes.builtins.registry.scope(b) == .session) return false;
+ // A new pane is every tag's to make, in the session's directory.
+ if (b == .New or b == .Term) return false;
+ var words = std.mem.tokenizeScalar(u8, own, ' ');
+ while (words.next()) |w| if (std.mem.eql(u8, w, word)) return false;
+ return true;
+}
+
+/// rmdir of a column closes it when it is empty; one with panes is
+/// refused, saying so (close them, or Delcol on its ctl, which asks first).
+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.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 };
+}
+
+// ---- tests ----
+
+const testing = std.testing;
+const th = @import("testing.zig");
+const Node = tree.Node;
+
test "New written to a column's exec makes its scratch in the session's directory, as tagexec's does" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -369,22 +401,6 @@ test "New written to a column's ctl reads back the new pane alone, as its exec d
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
-/// scope, Edit too, which the root's ctl takes at the active pane) and is
-/// not one of `own`, the words its tag holds by default: those a tag no
-/// pane owns refuses, never doing them at the pane with the keyboard.
-fn paneWord(line: []const u8, own: []const u8) bool {
- const cmd = pardes.exec.commandText(line);
- const word = cmd[0 .. std.mem.indexOfAny(u8, cmd, " \t+") orelse cmd.len];
- const b = std.meta.stringToEnum(pardes.builtins.registry.Builtin(), word) orelse return false;
- if (pardes.builtins.registry.scope(b) == .session) return false;
- // A new pane is every tag's to make, in the session's directory.
- if (b == .New or b == .Term) return false;
- var words = std.mem.tokenizeScalar(u8, own, ' ');
- while (words.next()) |w| if (std.mem.eql(u8, w, word)) return false;
- return true;
-}
-
test "a pane's word written to /tagexec or a column's exec is refused, and acts on no pane" {
const p = try th.withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -491,22 +507,6 @@ test "every pane word a tag no pane owns does not hold is refused there, Edit in
try testing.expectEqualStrings("keep me\n", p.panes[0].?.file.?.content);
}
-/// rmdir of a column closes it when it is empty; one with panes is
-/// refused, saying so (close them, or Delcol on its ctl, which asks first).
-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.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 };
-}
-
-// ---- tests ----
-
-const testing = std.testing;
-const th = @import("testing.zig");
-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();