summaryrefslogtreecommitdiff
path: root/src/ninep/tree.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ninep/tree.zig')
-rw-r--r--src/ninep/tree.zig42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index ed0e0352..64089c01 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -219,6 +219,9 @@ pub const TopFile = enum(u5) {
tag,
col,
tagexec,
+ /// The files opened lately, closed ones too, a line each:
+ /// `open|closed <path>`, most recent first.
+ recent,
pub fn fileName(f: TopFile) []const u8 {
return if (f == .root) "/" else @tagName(f);
@@ -228,7 +231,7 @@ pub const TopFile = enum(u5) {
return switch (f) {
.root, .pane, .col => 0o755,
.look, .exec, .log, .focus, .ctl, .tag, .tagexec => 0o666,
- .README, .index, .status, .screen, .listeners, .new, .commands, .layout => 0o444,
+ .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent => 0o444,
};
}
@@ -239,6 +242,13 @@ pub const TopFile = enum(u5) {
pub const root: u64 = @intFromEnum(TopFile.root);
+fn recentLen(p: *Pardes) u64 {
+ var buf: [64]u8 = undefined;
+ var counting: std.Io.Writer.Discarding = .init(&buf);
+ pardes.panes.Output.recentText(p, &counting.writer, false) catch return 0;
+ return counting.fullCount();
+}
+
/// Declaration order is readdir order.
pub const PaneFile = enum(u5) {
dir = 0,
@@ -556,6 +566,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 {
},
.ctl => ctl.rootLen(p),
.commands => ctl.commandsLen(),
+ .recent => recentLen(p),
.focus => focus: {
if (p.header_focus) break :focus 0;
const pn = p.panes[p.active] orelse break :focus 0;
@@ -653,7 +664,7 @@ fn readdir(p: *Pardes, req: Req, target: Target) Reply {
.root => {
// The guide, then what describes the session, then the
// files that act, then the directories.
- inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.look, TopFile.exec, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| {
+ inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.look, TopFile.exec, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.pane, TopFile.col }) |t| {
if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, @intFromEnum(t), t.dir(), t.fileName());
}
if (skip > 0) skip -= 1 else stageDirent(out, p.gpa, fs.os_root, true, "os");
@@ -917,7 +928,11 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply {
last = serial;
const id = p.paneBySerial(serial).?;
const pn = p.panes[id].?;
- out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), pane.nameOf(pn), pane.columnOf(p, id) }) catch {};
+ // A name as /log shows it: one line of UTF-8, a
+ // newline in it `\n` (events.shown).
+ var name_buf: [4 * 4096]u8 = undefined;
+ const name = events.shown(pane.nameOf(pn), &name_buf);
+ out.print(p.gpa, "{d} {s} {d} {s} {d}\n", .{ serial, pane.kindOf(pn), @intFromBool(pane.dirtyOf(pn)), name, pane.columnOf(p, id) }) catch {};
}
break :index stagedReply(p, req);
},
@@ -929,6 +944,12 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply {
.focus => ctl.readFocus(p, req),
.ctl => ctl.readRoot(p, req),
.commands => ctl.readCommands(p, req),
+ .recent => recent: {
+ var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
+ pardes.panes.Output.recentText(p, &text.writer, false) catch break :recent Reply.fail(req.tag, E.NOMEM);
+ p.fs.stage(p.gpa).appendSlice(p.gpa, text.written()) catch break :recent Reply.fail(req.tag, E.NOMEM);
+ break :recent stagedReply(p, req);
+ },
.layout => layout: {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
cols.writeLayout(p, &text.writer) catch break :layout Reply.fail(req.tag, E.NOMEM);
@@ -1007,7 +1028,7 @@ fn write(p: *Pardes, req: Req, target: Target) Reply {
if (o.what != .lines and o.what != .ctl) return writeNow(p, req, target);
// A clicked line holds no control character: refused at once, not held
// to fail unseen at the close.
- if (resultsFile(target)) for (req.data) |c| if (c < ' ' and c != '\t' and c != '\n' and c != '\r') return Reply.fail(req.tag, E.INVAL);
+ if (resultsFile(target)) for (req.data) |c| if ((c < ' ' and c != '\t' and c != '\n' and c != '\r') or c == 0x7f) return failText(req.tag, E.INVAL, ctl.e_control);
o.pending.appendSlice(p.gpa, req.data) catch return Reply.fail(req.tag, E.NOMEM);
const end = ctl.completeEnd(p, o.pending.items);
if (end == 0) {
@@ -1197,13 +1218,13 @@ test "readdir lists the root and a pane directory without creating anything" {
@memcpy(top_bytes[0..top_reply.bytes.len], top_reply.bytes);
const top = th.dirents(top_bytes[0..top_reply.bytes.len], &buf);
try testing.expect(top.len >= 10);
- for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| {
+ for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "col", "os" }, 0..) |name, i| {
try testing.expectEqualStrings(name, top[i].name);
- try testing.expectEqual(i >= 14, top[i].dir);
+ try testing.expectEqual(i >= 15, top[i].dir);
}
- try testing.expectEqual(@intFromEnum(TopFile.pane), top[14].node);
- try testing.expectEqual(@intFromEnum(TopFile.col), top[15].node);
- try testing.expectEqual(fs.os_root, top[16].node);
+ try testing.expectEqual(@intFromEnum(TopFile.pane), top[15].node);
+ try testing.expectEqual(@intFromEnum(TopFile.col), top[16].node);
+ try testing.expectEqual(fs.os_root, top[17].node);
var idbuf: [16]u8 = undefined;
try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null);
try testing.expect(th.nameAt(top, "self") == null);
@@ -1466,6 +1487,9 @@ test "at the pane cap, pane/new, look and New each say so, and look reads back e
const looked = th.wr(p, look_node, try std.fmt.bufPrint(&line, "{s}/f.txt\n", .{dir}));
try testing.expect(looked.errno() != 0);
try testing.expect(std.mem.indexOf(u8, looked.reply.ename, said) != null);
+ // Its err record names the file once: `look: no space...`.
+ try testing.expect(th.logHas(p, "look: no space"));
+ try testing.expect(!th.logHas(p, "look: look:"));
try testing.expectEqualStrings("", th.rd(p, look_node, 0, 64).bytes);
// New from a pane's ctl fails as well.
const ctl_node = Node.of(p.panes[0].?.serial, .ctl);