summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Term.zig130
-rw-r--r--core/root.zig4
-rw-r--r--core/term/terminal.zig19
3 files changed, 147 insertions, 6 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" {
diff --git a/core/root.zig b/core/root.zig
index 171bdfef..0e02a9bc 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -643,7 +643,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{
.{ "ninep/pty.zig", 1, "a 9P exec's shell check (tape.site(.shell))" },
.{ "ninep/screen.zig", 1, "a 9P address's text type" },
.{ "ninep/tree.zig", 1, "the daemon's registry (/sessions, tape.site(.sessions))" },
- .{ "term/terminal.zig", 2, "the emulator's image files (TMPDIR) and its Io: the session's emulator (a client's are written by deltas)" },
+ .{ "term/terminal.zig", 2, "the emulator's image files (TMPDIR) and its Io: each side's emulator, a medium's read taped (Term.media)" },
};
/// The lines of `src` that name the machine (`machine_lines`'s rules).
@@ -738,7 +738,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Core.zig", "surface facts frames own_frames chrome frame_arena scratch echo undrawn", "the frame's own and the views drawn here: written by frames (and chrome by a theme's step), read by frames and the runner; no step reads them" },
.{ "Core.zig", "needs_frame", "whether to draw: steps set it, the loop reads it; no step's outcome reads it" },
.{ "Core.zig", "effects effects_head effects_len in_q in_head in_len opts dump_out dump_export tape", "this process's queues, options and tape, drained or set by its host" },
- .{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; a terminal is in no digest (Term.zig)" },
+ .{ "Core.zig", "shell_rows", "a terminal's rows as read here, swept at every update; the terminal's own digest covers its active area, not its history (Term.zig `calls`)" },
.{ "Core.zig", "diff_output locations_cache tty_filter_palette body_chrome", "caches of pure functions of their key (a text, a theme): a step finds what it would make; a query row's colours from them are out of its digest (locations.Row.digest), and what a step asks a worker to paint is never decided by them (Stream.paintRows)" },
.{ "Core.zig", "retired_panes", "panes torn down this step, freed at its end" },
.{ "Core.zig", "distrusted frames tape", "Options: the client's own list, its runner's statistics, its tape" },
diff --git a/core/term/terminal.zig b/core/term/terminal.zig
index f130d7b9..44038a18 100644
--- a/core/term/terminal.zig
+++ b/core/term/terminal.zig
@@ -211,10 +211,22 @@ pub fn digest(s: *const State, h: *std.hash.Wyhash, view: bool) void {
const sb = screen.pages.scrollbar();
const cur = screen.cursor;
const offset = if (view) sb.offset else 0;
- // Whether it holds a kitty image: the tag says so (tagline.zig).
- const facts = .{ sb.total, offset, sb.len, cur.x, cur.y, s.vt.modes.get(.cursor_visible), s.vt.screens.active_key, s.reply_dropped, hasImages(s) };
+ // Everything a step reads of it (abi/term.zig `replicated`): its
+ // size, the view and the cursor, its modes (the alternate screen,
+ // the mouse's, focus reports, bracketed paste: `modes`), whether it
+ // holds a kitty image (the tag says so: tagline.zig), the reply
+ // buffer, the OSC 133 cycle (`prompt`), the active area's text. Not
+ // the history's text, only its length (a step's read of it: not
+ // covered; core/Term.zig `calls`).
+ const Modes = @TypeOf(s.vt.modes.values);
+ const mode_bits: @Int(.unsigned, @bitSizeOf(Modes)) = @bitCast(s.vt.modes.values);
+ const modes_word: @Int(.unsigned, (@bitSizeOf(Modes) + 7) / 8 * 8) = mode_bits;
+ const mouse_flags: [2]u8 = .{ @intCast(@intFromEnum(s.vt.flags.mouse_event)), @intCast(@intFromEnum(s.vt.flags.mouse_format)) };
+ const facts = .{ s.vt.cols, s.vt.rows, sb.total, offset, sb.len, cur.x, cur.y, modes_word, s.vt.screens.active_key, mouse_flags, s.reply_dropped, hasImages(s) };
inline for (facts) |fact| h.update(std.mem.asBytes(&fact));
h.update(s.reply[0..s.reply_len]);
+ var marks: [marks_len]u8 = undefined;
+ h.update(marksOf(s, &marks));
var buf: [4096]u8 = undefined;
var text: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(h.*, &buf);
if (screen.pages.getBottomRight(.active)) |br|
@@ -457,8 +469,7 @@ pub fn grid(state: ?*const State) Term.Grid {
}
/// What pardes made of a terminal's stream that its emulator does not hold
-/// (the OSC 133 cycle, MarkedHandler), as bytes two terminals' compare by
-/// (`expectSame`): phase u8, started, prompts, declined u32, continuation
+/// (the OSC 133 cycle, MarkedHandler), as bytes its digest holds: phase u8, started, prompts, declined u32, continuation
/// and lost u8, a finished command's seq u32 and status i32 (all ones:
/// none; i32 min: no status).
const marks_len = 1 + 4 * 3 + 2 + 4 + 4;