summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 15:58:05 -0300
committerGabriel Schneider <[email protected]>2026-11-06 17:53:43 -0300
commit75e4787be773c8cbfd2e60e59d409b9556898365 (patch)
tree7426b4184644e794c2abb2d7012461270b3ee43f /src
parent31c77aa3f259e99a9723e188b77b651e5cd31621 (diff)
downloadpardes-75e4787be773c8cbfd2e60e59d409b9556898365.tar.gz
pardes-75e4787be773c8cbfd2e60e59d409b9556898365.zip
kinds #35, the core's seam for ABI 3 (Kind.zig): each pane of a kind with view told each open view's facts by id when they change (the slot's view table, a hash a view, a stopped view told cols 0, and a step woken for a view a frame's layout changed) and ticked after, the tick's pa_tick and its prefix (placed and retag gone: the art words go on every pane of a PA_PICTURES kind from the first frame, the same bytes whichever view's step lays the tag out, by the session's first view, which was the 30 ms soak's rollbacks), found's rows the search's or appended to its +Search after, cancel's tokens dropped on every core (on the tape), a picture over PA_RASTER_MAX dropped and said once, a record of at most PA_RECORD_MAX, a Debug call over 16 ms of the kind's own (its allocations and job copies the core's) said once a site and failing --addon-test (which gains view N on|off and prints the tag the core makes), and the record §17.5's: a Restore, an Addon load and a reload read the pane's file as a Look does, a file not there a placeholder saying <path> is not here, record kept, opened by the next Look or watch of it
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src')
-rw-r--r--src/Addon.zig21
-rw-r--r--src/Kind.zig299
-rw-r--r--src/addon_test.zig42
-rw-r--r--src/dump.zig56
-rw-r--r--src/look.zig7
-rw-r--r--src/replica.zig2
6 files changed, 282 insertions, 145 deletions
diff --git a/src/Addon.zig b/src/Addon.zig
index 5219f2b1..030da7d4 100644
--- a/src/Addon.zig
+++ b/src/Addon.zig
@@ -351,11 +351,10 @@ pub fn loadedOf(ops: *const Kind.Ops, path: []const u8, hash: [32]u8, words: *[6
.ops = @intFromPtr(ops),
.caps = .{
.tick = ops.tick != null, .key = ops.key != null, .mouse = ops.mouse != null, .ctl = ops.ctl != null, .jobs = ops.job_run != null, .load = ops.load != null,
- // 2.1's: a library of 2.0 has no `search` to read, and Esc leaves it.
- .search = h.abi & 0xffff >= 1 and ops.search != null,
- .esc = h.abi & 0xffff >= 1 and ops.key != null,
+ .search = ops.search != null,
.address = ops.address != null,
- .v22 = h.abi & 0xffff >= 2,
+ .view = ops.view != null,
+ .pictures = h.flags & Kind.c.PA_PICTURES != 0,
},
};
}
@@ -560,13 +559,12 @@ pub fn landed(p: *Pardes, op: Op, pane: u8, l: Loaded) void {
/// The panes of kind `name` that waited for it (placeholders), opened.
pub fn reopenWaiting(p: *Pardes, name: []const u8) usize {
- const k = p.kinds.byName(name) orelse return 0;
+ if (p.kinds.byName(name) == null) return 0;
var n: usize = 0;
+ // Each from its file, as a Restore's (a file not here: it waits on).
for (p.panes, 0..) |slot, id| if (slot) |pane| if (pane.addon) |s| if (!s.live and s.is(name)) {
- s.ops = p.kinds.ops[k];
- s.gen = p.kinds.kinds[k].gen;
- s.refused = .{};
- if (Kind.reopen(p, id, s, null)) n += 1;
+ dump.reviveSlot(p, id, s);
+ n += @intFromBool(s.live);
};
return n;
}
@@ -607,7 +605,10 @@ fn swap(p: *Pardes, l: Loaded, why: *Why) bool {
n.where_text.set(Kind.where(s, &place));
if (o.dump != null and l.caps.load) n.record = dump.slotRecord(s) catch return fail(why, "out of memory", .{});
}
- if (!Kind.reopen(p, id, n, null)) return fail(why, "refused: a pane of it would not open again: {s}", .{n.refused.slice()});
+ // From its file as it is, the record its small state.
+ const bytes: ?[]u8 = if (new_ops != null and n.path.len > 0) @import("fs.zig").read(p, n.path) catch null else null;
+ defer if (bytes) |b| p.gpa.free(b);
+ if (!Kind.reopen(p, id, n, bytes)) return fail(why, "refused: a pane of it would not open again: {s}", .{n.refused.slice()});
};
// Every pane opened: the old states go, the new take their slots.
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |s| if (fresh[id]) |n| {
diff --git a/src/Kind.zig b/src/Kind.zig
index 9785a1a3..e3d74b24 100644
--- a/src/Kind.zig
+++ b/src/Kind.zig
@@ -38,9 +38,9 @@ pub const abi: u32 = c.PA_ABI;
comptime {
if (@sizeOf(usize) == 8) for (.{
.{ c.pa_cell, 20 }, .{ c.pa_window, 24 }, .{ c.pa_rect, 16 }, .{ c.pa_cells, 8 },
- .{ c.pa_placement, 80 }, .{ c.pa_paint, 128 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 },
- .{ c.pa_api, 104 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 },
- .{ c.pa_ops, 200 }, .{ c.pa_view, 32 },
+ .{ c.pa_placement, 80 }, .{ c.pa_paint, 32 }, .{ c.pa_key, 8 }, .{ c.pa_mouse, 16 },
+ .{ c.pa_api, 112 }, .{ c.pa_out, 16 }, .{ c.pa_word, 32 }, .{ c.pa_head, 56 },
+ .{ c.pa_ops, 208 }, .{ c.pa_view, 32 }, .{ c.pa_tick, 128 },
}) |r| if (@sizeOf(r[0]) != r[1]) @compileError(std.fmt.comptimePrint("{s} is {d} bytes, the header says {d}", .{ @typeName(r[0]), @sizeOf(r[0]), r[1] }));
}
@@ -57,11 +57,10 @@ pub const Caps = packed struct(u16) {
jobs: bool = false,
load: bool = false,
search: bool = false,
- /// Esc comes to its `key` first (2.1).
- esc: bool = false,
address: bool = false,
- /// 2.2's: a wheel's amount, the pointer in paint, PA_FRAMED.
- v22: bool = false,
+ view: bool = false,
+ /// PA_PICTURES: its tag says how its pictures show, from the first frame.
+ pictures: bool = false,
pad: u6 = 0,
};
@@ -158,40 +157,41 @@ pub const Slot = struct {
/// A placeholder's: the kind's record and its `where`, kept whole.
record: ?[]u8 = null,
where_text: Buf(32) = .{},
- /// What the kind said refusing its open (or a load).
- refused: Buf(96) = .{},
+ /// What the kind said refusing its open (or a load), or `<path> is not here`.
+ refused: Buf(160) = .{},
/// Its words' last values, a `Word arg` line each, which a kind with
/// no `dump` is given again when its pane comes back.
values: Buf(256) = .{},
- /// Its last frame's prefix, and whether it placed a picture; where its
- /// window is in its whole (the rail's thumb), 0 and 0 for none.
+ /// Its prefix as its last tick set it; where its window is in its
+ /// whole (the rail's thumb), 0 and 0 for none, as its last frame says.
prefix: Buf(96) = .{},
- placed: bool = false,
/// Its tag's prefix as the last step read it (the authority's): what a
/// Shadow says in a step, and what a dump keeps of it, so a replica
/// joining lays its tag out as the session did.
told: Buf(400) = .{},
thumb_at: f32 = 0,
thumb_span: f32 = 0,
- /// The pointer its last frame asked for over it (PA_POINTER_*, 2.2),
- /// and whether a frame was painted since its last tick.
+ /// The pointer its last frame asked for over it (PA_POINTER_*), and
+ /// whether a frame was painted since its last tick.
pointer: u8 = 0,
painted: bool = false,
- /// What its view was (`api.view`) when `tick` was last told: a change
- /// ticks it again (2.1).
- view: u64 = 0,
+ /// Each view's facts (a hash of its pa_view) as `view` was last told
+ /// them, 0 for none: a change tells it again.
+ views: [views.max]u64 = @splat(0),
+ /// The jobs whose answers it cancelled (`api.cancel`), dropped as they come.
+ cancelled: [4]u32 = @splat(0),
+ /// Debug: the sites a call over budget (or a raster over the bound) was said at.
+ over: u32 = 0,
/// What it has selected (`api.select`): a yank's, a chord's, a
/// keyboard Look's.
selection: []u8 = &.{},
/// Its tag's default words: Term, its kind's words for its panes,
/// Collapse Del.
tail: Buf(160) = .{},
- /// Its last frame changed its tag: a step is owed to lay the tag out
- /// again (the tag is laid out before the body paints).
- retag: bool = false,
/// A replica's frame of it, as the authority painted it.
shadow: ?*@import("screen_state.zig").Shadow = null,
- /// Debug: the kind's allocations, which paint must leave as they are.
+ /// Debug: the kind's allocations, which paint must leave as they are
+ /// (the list the page allocator's: a region's first is slow in Debug).
used: if (checked) std.ArrayList([]u8) else void = if (checked) .empty else {},
pub const Job = struct { token: u32, in: []u8 };
@@ -218,7 +218,7 @@ pub const Slot = struct {
pub fn free(s: *Slot) void {
for (&s.jobs) |*j| if (j.*) |job| s.gpa.free(job.in);
s.gpa.free(s.selection);
- if (checked) s.used.deinit(s.gpa);
+ if (checked) s.used.deinit(std.heap.page_allocator);
if (s.shadow) |sh| sh.deinit(s.gpa);
s.arena.deinit();
s.gpa.free(s.path);
@@ -278,7 +278,8 @@ pub fn reopen(p: ?*Pardes, id: usize, s: *Slot, bytes: ?[]const u8) bool {
s.tail.len = @intCast(w.buffered().len);
};
s.opened = if (bytes) |b| std.hash.Wyhash.hash(0, b) else 0;
- if (s.ops) |ops| {
+ // Its file not read (not here): it waits for it, a placeholder.
+ if (s.ops != null and bytes == null and s.path.len > 0) _ = cl.refused.print("{s} is not here", .{s.path}) else if (s.ops) |ops| {
const path_z = s.arena.allocator().dupeSentinel(u8, s.path, 0) catch "";
cl.opening = true;
if (ops.open) |f| s.st = f(if (s.path.len > 0) path_z.ptr else null, if (bytes) |b| b.ptr else null, if (bytes) |b| b.len else 0);
@@ -320,7 +321,12 @@ fn poke(p: *const Pardes, s: *Slot) void {
pub fn fileChanged(p: *Pardes, id: usize, _: []const u8) bool {
const pane = p.panes[id] orelse return false;
const s = pane.addon orelse return false;
- if (!s.live or s.path.len == 0) return false;
+ if (s.path.len == 0) return false;
+ // A placeholder waiting for its file: here now, it opens.
+ if (!s.live) {
+ @import("dump.zig").reviveSlot(p, id, s);
+ return s.live;
+ }
// Both cores read it and reopen it alike (the read and its open's
// outcome on the tape); the kind's record only the authority has.
const bytes: ?[]u8 = @import("fs.zig").read(p, s.path) catch null;
@@ -375,7 +381,8 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
} else if (slot.ops == null) {
var line: [160]u8 = undefined;
const why = if (slot.refused.len > 0) slot.refused.slice() else "Addon load <path>";
- const text = std.fmt.bufPrint(&line, "addon {s} {d} is not loaded: {s}", .{ slot.nameOf(), slot.version, why }) catch &line;
+ // Its kind here, it waits for its file (`<path> is not here`).
+ const text = if (p.kinds.byName(slot.nameOf()) != null) why else std.fmt.bufPrint(&line, "addon {s} {d} is not loaded: {s}", .{ slot.nameOf(), slot.version, why }) catch &line;
_ = s.print(x, y, cols, text, .{ .fg = fg, .bg = bg });
return;
} else frame.cells = (paint(p, slot, id, arena, cols, rows, &frame) orelse return);
@@ -387,6 +394,11 @@ pub fn draw(p: *Pardes, s: *surface.Surface, arena: std.mem.Allocator, pane: *Pa
};
for (frame.places[0..frame.n]) |pl| {
if (pl.rgba == null or pl.w == 0 or pl.h == 0) continue;
+ if (@as(u64, pl.w) * pl.h * 4 > c.PA_RASTER_MAX) {
+ if (slot.over & 1 << 31 == 0) std.log.warn("{s}: a picture of {d} MB, over {d} MiB", .{ slot.nameOf(), @as(u64, pl.w) * pl.h * 4 >> 20, c.PA_RASTER_MAX >> 20 });
+ slot.over |= 1 << 31;
+ continue;
+ }
const dx = @min(pl.dst.x, cols);
const dy = @min(pl.dst.y, rows);
_ = p.appendPlacement(.{
@@ -412,16 +424,16 @@ pub const Frame = struct {
buf: [64]c.pa_placement = undefined,
};
-/// The one paint of a frame: its cells (in `arena`) and placements into
-/// `frame`, its prefix and whether it placed a picture into the slot.
-/// Debug checks it changed none of the kind's memory.
+/// The one paint of a frame in the live view: its cells (in `arena`) and
+/// placements into `frame`, its thumb and pointer into the slot. Debug
+/// checks it changed none of the kind's memory.
pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator, cols: u16, rows: u16, frame: *Frame) ?[]c.pa_cell {
const ops = slot.ops orelse return null;
const cells = arena.alloc(c.pa_cell, @as(usize, cols) * rows) catch return null;
@memset(std.mem.sliceAsBytes(cells), 0);
var out: c.pa_paint = std.mem.zeroInit(c.pa_paint, .{ .placements = &frame.buf, .cap = frame.buf.len });
const px = p.view().cell_pixels;
- const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)) });
+ const win = std.mem.zeroInit(c.pa_window, .{ .cells = cells.ptr, .stride = cols, .rows = rows, .cols = cols, .cell_w = px.w, .cell_h = px.h, .focused = @intFromBool(focusedAnywhere(p, id)), .view = p.live + 1, .glyphs = @intFromBool(!p.view().frontend.native_images) });
var cl: Call = .{ .p = null, .id = 0, .slot = slot, .quiet = true };
const prev = cl.begin("paint");
const before = if (checked) usedHash(slot) else {};
@@ -430,16 +442,9 @@ pub fn paint(p: *const Pardes, slot: *Slot, id: usize, arena: std.mem.Allocator,
_ = cl.end(prev);
frame.places = &frame.buf;
frame.n = @min(out.n, frame.buf.len);
- const own = out.prefix[0..@min(out.prefix_len, out.prefix.len)];
- const placed = for (frame.buf[0..frame.n]) |pl| {
- if (pl.rgba != null and pl.w > 0 and pl.h > 0) break true;
- } else false;
- if (placed != slot.placed or !std.mem.eql(u8, own, slot.prefix.slice())) slot.retag = true;
- slot.prefix.set(own);
- slot.placed = placed;
slot.thumb_at = std.math.clamp(out.at, 0, 1);
slot.thumb_span = std.math.clamp(out.span, 0, 1);
- slot.pointer = if (caps(p, slot).v22) @intCast(@min(out.pointer, 255)) else 0;
+ slot.pointer = @intCast(@min(out.pointer, 255));
slot.painted = true;
return cells;
}
@@ -471,9 +476,9 @@ fn colorOf(v: u32, default: surface.Color) surface.Color {
};
}
-/// The start of its tag: its kind's prefix from its last frame (else the
-/// kind's name), the core's art words when that frame placed a picture,
-/// and its path. The authority's: a step reads it off the tape on a replica.
+/// The start of its tag: its kind's prefix from its last tick (else the
+/// kind's name), the core's art words for a kind of PA_PICTURES, and its
+/// path. The authority's: a step reads it off the tape on a replica.
pub fn prefix(p: *const Pardes, arena: std.mem.Allocator, pane: *const Pane) ![]const u8 {
const slot = pane.addon.?;
var buf: [400]u8 = undefined;
@@ -491,11 +496,13 @@ fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
// step's, a notch behind its frames until the next step.
if (slot.ops == null and slot.told.len > 0) return slot.told.slice();
const own = if (slot.shadow) |sh| sh.prefix.slice() else slot.prefix.slice();
- const placed = if (slot.shadow) |sh| sh.placed else slot.placed;
var w: std.Io.Writer = .fixed(buf);
w.writeAll(if (own.len > 0) own else slot.nameOf()) catch {};
- if (placed) w.print(" petscii:{s} palette:{t} ascii:{s}", .{
- if (slot.art.glyph or !p.view().frontend.native_images) "on" else "off",
+ // The same bytes whichever view's step lays the tag out (17.2): glyph
+ // art when Petscii says or the session's first view shows no pictures.
+ const first = &p.views[@min(@ctz(p.views_open), views.max - 1)].?;
+ if (caps(p, slot).pictures) w.print(" petscii:{s} palette:{t} ascii:{s}", .{
+ if (slot.art.glyph or !first.frontend.native_images) "on" else "off",
slot.art.palette,
if (slot.art.ascii) "on" else "off",
}) catch {};
@@ -508,9 +515,8 @@ fn prefixOf(p: *const Pardes, slot: *const Slot, buf: *[400]u8) []const u8 {
pub fn key(p: *Pardes, id: usize, k: pardes.Key) bool {
const slot = (p.panes[id] orelse return false).addon orelse return false;
if (!caps(p, slot).key) return false;
- if (k.cp == pardes.Key.escape and !caps(p, slot).esc) return false;
if (authorityOnly("a key into a kind's pane")) return true;
- const pk: c.pa_key = .{ .cp = k.cp, .ctrl = @intFromBool(k.ctrl), .alt = @intFromBool(k.alt), .shift = @intFromBool(k.shift), .pad = 0 };
+ const pk: c.pa_key = .{ .cp = k.cp, .ctrl = @intFromBool(k.ctrl), .alt = @intFromBool(k.alt), .shift = @intFromBool(k.shift), .view = p.live + 1 };
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("key");
if (slot.ops) |o| cl.ret = o.key.?(slot.st, &pk);
@@ -527,15 +533,16 @@ pub fn takesKeys(p: *const Pardes, s: *const Slot) bool {
return caps(p, s).key;
}
-/// The kind's own rows for the core's `/` (2.1's `search`), in `buf`; null
-/// for a kind with none.
-pub fn search(p: *Pardes, id: usize, pat: []const u8, buf: []u8) ?[]const u8 {
+/// The kind's own rows for the core's `/`, those it found in the call
+/// (`api.found`; later ones go to its +Search as they come); null for a
+/// kind with no search.
+pub fn search(p: *Pardes, id: usize, pat: []const u8) ?[]const u8 {
const slot = (p.panes[id] orelse return null).addon orelse return null;
if (!caps(p, slot).search) return null;
if (authorityOnly("a kind's search")) return null;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("search");
- if (slot.ops) |o| cl.rows = buf[0..@min(buf.len, o.search.?(slot.st, pat.ptr, @intCast(pat.len), buf.ptr, @intCast(buf.len)))];
+ if (slot.ops) |o| o.search.?(slot.st, pat.ptr, @intCast(pat.len));
// The rows are the authority's, on the tape: a replica's are those.
const o = cl.end(prev);
poke(p, slot);
@@ -586,7 +593,7 @@ pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool {
.ctrl = @intFromBool(m.ctrl),
.shift = @intFromBool(m.shift),
.alt = @intFromBool(m.alt),
- .pad = 0,
+ .view = p.live + 1,
.col = col,
.row = row,
.amount = m.amount,
@@ -597,24 +604,31 @@ pub fn mouse(p: *Pardes, id: usize, m: pardes.Mouse, col: u16, row: u16) bool {
return taken(p, slot, cl.end(prev));
}
-/// The end of a step: each pane of a kind whose focus changed, or whose
-/// time has come, ticks (16.2).
+/// The end of a step: each pane of a kind told of each view whose facts
+/// changed (17.1), and each whose focus changed, or whose time has come,
+/// ticked (16.2).
pub fn step(p: *Pardes) void {
const now = p.clock.stepped_ns;
- // A tick is the authority's kind's alone: a speculation whose step
- // would tick one waits for the authority's unit (guessed untouched, the
- // unit rolled it back, a visible rollback an input).
+ // A kind's call is the authority's kind's alone: a speculation whose
+ // step would make one waits for the authority's unit (guessed
+ // untouched, the unit rolled it back, a visible rollback an input).
if (tape.speculating()) return if (wouldTick(p, now)) tape.poison("a kind's tick");
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
- // Its tag laid out again by this step's sync, and drawn.
- if (slot.retag) p.needs_frame = true;
- slot.retag = false;
+ if (caps(p, slot).view) for (0..views.max) |k| {
+ var v = viewOf(p, @intCast(k), id);
+ if (seen(&v) == slot.views[k]) continue;
+ slot.views[k] = seen(&v);
+ var cl: Call = .{ .p = p, .id = id, .slot = slot };
+ const prev = cl.begin("view");
+ if (slot.ops) |o| o.view.?(slot.st, &v);
+ _ = cl.end(prev);
+ poke(p, slot);
+ p.needs_frame = true;
+ };
if (!caps(p, slot).tick) continue;
const focused = focusedAnywhere(p, id);
- const seen = std.hash.Wyhash.hash(0, std.mem.asBytes(&viewOf(p, id)));
- if (focused != slot.focused or seen != slot.view) {
+ if (focused != slot.focused) {
slot.focused = focused;
- slot.view = seen;
slot.next_tick = 1;
}
// 1 is the next step, whatever the clock says (a session whose
@@ -622,25 +636,36 @@ pub fn step(p: *Pardes) void {
if (slot.next_tick == 0 or (slot.next_tick > 1 and now < slot.next_tick)) continue;
var cl: Call = .{ .p = p, .id = id, .slot = slot };
const prev = cl.begin("tick");
- // A frame drawn since its last tick (2.2): a fling's frames are
- // counted by them.
- const flags = (if (focused) c.PA_FOCUSED else 0) | (if (slot.painted and caps(p, slot).v22) c.PA_FRAMED else 0);
+ // A frame drawn since its last tick: a fling's frames are counted by them.
+ const flags = (if (focused) c.PA_FOCUSED else 0) | (if (slot.painted) c.PA_FRAMED else 0);
slot.painted = false;
// The clock's now for a tick after an event (a key, a focus): the
// stepped frame lags it while the next wake is still to come.
- const at = if (slot.next_tick == 1) @max(now, p.clock.now_ns) else now;
- if (slot.ops) |o| cl.ret = @bitCast(o.tick.?(slot.st, at, flags));
+ var t = std.mem.zeroInit(c.pa_tick, .{ .now = if (slot.next_tick == 1) @max(now, p.clock.now_ns) else now, .flags = flags });
+ if (slot.ops) |o| {
+ o.tick.?(slot.st, &t);
+ cl.ret = @bitCast(t.next);
+ slot.prefix.set(t.prefix[0..@min(t.prefix_len, t.prefix.len)]);
+ }
slot.next_tick = @bitCast(cl.end(prev).ret);
p.needs_frame = true;
repaint(p, slot, id);
};
}
-/// Its prefix and whether it places a picture as its tick left it, for
-/// this step's tag: a frame's paint set them, a step behind the tick (a
-/// PDF to its text layer, or back), and a replica guessing its next input
-/// took the tag this step laid out. The live view's frame of it, painted
-/// and let go; not a frame drawn (`painted` kept).
+/// Whether some view's facts are not what its kind was told.
+pub fn viewOwed(p: *const Pardes, slot: *const Slot, id: usize) bool {
+ if (caps(p, slot).view) for (0..views.max) |k| if (seen(&viewOf(p, @intCast(k), id)) != slot.views[k]) return true;
+ return false;
+}
+
+/// A view's facts as `view` is told them: 0 for one that shows it not.
+fn seen(v: *const c.pa_view) u64 {
+ return if (v.cols == 0) 0 else std.hash.Wyhash.hash(0, std.mem.asBytes(v));
+}
+
+/// Its thumb and pointer as its tick left them, the live view's frame of
+/// it painted and let go; not a frame drawn (`painted` kept).
fn repaint(p: *Pardes, slot: *Slot, id: usize) void {
const pane = p.panes[id] orelse return;
if (slot.ops == null or pane.collapsed) return;
@@ -656,23 +681,30 @@ fn repaint(p: *Pardes, slot: *Slot, id: usize) void {
_ = paint(p, slot, id, arena.allocator(), cols, rows, &frame);
}
-/// Whether `step` would tick some pane of a kind now (its rule, read only).
+/// Whether `step` would call some pane's kind now (its rule, read only).
fn wouldTick(p: *const Pardes, now: u64) bool {
for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
+ if (viewOwed(p, slot, id)) return true;
if (!caps(p, slot).tick) continue;
- if (focusedAnywhere(p, id) != slot.focused or std.hash.Wyhash.hash(0, std.mem.asBytes(&viewOf(p, id))) != slot.view) return true;
+ if (focusedAnywhere(p, id) != slot.focused) return true;
if (slot.next_tick == 1 or (slot.next_tick > 1 and now >= slot.next_tick)) return true;
};
return false;
}
-/// Pane `id` as its next paint sees it: its body below its notices, as
-/// draw.zig paints it, a cell's pixels, the theme's colours and the
-/// raster this frontend wants a picture at.
-pub fn viewOf(p: *const Pardes, id: usize) c.pa_view {
- const v = p.view();
- const pane = p.panes[id] orelse return std.mem.zeroes(c.pa_view);
+/// Pane `id` as view `k` shows it (its id k + 1): its body below its
+/// notices, as draw.zig paints it, a cell's pixels, the theme's colours and
+/// the raster that view's frontend wants a picture at; no cells when the
+/// view is closed or shows it not.
+pub fn viewOf(p: *const Pardes, k: u8, id: usize) c.pa_view {
+ var out = std.mem.zeroes(c.pa_view);
+ out.id = k + 1;
+ const v = if (views.isOpen(p, k)) &(p.views[k] orelse return out) else return out;
+ const pane = p.panes[id] orelse return out;
const r = v.rects[id];
+ // The live view's share of the pane is in its own fields, another's parked.
+ const collapsed, const tag_rows, const notices = if (k == p.live) .{ pane.collapsed, pane.tag_rows, pane.notices.span() } else .{ pane.pv[k].collapsed, pane.pv[k].tag_rows, pane.pv[k].notices.span() };
+ if (collapsed) return out;
const th = p.theme();
const rgb = struct {
fn f(x: [3]u8) u32 {
@@ -681,8 +713,8 @@ pub fn viewOf(p: *const Pardes, id: usize) c.pa_view {
}.f;
const policy = pardes.rasterPolicy(v.frontend.windowed);
return .{
- .cols = if (pane.collapsed) 0 else r.w -| pardes.config.GUTTER,
- .rows = if (pane.collapsed) 0 else (r.h -| pane.tag_rows) -| pane.notices.span(),
+ .cols = r.w -| pardes.config.GUTTER,
+ .rows = (r.h -| tag_rows) -| notices,
.cell_w = v.cell_pixels.w,
.cell_h = v.cell_pixels.h,
.fg = rgb(th.fg orelse th.tag_fg),
@@ -693,7 +725,8 @@ pub fn viewOf(p: *const Pardes, id: usize) c.pa_view {
.max_px = policy.max_dimension,
.fill = @intFromBool(policy.match_viewport),
.glyphs = @intFromBool(!v.frontend.native_images),
- .pad = @splat(0),
+ .id = k + 1,
+ .pad = 0,
};
}
@@ -703,12 +736,12 @@ fn focusedAnywhere(p: *const Pardes, id: usize) bool {
return false;
}
-/// When the kinds next want a step: the soonest deadline (now, for a
-/// tag to lay out again), or null.
+/// When the kinds next want a step: the soonest deadline (now, for a view
+/// whose facts a step's layout changed after the kind was told them), or null.
pub fn wake(p: *const Pardes) ?u64 {
var soonest: ?u64 = null;
- for (p.panes) |pslot| if (pslot) |pane| if (pane.addon) |slot| {
- const due = if (slot.retag) @max(1, p.clock.stepped_ns) else slot.next_tick;
+ for (p.panes, 0..) |pslot, id| if (pslot) |pane| if (pane.addon) |slot| {
+ const due = if (viewOwed(p, slot, id)) @max(1, p.clock.stepped_ns) else slot.next_tick;
if (due != 0) soonest = @min(soonest orelse due, due);
};
return soonest;
@@ -720,6 +753,11 @@ pub fn jobDone(p: *Pardes, pane_id: u8, serial: u32, token: u32, gen: u32, bytes
const pane = p.panes[pane_id] orelse return;
const slot = pane.addon orelse return;
if (pane.serial != serial or slot.gen != gen or !caps(p, slot).jobs) return;
+ // Cancelled: dropped, on every core (the cancel was on the tape).
+ if (std.mem.indexOfScalar(u32, &slot.cancelled, token)) |i| {
+ slot.cancelled[i] = 0;
+ return;
+ }
var cl: Call = .{ .p = p, .id = pane_id, .slot = slot };
const prev = cl.begin("job_done");
if (slot.ops) |o| o.job_done.?(slot.st, token, bytes.ptr, @intCast(bytes.len));
@@ -829,8 +867,10 @@ pub const Outcome = struct {
selected: ?[]const u8 = null,
rows: []const u8 = "",
/// The jobs it asked for (their tokens, 0 past the last): every core
- /// emits them, so a replica's effects are the authority's.
+ /// emits them, so a replica's effects are the authority's; and those
+ /// it cancelled, every core drops.
jobs: [8]u32 = @splat(0),
+ cancels: [4]u32 = @splat(0),
};
/// The call under way: what `api` acts on, and what it gathers.
@@ -856,9 +896,13 @@ const Call = struct {
selected: ?[]const u8 = null,
rows: []const u8 = "",
jobs: [8]u32 = @splat(0),
+ cancels: [4]u32 = @splat(0),
+ /// Debug: when it began, for the budget.
+ began: u64 = 0,
fn begin(cl: *Call, comptime name: []const u8) ?*Call {
cl.name = name;
+ if (checked) cl.began = @import("FrameStats.zig").nowNs();
const prev = current;
current = cl;
return prev;
@@ -867,9 +911,18 @@ const Call = struct {
/// The call's outcome, as the authority's took it, done.
fn end(cl: *Call, prev: ?*Call) Outcome {
current = prev;
+ if (checked) overBudget(cl);
if (cl.quiet) return .{};
- const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .jobs = cl.jobs }});
+ const o = tape.value(.addon, same, .{Outcome{ .ret = cl.ret, .text = cl.refused.slice(), .said = cl.said.slice(), .err = cl.err, .look = cl.look.slice(), .pane_name = cl.pane_name.slice(), .pane_text = cl.pane_text, .exec = cl.exec.slice(), .selected = cl.selected, .rows = cl.rows, .jobs = cl.jobs, .cancels = cl.cancels }});
if (cl.p) |p| if (p.panes[cl.id]) |pane| for (o.jobs) |token| if (token != 0) p.emit(.{ .job = .{ .pane = @intCast(cl.id), .serial = pane.serial, .token = token } });
+ for (o.cancels) |token| if (token != 0) {
+ for (&cl.slot.jobs) |*j| if (j.*) |job| if (job.token == token) {
+ cl.slot.gpa.free(job.in);
+ j.* = null;
+ };
+ std.mem.copyForwards(u32, cl.slot.cancelled[1..], cl.slot.cancelled[0..3]);
+ cl.slot.cancelled[0] = token;
+ };
if (o.selected) |sel| {
cl.slot.gpa.free(cl.slot.selection);
cl.slot.selection = cl.slot.gpa.dupe(u8, sel) catch &.{};
@@ -883,11 +936,44 @@ const Call = struct {
if (o.pane_name.len > 0) textPane(p, cl.id, cl.slot, o.pane_name, o.pane_text);
if (o.look.len > 0) @import("look.zig").lookAt(p, cl.id, o.look);
if (o.exec.len > 0) @import("mouse.zig").dispatchPointerBuiltin(p, cl.id, pardes.config.exec_cmd, o.exec, null);
+ // Rows found after its search (a job's): onto its +Search.
+ if (o.rows.len > 0 and !std.mem.eql(u8, cl.name, "search")) moreFound(p, cl.id, o.rows);
return o;
}
};
var current: ?*Call = null;
+/// A call's budget, in Debug: a frame (17.4; 2 ms in ReleaseFast, which
+/// Debug's kinds run three to four times slower than).
+const budget_ns = 16 * std.time.ns_per_ms;
+const sites = [_][]const u8{ "open", "close", "tick", "paint", "view", "key", "mouse", "body", "address", "where", "ctl", "ctl_read", "job_done", "dump", "search" };
+/// The first call over budget, `pdf: search took 118 ms, over 16 ms`:
+/// what `--addon-test` fails on.
+pub var breach: Buf(96) = .{};
+
+fn overBudget(cl: *Call) void {
+ const took = @import("FrameStats.zig").nowNs() -| cl.began;
+ const site = for (sites, 0..) |n, i| {
+ if (std.mem.eql(u8, n, cl.name)) break i;
+ } else return;
+ if (took <= budget_ns or cl.slot.over & @as(u32, 1) << @intCast(site) != 0) return;
+ cl.slot.over |= @as(u32, 1) << @intCast(site);
+ var line: Buf(96) = .{};
+ std.log.warn("{s}", .{line.print("{s}: {s} took {d} ms, over {d} ms", .{ cl.slot.nameOf(), cl.name, took / std.time.ns_per_ms, budget_ns / std.time.ns_per_ms })});
+ if (breach.len == 0) breach = line;
+}
+
+/// Rows a kind found after its search answered, appended to the pane's
+/// +Search (the list its last `/` made), as a file search's stream in.
+fn moreFound(p: *Pardes, id: usize, rows: []const u8) void {
+ const pane = p.panes[id] orelse return;
+ const rp = p.panes[pane.search_pane orelse return] orelse return;
+ const rf = if (rp.file) |*f| f else return;
+ const o = if (rf.output) |*x| x else return;
+ const content = std.mem.concat(p.gpa, u8, &.{ rf.content, rows }) catch return;
+ pardes.panes.Output.fillResults(p, id, std.fs.path.dirname(rf.path) orelse p.sessionDir(), .search, o.arg(), content, null) catch |err| p.reportError(id, "found", err);
+}
+
fn same(o: Outcome) Outcome {
return o;
}
@@ -906,9 +992,15 @@ pub const api: c.pa_api = .{
.alloc = struct {
fn f(n: usize) callconv(.c) ?*anyopaque {
const cl = current orelse return null;
+ // Its time the core's, not the kind's budget's (a region's
+ // first allocation is slow in Debug), as a job's copy is.
+ const t0 = if (checked) @import("FrameStats.zig").nowNs();
+ defer if (checked) {
+ cl.began += @import("FrameStats.zig").nowNs() -| t0;
+ };
const mem = cl.slot.arena.allocator().alignedAlloc(u8, .@"16", @max(n, 1)) catch return null;
@memset(mem, 0);
- if (checked) cl.slot.used.append(cl.slot.gpa, mem) catch {};
+ if (checked) cl.slot.used.append(std.heap.page_allocator, mem) catch {};
return mem.ptr;
}
}.f,
@@ -928,6 +1020,10 @@ pub const api: c.pa_api = .{
fn f(in: ?*const anyopaque, n: u32) callconv(.c) u32 {
const cl = current orelse return 0;
if (cl.p == null or cl.quiet) return 0;
+ const t0 = if (checked) @import("FrameStats.zig").nowNs();
+ defer if (checked) {
+ cl.began += @import("FrameStats.zig").nowNs() -| t0;
+ };
const s = cl.slot;
const free = for (&s.jobs) |*j| {
if (j.* == null) break j;
@@ -987,12 +1083,6 @@ pub const api: c.pa_api = .{
return kind_heap.realloc(ptr, n);
}
}.f,
- .view = struct {
- fn f(out: [*c]c.pa_view) callconv(.c) void {
- const cl = current orelse return;
- out.* = if (cl.p) |p| viewOf(p, cl.id) else std.mem.zeroes(c.pa_view);
- }
- }.f,
.exec = struct {
fn f(text: [*c]const u8, n: u32) callconv(.c) void {
const cl = current orelse return;
@@ -1007,6 +1097,23 @@ pub const api: c.pa_api = .{
cl.selected = p.scratch.allocator().dupe(u8, if (text == null) "" else text[0..n]) catch return;
}
}.f,
+ .cancel = struct {
+ fn f(token: u32) callconv(.c) void {
+ const cl = current orelse return;
+ if (cl.quiet or token == 0) return;
+ const free = std.mem.indexOfScalar(u32, &cl.cancels, 0) orelse return;
+ cl.cancels[free] = token;
+ }
+ }.f,
+ .found = struct {
+ /// Gathered in the call: the search's answer, or onto its +Search after.
+ fn f(rows: [*c]const u8, n: u32) callconv(.c) void {
+ const cl = current orelse return;
+ const p = cl.p orelse return;
+ if (cl.quiet or rows == null) return;
+ cl.rows = std.mem.concat(p.scratch.allocator(), u8, &.{ cl.rows, rows[0..n] }) catch return;
+ }
+ }.f,
};
/// What `api.heap` hands out: memory that outlives a call, from any
@@ -1035,7 +1142,7 @@ pub const test_kind = struct {
out.*.placements[0] = std.mem.zeroInit(c.pa_placement, .{ .rgba = &pixel, .w = 1, .h = 1, .src = .{ .x = 0, .y = 0, .w = 1, .h = 1 }, .dst = .{ .x = 0, .y = 0, .w = win.*.cols, .h = win.*.rows } });
out.*.n = 1;
}
- const ops = std.mem.zeroInit(Ops, .{ .head = std.mem.zeroInit(c.pa_head, .{ .size = @sizeOf(c.pa_head), .abi = abi, .name = "test".* ++ @as([12]u8, @splat(0)), .version = 1 }), .paint = picture });
+ const ops = std.mem.zeroInit(Ops, .{ .head = std.mem.zeroInit(c.pa_head, .{ .size = @sizeOf(c.pa_head), .abi = abi, .name = "test".* ++ @as([12]u8, @splat(0)), .version = 1, .flags = c.PA_PICTURES }), .paint = picture });
/// Its index in `p`'s kinds, taken in at the first ask.
pub fn of(p: *Pardes) u8 {
diff --git a/src/addon_test.zig b/src/addon_test.zig
index 7b151ee6..7c9950d7 100644
--- a/src/addon_test.zig
+++ b/src/addon_test.zig
@@ -2,9 +2,11 @@
//! The addon is loaded into a session of its own (80x24, no terminal, no
//! disk, its jobs run at once, its clock virtual, starting at 1 s and moved
//! by `tick` and `settle` alone), a pane of it opened, and the script's
-//! lines run in turn, each printed with the pane's tag (the kind's own
-//! prefix), cells and placements after it; a script compares the output
-//! with what it wants as a snapshot script does (`diff`).
+//! lines run in turn, each printed with the start of the pane's tag (the
+//! kind's prefix, the core's art words, the path), cells and placements
+//! after it; a script compares the output with what it wants as a snapshot
+//! script does (`diff`). A call into the kind over its budget (16 ms in a
+//! Debug pardes) is said, and fails the script.
//!
//! open [path] a pane of the kind (the first step opens one bare)
//! key hjkl<up> keys, a character or <up> <down> <left> <right>
@@ -16,9 +18,11 @@
//! (`window CxR` says what the kind paints)
//! seed 7 what every pane's seed is made from (before open)
//! click 3 1 a left click at the body's column 3, row 1
-//! focus, blur the window takes the keyboard, or loses it
-//! graphics on|off a frontend that shows pictures, or one without
-//! them (glyph art, the start's)
+//! focus, blur the view's window takes the keyboard, or loses it
+//! graphics on|off the view's frontend shows pictures, or not
+//! (glyph art, the start's)
+//! view 2 on|off into view 2 (1 is the start's; one opened as the
+//! first is), its frontend with pictures or not
//! dump the pane's record (its length) loaded into a
//! fresh pane, which the script goes on with
//! body, ctl the pane's body, or its ctl file's read
@@ -64,6 +68,7 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
var now: u64 = std.time.ns_per_s;
p.advance(now);
var id: ?usize = null;
+ var said = false;
var lines = std.mem.splitScalar(u8, script, '\n');
while (lines.next()) |raw| {
const line = std.mem.trim(u8, raw, " \t\r");
@@ -110,9 +115,15 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
p.update(.{ .mouse = .{ .button = .left, .kind = mk, .col = body.x + col, .row = body.y + row } });
} else if (is(verb, "focus") or is(verb, "blur")) {
p.update(.{ .focus = is(verb, "focus") });
- } else if (is(verb, "graphics")) {
- // A frontend that shows pictures (`graphics on`), or glyph art.
- p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.eql(u8, arg, "on") } });
+ } else if (is(verb, "graphics") or is(verb, "view")) {
+ // Into view N (another client's), then its frontend: with
+ // pictures (`on`), or glyph art.
+ if (is(verb, "view")) {
+ const n = std.fmt.parseInt(u8, arg[0..@min(1, arg.len)], 10) catch 1;
+ while (n > 1 and !pardes.views.isOpen(p, n - 1)) _ = p.openView() orelse break;
+ if (pardes.views.isOpen(p, n -| 1)) p.toView(n -| 1);
+ }
+ p.update(.{ .frontend = .{ .windowed = false, .native_images = std.mem.endsWith(u8, arg, "on") } });
} else if (is(verb, "dump")) {
id = try reloaded(p, gpa, at, out);
} else if (is(verb, "body") or is(verb, "ctl")) {
@@ -127,8 +138,18 @@ fn run(io: std.Io, gpa: std.mem.Allocator, lib: []const u8, script_path: ?[]cons
if (!p.executeBuiltinLine(at, line)) try out.print("not a word here: {s}\n", .{verb});
}
drain(p);
+ // A tick owed (a pane opened or loaded here, outside a step) and a
+ // view whose facts a frame's layout changed (its tag wrapped), as
+ // a host steps for them.
+ if (p.panes[id.?]) |pane| if (window(p, id.?) != null and (pane.addon.?.next_tick == 1 or Kind.viewOwed(p, pane.addon.?, id.?))) {
+ p.update(.tick);
+ drain(p);
+ };
try show(p, gpa, id.?, out, opened or is(verb, "size"));
+ if (Kind.breach.len > 0 and !said) try out.print("addon-test: {s}\n", .{Kind.breach.slice()});
+ said = Kind.breach.len > 0;
}
+ if (said) return error.OverBudget;
}
fn open(p: *Pardes, k: u8, path: ?[]const u8) !usize {
@@ -212,9 +233,8 @@ fn show(p: *Pardes, gpa: std.mem.Allocator, id: usize, out: *std.Io.Writer, size
defer arena.deinit();
const s = try p.render(arena.allocator());
const pane = p.panes[id] orelse return out.writeAll("(the pane is gone)\n");
- const slot = pane.addon.?;
if (size) if (window(p, id)) |w| try out.print("window {d}x{d}\n", .{ w.w, w.h });
- try out.print("tag {s}\n", .{if (slot.prefix.len > 0) slot.prefix.slice() else slot.nameOf()});
+ try out.print("tag {s}\n", .{try Kind.prefix(p, arena.allocator(), pane)});
const r = (s.region(.body, id) orelse return).rect;
for (r.y..r.y + r.h) |y| {
var row: std.ArrayList(u8) = .empty;
diff --git a/src/dump.zig b/src/dump.zig
index 08736c84..52002697 100644
--- a/src/dump.zig
+++ b/src/dump.zig
@@ -925,9 +925,11 @@ const SlotRecord = struct {
/// What decides its next calls (Kind.step): a replica joining keeps
/// them, its Shadow calling where the authority's kind does.
next_tick: u64 = 0,
- view: u64 = 0,
+ views: [views.max]u64 = @splat(0),
focused: bool = false,
told: []const u8 = "",
+ /// A placeholder's why (its file not here).
+ refused: []const u8 = "",
/// What a step reads of it that its kind's open made (Kind.reopen) or
/// a call set: its tag's default words and what it has selected. A
/// replica's load opens no kind; without them its tag wrapped another
@@ -938,7 +940,7 @@ const SlotRecord = struct {
pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer) !void {
var place: [32]u8 = undefined;
- var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .view = s.view, .focused = s.focused, .told = s.told.slice(), .tail = s.tail.slice(), .selection = s.selection };
+ var r: SlotRecord = .{ .name = s.nameOf(), .version = s.version, .path = s.path, .art = s.art, .record = s.record, .where = s.where_text.slice(), .values = s.values.slice(), .live = s.live, .next_tick = s.next_tick, .views = s.views, .focused = s.focused, .told = s.told.slice(), .refused = s.refused.slice(), .tail = s.tail.slice(), .selection = s.selection };
var owned: ?[]u8 = null;
defer if (owned) |o| s.gpa.free(o);
if (s.ops != null) {
@@ -951,22 +953,17 @@ pub fn slotWrite(s: *const Kind.Slot, gpa: std.mem.Allocator, w: *std.Io.Writer)
try w.writeAll(bytes);
}
-/// The kind's record of a slot's state (`s.gpa`'s), or null for none: a
-/// dump of at most 1 MiB, then as many bytes as it asked for.
+/// The kind's record of a slot's state (`s.gpa`'s), or null for none: at
+/// most PA_RECORD_MAX bytes.
pub fn slotRecord(s: *Kind.Slot) !?[]u8 {
const f = (s.ops orelse return null).dump orelse return null;
- var cap: usize = 1 << 20;
- while (true) {
- const buf = try s.gpa.alloc(u8, cap);
- const n = Kind.dumpCall(s, f, buf);
- if (n == 0) {
- s.gpa.free(buf);
- return null;
- }
- if (n <= cap) return s.gpa.realloc(buf, n) catch buf[0..n];
+ const buf = try s.gpa.alloc(u8, Kind.c.PA_RECORD_MAX);
+ const n = Kind.dumpCall(s, f, buf);
+ if (n == 0 or n > buf.len) {
s.gpa.free(buf);
- cap = n;
+ return null;
}
+ return s.gpa.realloc(buf, n) catch buf[0..n];
}
/// The pane back from its record, a placeholder holding it until its
@@ -975,12 +972,13 @@ pub fn slotRead(out: *Kind.Slot, gpa: std.mem.Allocator, bytes: []const u8) !voi
var arena: std.heap.ArenaAllocator = .init(gpa);
defer arena.deinit();
const r = try walk.load(SlotRecord, arena.allocator(), bytes, null);
- out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .view = r.view, .focused = r.focused };
+ out.* = .{ .gpa = gpa, .arena = .init(gpa), .version = r.version, .art = r.art, .live = r.live, .next_tick = r.next_tick, .views = r.views, .focused = r.focused };
errdefer out.free();
@memcpy(out.name[0..@min(15, r.name.len)], r.name[0..@min(15, r.name.len)]);
out.path = try gpa.dupe(u8, r.path);
out.where_text.set(r.where);
out.told.set(r.told);
+ out.refused.set(r.refused);
out.tail.set(r.tail);
out.values.set(r.values);
out.selection = try gpa.dupe(u8, r.selection);
@@ -992,9 +990,12 @@ pub fn slotFree(s: *Kind.Slot, gpa: std.mem.Allocator) void {
s.free();
}
-/// A loaded pane of a kind opened by its kind, if this core has it, else
-/// a placeholder saying what it waits for. One with no record reopens from
-/// its file, its place and its words.
+/// A loaded pane of a kind opened by its kind from its file as a Look
+/// reads it, then given its record, if this core has the kind; else, or
+/// refused (its file not here, its record not taken), a placeholder saying
+/// what it waits for, its record kept. One with no record reopens at its
+/// place with its words. A placeholder comes back at the next Look or
+/// watch of its path, or the load of its kind.
pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void {
const k = p.kinds.byName(s.nameOf()) orelse {
s.live = false;
@@ -1002,14 +1003,19 @@ pub fn reviveSlot(p: *Pardes, id: usize, s: *Kind.Slot) void {
};
s.ops = p.kinds.ops[k];
s.gen = p.kinds.kinds[k].gen;
- const bytes: ?[]u8 = if (s.record == null and s.path.len > 0) filesystem.read(p, s.path) catch null else null;
+ // A replica has no code to read it for: the authority's outcome is taped.
+ const bytes: ?[]u8 = if (s.ops != null and s.path.len > 0) filesystem.read(p, s.path) catch null else null;
defer if (bytes) |b| p.gpa.free(b);
- const kept = .{ s.next_tick, s.view, s.focused };
- _ = Kind.reopen(p, id, s, bytes);
- // A replica's Shadow is the authority's pane as it is: it ticks when
- // that one does, not because it was loaded (a kind opened here ticks
- // to lay itself out).
- if (s.ops == null) s.next_tick, s.view, s.focused = kept;
+ const kept = .{ s.next_tick, s.views, s.focused };
+ if (!Kind.reopen(p, id, s, bytes)) {
+ s.ops = null;
+ s.live = false;
+ } else if (s.ops == null) {
+ // A replica's Shadow is the authority's pane as it is: it ticks
+ // when that one does, not because it was loaded (a kind opened
+ // here ticks to lay itself out).
+ s.next_tick, s.views, s.focused = kept;
+ }
}
/// A PDF pane of a dump from before the pdf addon: a pane of the addon's
diff --git a/src/look.zig b/src/look.zig
index 0414f6d1..7f76602e 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -622,8 +622,9 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
var anchor: ?usize = null;
if (pane.addon != null) {
// A kind's own rows, if it has a search.
- const rows = Kind.search(p, id, pat, out) orelse "";
- out_len = rows.len;
+ const rows = Kind.search(p, id, pat) orelse "";
+ out_len = @min(rows.len, out.len);
+ @memcpy(out[0..out_len], rows[0..out_len]);
nrows = std.mem.count(u8, rows, "\n");
} else {
const lines = try edit.paneCursorLines(p, &pane.body);
@@ -1738,6 +1739,8 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void {
return missed(p, id, "no pane {s}", .{pl.path[0..@min(pl.path.len, 32)]});
}
const target = p.panes[t.id].?;
+ // A kind's placeholder waiting for its file opens if it is here now.
+ if (target.addon) |k| if (!k.live) pardes.dump.reviveSlot(p, t.id, k);
// A place in a kind's pane is its `address`'s, a miss its to say.
if (target.addon != null and t.at.line > 0) {
var place: [41]u8 = undefined;
diff --git a/src/replica.zig b/src/replica.zig
index e3deff40..f2c8f8b4 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -449,7 +449,7 @@ pub const Screens = struct {
// Within the wire's bound, its head (6 bytes) aside: a page of a
// PDF in a wide window is more, and a message past it ends
// the peer's link (its reader stops at it).
- if (!try screen_state.encodeShadow(x.s.gpa, &pp.shadow, &frame, k.prefix.slice(), k.placed, k.pointer, wire.max_payload - 6, &w.writer)) continue;
+ if (!try screen_state.encodeShadow(x.s.gpa, &pp.shadow, &frame, k.prefix.slice(), false, k.pointer, wire.max_payload - 6, &w.writer)) continue;
try x.out.append(x.s.gpa, try x.s.gpa.dupe(u8, w.written()));
};
}