summaryrefslogtreecommitdiff
path: root/src/ninep
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
committerGabriel Schneider <[email protected]>2026-10-31 06:28:48 -0300
commita479792a1ab2b593642d7f648194bfa23ce01dba (patch)
tree96ddee7d879a9084daa07db43b0b7910b072a785 /src/ninep
parente179cc44fe5060c76a5b00c41e53f11209f5acd9 (diff)
parent4c761893e5b3fdae422622cfa02104ab36633045 (diff)
downloadpardes-a479792a1ab2b593642d7f648194bfa23ce01dba.tar.gz
pardes-a479792a1ab2b593642d7f648194bfa23ce01dba.zip
Merge the upstream daemon and replicated client/server refactor
Diffstat (limited to 'src/ninep')
-rw-r--r--src/ninep/ctl.zig118
-rw-r--r--src/ninep/events.zig24
-rw-r--r--src/ninep/pane.zig3
-rw-r--r--src/ninep/pty.zig16
-rw-r--r--src/ninep/tree.zig4
5 files changed, 65 insertions, 100 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index d0d9b0b4..2859304a 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -524,10 +524,12 @@ fn checkBuiltin(p: *Pardes, req: Req, line: []const u8, scope: builtins.Scope) ?
break now;
} else typed;
const arg = if (sp) |s| std.mem.trim(u8, line[s + 1 ..], " \t") else "";
- const b = std.meta.stringToEnum(Builtin, word) orelse {
+ const here = if (std.meta.stringToEnum(Builtin, word)) |b| builtins.registry.here(p, b) else false;
+ const b = (if (here) std.meta.stringToEnum(Builtin, word) else null) orelse {
// A setting this build's frontend cannot show (Lift, GripWidth on a
- // terminal) is known, and says so rather than sound misspelt.
- if (builtins.absentWhy(word) orelse if (config.Runtime.find(word) != null) @as([]const u8, "GUI-only") else null) |absent| {
+ // terminal, the window's own words in a terminal's view) is known,
+ // and says so rather than sound misspelt.
+ if (builtins.absentWhy(word) orelse if (config.Runtime.find(word) != null or std.meta.stringToEnum(Builtin, word) != null) @as([]const u8, "GUI-only") else null) |absent| {
var why: [64]u8 = undefined;
// EINVAL, a request this build cannot take, in words 9ns reads
// as that: `invalid`.
@@ -618,18 +620,24 @@ const e_prompt = "control message needs its argument";
/// What is not a setting -- platform, themes, where the config came from --
/// is /status's or the DumpConfig window's.
fn writeSettings(p: *Pardes, w: *std.Io.Writer) !void {
- try writeSettingsOf(p, &p.settings, w);
+ try writeSettingsFor(p, &p.settings, w, builtins.viewCapabilities(p));
try w.writeAll("LocationsConfig ");
try p.locations_config.write(w);
try w.writeByte('\n');
- if (comptime builtins.Pet.enabled) try w.print("Pet {s}\n", .{@tagName(p.settings.pet)});
+ if (comptime builtins.Pet.enabled) if (builtins.registry.here(p, .Pet)) try w.print("Pet {s}\n", .{@tagName(p.settings.pet)});
}
/// The setting words of `s`, one a line, as the root ctl reads them; a Dump
/// keeps those that differ from a fresh session's (dump.zig).
pub fn writeSettingsOf(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer) !void {
- inline for (config.Runtime.settings) |setting| {
+ return writeSettingsFor(p, s, w, builtins.capabilities);
+}
+
+/// ...those a frontend of `caps` takes (the root ctl's: the live view's).
+fn writeSettingsFor(p: *Pardes, s: *const config.Runtime, w: *std.Io.Writer, caps: config.Runtime.Capabilities) !void {
+ inline for (config.Runtime.settings) |setting| skip: {
if (comptime !setting.enabled(builtins.capabilities)) continue;
+ if (!setting.enabled(caps)) break :skip;
const word = setting.word;
switch (setting.action) {
.toggle => |field| try w.print("{s} {s}\n", .{ word, if (@field(s, @tagName(field))) "on" else "off" }),
@@ -909,8 +917,10 @@ fn stripCitations(text: []u8) []u8 {
return text[0..out];
}
-fn writeCommands(w: *std.Io.Writer) !void {
+fn writeCommands(p: *const Pardes, w: *std.Io.Writer) !void {
for (std.enums.values(Builtin)) |b| {
+ // A window's own word is none in a terminal's view.
+ if (!builtins.registry.here(p, b)) continue;
// Edit is a pane's word the root's ctl takes too, at the active pane.
const scope: []const u8 = if (b == .Edit) "both" else if (builtins.registry.scope(b) == .session) "root" else "pane";
try w.print("{s}{s} {s}", .{
@@ -938,16 +948,16 @@ fn writeCommands(w: *std.Io.Writer) !void {
}
}
-pub fn commandsLen() u64 {
+pub fn commandsLen(p: *const Pardes) u64 {
var buf: [256]u8 = undefined;
var counting: std.Io.Writer.Discarding = .init(&buf);
- writeCommands(&counting.writer) catch return 0;
+ writeCommands(p, &counting.writer) catch return 0;
return counting.fullCount();
}
pub fn readCommands(p: *Pardes, req: Req) Reply {
var text: std.Io.Writer.Allocating = .init(p.scratch.allocator());
- writeCommands(&text.writer) catch return Reply.fail(req.tag, E.NOMEM);
+ writeCommands(p, &text.writer) catch return Reply.fail(req.tag, E.NOMEM);
p.fs.stage(p.gpa).appendSlice(p.gpa, text.written()) catch return Reply.fail(req.tag, E.NOMEM);
return tree.stagedReply(p, req);
}
@@ -1362,7 +1372,9 @@ test "commands lists every builtin with its argument and the ctl that takes it"
// Then, where the source has one, ` -- ` and what it does.
if (words.next()) |dashes| try testing.expectEqualStrings("--", dashes);
}
- try testing.expectEqual(std.enums.values(Builtin).len, lines);
+ var here: usize = 0;
+ for (std.enums.values(Builtin)) |b| here += @intFromBool(builtins.registry.here(p, b));
+ try testing.expectEqual(here, lines);
for ([_][]const u8{ "\nDel arg pane -- ", "\nNewcol root -- ", "\nSave arg pane", "\nVerbose arg root on,off", "\nPlacement arg root acme,pardes", "\nUndo pane -- ", "\nEdit arg both -- acme's Edit" }) |row|
try testing.expect(std.mem.indexOf(u8, listed.bytes, row) != null);
}
@@ -1738,6 +1750,8 @@ test "status reads the editor, and look and exec validate whole batches" {
const gpa = testing.allocator;
const p = try withFile(gpa, "Msg root\n");
defer p.deinit();
+ // A terminal's view first (a window's build starts windowed).
+ p.windowed = false;
const status = rd(p, root_status, 0, 4096);
try testing.expectEqual(Status.ok, status.reply.status);
var lines = std.mem.tokenizeScalar(u8, status.bytes, '\n');
@@ -2075,8 +2089,7 @@ test "Zerox twins dump their text once and come back on one buffer from a Restor
try pardes.dump.dumpState(p);
const text = p.dump_out.?;
// The text is kept once though three panes show it.
- const encoded = try pardes.dump.encodeBytes(p.scratch.allocator(), p.panes[0].?.file.?.content);
- try testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, encoded));
+ try testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, p.panes[0].?.file.?.content));
const restored = try pardes.dump.restore(p, text, "/tmp/pardes.dump.zon");
defer restored.deinit();
var files: [3]*pardes.panes.File.State = undefined;
@@ -2838,7 +2851,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, line);
try testing.expectEqual(E.IO, refused.errno());
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: line 1: ") != null);
+ try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: it does not begin as one") != null);
try testing.expect(p.restore_req == null);
try testing.expect(p.panes[0].?.discard_warned == null);
@@ -2856,7 +2869,7 @@ test "a setting this frontend cannot show says GUI-only, and DumpDir reads back
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
const root_ctl = @backingInt(tree.TopFile.ctl);
- if (!builtins.capabilities.lift) {
+ if (!builtins.viewCapabilities(p).lift) {
try testing.expectEqualStrings("Lift is GUI-only, invalid here \"Lift\"", wr(p, root_ctl, "Lift on\n").reply.ename);
try testing.expectEqualStrings("GripWidth is GUI-only, invalid here \"GripWidth\"", wr(p, root_ctl, "GripWidth 120\n").reply.ename);
// A builtin the GUI alone has, written to a ctl or an exec, never
@@ -4676,9 +4689,8 @@ test "pager answers its +Pager on the open that asked, whatever another client e
try testing.expectEqualStrings("/tmp/+Pager", second_pane.file.?.path);
try testing.expect(p.paneBySerial(paged) != null);
_ = call(p, .{ .tag = 14, .op = .release, .node = pager, .handle = resolved, .opened = true });
- // One that may not be written is refused, permission denied.
- if (comptime @import("builtin").os.tag == .linux)
- try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno());
+ // One that may not be written is refused, permission denied (Linux's /proc/1).
+ if (comptime @import("builtin").os.tag == .linux) try testing.expectEqual(E.PERM, wr(p, pager, "/proc/1\n").errno());
// One directory a write, absolute, and there.
try testing.expectEqual(E.INVAL, wr(p, pager, "/a\n/b\n").errno());
// One directory an open: one refused is not followed by another, as a
@@ -4787,8 +4799,11 @@ test "a command pane an exec open was answered is leased to it while it stays op
test "a Save whose directory is missing because one above refuses says permission denied, not no such directory" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
- p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound);
- try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied"));
+ // The refusing directory is Linux's /proc/1/root.
+ if (comptime @import("builtin").os.tag == .linux) {
+ p.saveFailed(0, "/proc/1/root/x/f.txt", error.FileNotFound);
+ try testing.expect(th.logHas(p, "Save /proc/1/root/x/f.txt: permission denied"));
+ }
p.saveFailed(0, "/tmp/pardes-surely-missing-dir/f.txt", error.FileNotFound);
try testing.expect(th.logHas(p, "no such directory"));
}
@@ -4897,46 +4912,6 @@ test "Petscii, Palette and Ascii take the state their tag word names, set rather
try testing.expect(th.logHas(p, "Petscii takes on or off"));
}
-test "a Restore reads a clean file from disk; an unsaved one whose file changed since is said so, and its first Save asks" {
- if (comptime !pardes.hosted) return;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\n" });
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- var path_buf: [4200]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/a.txt", .{dir});
- const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- // Clean: the dump keeps no text, and the newer disk is what comes back.
- try pardes.dump.dumpState(p);
- try testing.expect(std.mem.indexOf(u8, p.dump_out.?, "b25lCg==") == null); // "one\n" in base64
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "two\n" });
- {
- const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
- defer restored.deinit();
- const f = pane_files.fileOf(restored.panes[0].?).?;
- try testing.expectEqualStrings("two\n", f.content);
- try testing.expectEqual(f.saved_revision, f.revision);
- }
- // Unsaved: its text comes back, the disk changed under it is said, and
- // Save asks once before overwriting it.
- const f = pane_files.fileOf(p.panes[0].?).?;
- const edited = try gpa.dupe(u8, "edited\n");
- pardes.panes.File.setContent(p, f, edited);
- try testing.expect(f.revision != f.saved_revision);
- try pardes.dump.dumpState(p);
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "three\n" });
- const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
- defer restored.deinit();
- const rf = pane_files.fileOf(restored.panes[0].?).?;
- try testing.expectEqualStrings("edited\n", rf.content);
- try testing.expect(rf.disk_newer != null);
- pardes.exec.saveFile(restored, 0);
- try testing.expect(th.logHas(restored, "modified on disk since read (Save again to overwrite)"));
-}
-
test "a Rename the server answered for this file alone, with other open files saying the name, is previewed and says so" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -5037,8 +5012,10 @@ test "DumpDir refuses a relative directory and one that may not be written, up f
defer p.deinit();
const root_ctl = @backingInt(tree.TopFile.ctl);
try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir dumps\n").errno());
- try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno());
try testing.expectEqual(Status.ok, wr(p, root_ctl, "DumpDir /tmp/pardes-dumps-test\n").reply.status);
+ // The refusing directory is Linux's /proc/1/root.
+ if (comptime @import("builtin").os.tag != .linux) return;
+ try testing.expectEqual(E.INVAL, wr(p, root_ctl, "DumpDir /proc/1/root/dumps\n").errno());
p.fs.late_failure_len = 0;
p.dumpFailed("/proc/1/root/x/pardes.dump.zon", error.FileNotFound);
try testing.expect(std.mem.endsWith(u8, p.fs.late_failure[0..p.fs.late_failure_len], ": permission denied"));
@@ -5082,25 +5059,6 @@ test "a command or a terminal refused for room is refused before anything is log
}
}
-test "an unsaved pane from a dump that says nothing of its disk asks at its first Save" {
- if (comptime !pardes.hosted) return;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "old.txt", .data = "disk\n" });
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- var path_buf: [4200]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/old.txt", .{dir});
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const id = p.freeSlot().?;
- const pane = try pardes.panes.File.restore(p, id, .{ .kind = .file, .tag = "", .body = "", .file = .{ .path = path, .content = "unsaved\n", .dirty = true } });
- try testing.expect(pane.file.?.disk_newer != null);
- pardes.exec.saveFile(p, id);
- try testing.expect(th.logHas(p, "modified on disk since read (Save again to overwrite)"));
-}
-
test "a Mount of a socket path that is not there says no such socket, ENOENT" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 78788c3c..f24c6120 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -1305,27 +1305,23 @@ test "a Dump written and a Restore made are in the log, with their files" {
var want: [64]u8 = undefined;
try testing.expect(std.mem.indexOf(u8, log.bytes, try std.fmt.bufPrint(&want, "{s} /tmp/pardes.dump.zon\n", .{what})) != null);
}
- // The replacement's last says which serial each pane had.
- const log = try freezeLog(restored);
- defer restored.gpa.free(log.bytes);
- var want: [64]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, log.bytes, try std.fmt.bufPrint(&want, "restore /tmp/pardes.dump.zon\nrestored {d} {d}\n", .{ p.panes[0].?.serial, restored.panes[0].?.serial })) != null);
- // ...and each column's: restoredcol <old> <new>.
- try testing.expect(std.mem.endsWith(u8, log.bytes, try std.fmt.bufPrint(&want, "restoredcol {d} {d}\n", .{ pardes.layout.columnSerial(p, 0), pardes.layout.columnSerial(restored, 0) })));
+ // Its panes and columns are the dump's, serials and all.
+ try testing.expectEqual(p.panes[0].?.serial, restored.panes[0].?.serial);
+ try testing.expectEqual(pardes.layout.columnSerial(p, 0), pardes.layout.columnSerial(restored, 0));
}
-test "a Restore gives columns fresh serials, past every serial the old session handed out" {
+test "after a Restore a new pane or column takes a serial past every one the old session handed out" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
- const first = pardes.layout.columnSerial(p, 0);
- // Serials spent on columns since deleted.
- p.next_column_serial += 5;
- const spent = p.next_column_serial;
try dump.dumpState(p);
+ // Serials spent since the dump, on panes and columns since deleted.
+ p.next_serial += 5;
+ p.next_column_serial += 5;
+ const spent = p.next_serial;
+ const spent_col = p.next_column_serial;
const restored = try dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
defer restored.deinit();
- for (0..restored.ncol) |c| try testing.expect(pardes.layout.columnSerial(restored, c) >= spent);
- try testing.expect(pardes.layout.columnSerial(restored, 0) != first);
+ try testing.expect(restored.next_serial >= spent and restored.next_column_serial >= spent_col);
}
test "a pane named before it is announced has its new under that name, and no rename before it" {
diff --git a/src/ninep/pane.zig b/src/ninep/pane.zig
index f9112ae2..33f816fe 100644
--- a/src/ninep/pane.zig
+++ b/src/ninep/pane.zig
@@ -1002,8 +1002,7 @@ pub fn nameBuffer(p: *Pardes, id: usize, full: []const u8, preserve_tag: bool) !
f.highlight_start = 0;
f.syntax_dirty = true;
f.context_revision = null;
- pane.context_rows = 0;
- pane.wrap_n = 0;
+ pane.geometry_key = 0;
look.invalidateLookHover(p, id);
p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } });
events.noteLog(p, .rename, pane);
diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig
index d80f7175..ee8c618e 100644
--- a/src/ninep/pty.zig
+++ b/src/ninep/pty.zig
@@ -86,7 +86,7 @@ pub fn writeCtl(p: *Pardes, req: Req, id: usize) Reply {
if (comptime pardes.hosted) if (!apply and std.mem.eql(u8, line, "exec")) if (p.panes[id]) |pane| {
const bin = pane.shell orelse p.shellBin();
var why: [320]u8 = undefined;
- if (@import("../host_io.zig").Shell.refusal(bin[0..@min(bin.len, 200)], &why)) |refused|
+ if (pardes.tape.value(.shell, @import("../host_io.zig").Shell.refusal, .{ bin[0..@min(bin.len, 200)], &why })) |refused|
return tree.failText(req.tag, E.NOENT, std.fmt.bufPrint(&p.fs.ename, "exec: {s}", .{refused}) catch "exec: no such shell");
};
if (!verb(p, id, line, apply)) return tree.failText(req.tag, E.INVAL, if (tooFewRows(line)) e_winsize_rows else if (outOfRange(line)) e_winsize_range else e_bad_pty_ctl);
@@ -378,9 +378,11 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void {
/// Answers a run whose command ended with `status`: the header and the
/// output it printed.
fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void {
- const printed = pardes.panes.terminal.commandOutput(pane, p.gpa, output_rows) catch
+ // As the authority's emulator has it (taped): a screen-state replica's
+ // is its deltas', which a lagging client's can be states behind, its
+ // pins in pages it never had (ghostty's leftWrap overflowed on one).
+ const printed = pardes.tape.value(.prompt, printedBy, .{ pane, p.scratch.allocator() }) orelse
return answer(p, slot, "error out of memory", .{});
- defer p.gpa.free(printed.text);
// Keep the tail, cut at a line start so the first line kept is whole.
var keep: []const u8 = printed.text;
if (keep.len > output_cap) {
@@ -409,6 +411,14 @@ fn finish(p: *Pardes, slot: *Run, pane: *Pane, status_code: ?i32) void {
answer(p, slot, "exit {s}", .{status});
}
+pub const Printed = struct { text: []const u8, whole: bool };
+
+/// What pane `pane`'s command printed (terminal.commandOutput), in `arena`.
+fn printedBy(pane: *Pane, arena: std.mem.Allocator) ?Printed {
+ const out = pardes.panes.terminal.commandOutput(pane, arena, output_rows) catch return null;
+ return .{ .text = out.text, .whole = out.whole };
+}
+
/// The shell itself exited (a run's `exit 3`, or one typed): a run waiting
/// on the command it ran answers with the shell's status and what it
/// printed, and the log says `exit` before the pane's `del`. Unknown, the
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig
index 7b107ea7..bd87f5bc 100644
--- a/src/ninep/tree.zig
+++ b/src/ninep/tree.zig
@@ -678,7 +678,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 {
// one (a 9ns mount's splice), and a follower's reads go past it.
.log => 0,
.ctl => ctl.rootLen(p),
- .commands => ctl.commandsLen(),
+ .commands => ctl.commandsLen(p),
.focus => focus: {
if (p.header_focus) break :focus 0;
const pn = p.panes[p.active] orelse break :focus 0;
@@ -1192,6 +1192,8 @@ fn linesOpen(target: Target, req: Req) bool {
/// The editor's step: the last lines of closed opens run, each as a write
/// of its own; a refusal is the log's err, as no open is left to answer.
pub fn runClosedLines(p: *Pardes) void {
+ const taped = pardes.tape.enter(p, .run_closed_lines);
+ defer pardes.tape.leave(p, taped);
for (p.fs.closed_lines.items) |*line| {
defer line.bytes.deinit(p.gpa);
const t = Node.target(line.node) orelse continue;