summaryrefslogtreecommitdiff
path: root/core/Term.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Term.zig')
-rw-r--r--core/Term.zig130
1 files changed, 130 insertions, 0 deletions
diff --git a/core/Term.zig b/core/Term.zig
index 968a8d68..580db4fa 100644
--- a/core/Term.zig
+++ b/core/Term.zig
@@ -403,6 +403,136 @@ pub fn hasImages(s: ?*const State) bool {
return o.hasImages(if (s) |state| state.impl else null);
}
+// ---- the boundary (S1): every call of the core's into its terminal ----
+
+/// Every call of the core's (core/, but this file and the module's own
+/// core/term/) into a terminal, by entry, its files and how many in each
+/// (a test's among them), and its rule: the emulator is outside the
+/// rollback copy and its digest is the terminal's (`State.digest`, which
+/// covers what abi/term.zig `replicated` lists a step reads, but the
+/// history's text). A READ from a step is covered by the digest or is
+/// said not to be; a WRITE outside the copy is never made by a unit kept
+/// to replay, or its record puts it back exactly; a LOCAL entry
+/// (abi/term.zig `local`) is never read into a step's state. A new call
+/// fails the test below until it is listed here with its rule (round 6's
+/// and pardes-image-loop's tables, kept as a test).
+pub const calls = [_]struct { []const u8, []const u8, []const u8 }{
+ // ---- writes: outside the copy ----
+ .{ "open", "dump.zig:1 panes.zig:1", "WRITE: a terminal made by a step (a shell's pane) or a load; a copy held across a pane's opening is let go (replica.zig `confirm`: serials)" },
+ .{ "close", "panes.zig:1", "WRITE: let go by a step that closes its pane: a copy held across it is let go (retiring panes); a unit that closes one is never kept over a copy" },
+ .{ "revive", "dump.zig:1", "WRITE: a load's (a join's dump, a Restore): no copy is held" },
+ .{ "reload", "panes.zig:1", "WRITE: a join's step remakes each terminal written since its last reload, on every side (panes.reloadTerminals, the session's choice taped, the snapshot's hash compared)" },
+ .{ "feed", "keys.zig:1 panes.zig:3", "WRITE: the pty's bytes in a unit, every side in the tape's order; a unit that feeds lets a copy held ahead go (`Term.writes`), so none is replayed (keys.zig's: a test's)" },
+ .{ "viewTo", "replica.zig:2", "WRITE: a rollback puts each view back by its row (`putViews`), exact since a reflow keeps a view a row (pardes-term-join-6)" },
+ .{ "scroll", "Core.zig:2 panes.zig:1", "WRITE: a step moves the view; outside the copy, put back by `putViews`" },
+ .{ "follow", "panes.zig:1", "WRITE: a step puts the view on the output; put back by `putViews`" },
+ .{ "resize", "panes.zig:1", "WRITE: a step's reflow; a speculation owes it (`touchTerminal`): its input is taken when confirmed, never as speculated" },
+ .{ "endOutputHere", "ninep/pty.zig:1", "WRITE: a 9P pty/run's step ends a command's output at the cursor: the session's step, replayed as such" },
+ .{ "replies", "Core.zig:1", "WRITE: a step drains the reply buffer (in the digest); only the session writes it to the pty (pty_write is off the tape)" },
+ // ---- reads by a step: in the digest ----
+ .{ "grid", "Core.zig:8 ansi.zig:4 body_layer.zig:5 draw.zig:3 dump.zig:4 echo.zig:8 edit.zig:1 exec.zig:3 keys.zig:3 layout.zig:2 mouse.zig:1 panes.zig:6 replica.zig:4", "READ: the size, the view, the cursor: in the digest (ansi.zig, body_layer.zig, draw.zig, echo.zig: a draw's)" },
+ .{ "modes", "Core.zig:5 draw.zig:1 dump.zig:2 echo.zig:3 exec.zig:3 mouse.zig:4 ninep/pty.zig:3 replica.zig:1", "READ: the program's modes (mouse, focus, bracketed paste, the alternate screen): in the digest (draw.zig, echo.zig: a draw's)" },
+ .{ "prompt", "Core.zig:1 builtins.zig:1 echo.zig:1 exec.zig:3 ninep/pty.zig:1 panes.zig:1", "READ: the OSC 133 cycle: in the digest (`marksOf`); Core.zig's and ninep/pty.zig's also taped (`.prompt`, each side's compared)" },
+ .{ "promptPrefix", "body_layer.zig:1 edit.zig:1 exec.zig:1", "READ: a row's prompt cells (`promptCut`): the active area's in the digest; a history row's text is not (below)" },
+ .{ "hasImages", "replica.zig:3 tagline.zig:1", "READ: whether it holds a kitty image (the tag's prefix): in the digest" },
+ .{ "key", "keys.zig:1", "READ: a key's bytes for the pty from its modes (in the digest): a write the session makes" },
+ .{ "mouse", "mouse.zig:4", "READ: a report's bytes from its modes (in the digest); the last cell told is the pane's (in the copy)" },
+ .{ "wheel", "mouse.zig:1", "READ: a wheel's report from its modes (in the digest)" },
+ .{ "paste", "edit.zig:1", "READ: a paste's bracketing from its modes (in the digest)" },
+ .{ "promptMoves", "keys.zig:1", "READ: the cursor keys a click at its prompt types, from the prompt's cells and the cursor (in the digest)" },
+ .{ "page", "Core.zig:1 ninep/ctl.zig:1", "PURE: a pager's parse of bytes the step holds; no emulator" },
+ .{ "filter", "File.zig:1", "PURE: a pager's colours from the theme; no emulator" },
+ .{ "spanColor", "File.zig:2", "PURE: as `filter`" },
+ // ---- reads by a step: NOT in the digest (the history's text) ----
+ .{ "scrollback", "Core.zig:3 Effect.zig:1 dump.zig:1 ninep/pane.zig:1 ninep/screen.zig:2", "READ, NOT COVERED: the history's text (a 9P read, a Save, an exit dump): each side fed the same bytes; a parting there is found when it reaches the core's state" },
+ .{ "scrollbackLen", "ninep/ctl.zig:1 ninep/pane.zig:1", "READ, NOT COVERED: the history's text's length (its row count is in the digest)" },
+ .{ "commandOutput", "ninep/pty.zig:1", "READ, NOT COVERED: a command's output rows (a 9P pty/run): taped as the session's answer" },
+ .{ "textRows", "edit.zig:2", "READ, NOT COVERED: every row's text, the history's among them (a selection, a Look over a shell)" },
+ .{ "viewport", "body_layer.zig:1 replica.zig:1", "READ: the view's rows' text (body_layer.zig: a draw's; replica.zig: a test's)" },
+ .{ "editRows", "ansi.zig:1", "READ: rows' text for a draw" },
+ // ---- local ----
+ .{ "due", "Core.zig:1", "LOCAL: its next wake (a blink, an animation): the loop's, never a step's state" },
+ .{ "cellPixels", "ansi.zig:1 panes.zig:2", "LOCAL: a frontend's draw sets its view's cell size (ansi.zig); a step sets the view's (in the digest) before each feed (panes.zig), so a reply to CSI 16 t is the step's" },
+ .{ "echoCell", "echo.zig:1", "LOCAL: the predicted echo's judge reads a cell; the echo is no core state" },
+ .{ "paint", "ansi.zig:1", "LOCAL: its cells drawn" },
+ .{ "images", "ansi.zig:1", "LOCAL: its kitty images drawn" },
+ .{ "start", "tape.zig:1", "LOCAL: the module's start, a test's (its own process's)" },
+ .{ "emulatorOf", "Core.zig:2 ninep/pty.zig:3", "the module's state itself: tests only" },
+};
+
+test "every call of the core's into a terminal is listed with its rule (S1): a new read, writer or local use fails until it is" {
+ const gpa = std.testing.allocator;
+ const io = std.testing.io;
+ var dir = try std.Io.Dir.cwd().openDir(io, "core", .{ .iterate = true });
+ defer dir.close(io);
+ var walker = try dir.walk(gpa);
+ defer walker.deinit();
+ var wrong: usize = 0;
+ var counts: std.StringHashMapUnmanaged(usize) = .empty;
+ defer {
+ var it = counts.keyIterator();
+ while (it.next()) |k| gpa.free(k.*);
+ counts.deinit(gpa);
+ }
+ while (try walker.next(io)) |e| {
+ if (e.kind != .file or !std.mem.endsWith(u8, e.basename, ".zig")) continue;
+ if (std.mem.eql(u8, e.path, "Term.zig") or std.mem.startsWith(u8, e.path, "term/")) continue;
+ const src = try e.dir.readFileAlloc(io, e.basename, gpa, .limited(16 << 20));
+ defer gpa.free(src);
+ var lines = std.mem.splitScalar(u8, src, '\n');
+ while (lines.next()) |line| {
+ if (std.mem.startsWith(u8, std.mem.trimStart(u8, line, " \t"), "//")) continue;
+ var at: usize = 0;
+ while (std.mem.indexOfPos(u8, line, at, "Term.")) |i| {
+ at = i + 5;
+ var end = at;
+ while (end < line.len and (std.ascii.isAlphanumeric(line[end]) or line[end] == '_')) end += 1;
+ if (end == at or end >= line.len or line[end] != '(' or !std.ascii.isLower(line[at])) continue;
+ if (i > 0 and (std.ascii.isAlphanumeric(line[i - 1]) or line[i - 1] == '_')) continue;
+ const k = try std.fmt.allocPrint(gpa, "{s} {s}", .{ line[at..end], e.path });
+ const got = try counts.getOrPut(gpa, k);
+ if (got.found_existing) {
+ gpa.free(k);
+ got.value_ptr.* += 1;
+ } else got.value_ptr.* = 1;
+ }
+ }
+ }
+ // Each listed file's count is what the tree has, and nothing else calls.
+ for (calls) |c| {
+ var files = std.mem.tokenizeScalar(u8, c[1], ' ');
+ while (files.next()) |fc| {
+ const colon = std.mem.lastIndexOfScalar(u8, fc, ':').?;
+ const want = try std.fmt.parseInt(usize, fc[colon + 1 ..], 10);
+ var buf: [256]u8 = undefined;
+ const pair = try std.fmt.bufPrint(&buf, "{s} {s}", .{ c[0], fc[0..colon] });
+ const have = counts.get(pair) orelse 0;
+ if (have == want) continue;
+ wrong += 1;
+ std.debug.print("core/{s}: {d} calls of Term.{s}, Term.zig's `calls` says {d}: {s}\n", .{ fc[0..colon], have, c[0], want, c[2] });
+ }
+ }
+ var it = counts.iterator();
+ while (it.next()) |kv| {
+ const space = std.mem.indexOfScalar(u8, kv.key_ptr.*, ' ').?;
+ const name = kv.key_ptr.*[0..space];
+ const file = kv.key_ptr.*[space + 1 ..];
+ if (listedCall(name, file)) continue;
+ wrong += 1;
+ std.debug.print("core/{s}: {d} calls of Term.{s}, not in Term.zig's `calls`: list it with its rule (a step's read the digest covers, a write the copy puts back, a local use)\n", .{ file, kv.value_ptr.*, name });
+ }
+ try std.testing.expectEqual(@as(usize, 0), wrong);
+}
+
+fn listedCall(name: []const u8, file: []const u8) bool {
+ for (calls) |c| {
+ if (!std.mem.eql(u8, c[0], name)) continue;
+ var files = std.mem.tokenizeScalar(u8, c[1], ' ');
+ while (files.next()) |fc| if (std.mem.eql(u8, fc[0..std.mem.lastIndexOfScalar(u8, fc, ':').?], file)) return true;
+ }
+ return false;
+}
+
// ---- a core without a terminal (core-test's) ----
test "a core without a terminal boots to a scratch pane" {