summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig40
-rw-r--r--core/draw.zig45
-rw-r--r--core/replica.zig29
-rw-r--r--core/rollback.zig2
-rw-r--r--core/root.zig1
-rw-r--r--core/surface.zig50
-rw-r--r--core/tape.zig2
-rw-r--r--core/views.zig27
8 files changed, 152 insertions, 44 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 398d5973..0e37f945 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -282,8 +282,12 @@ theme_file_loaded: config.Runtime.Text(limits.host_path_cap) = .{},
theme_file_generation: u32 = 0,
theme_file_pane: u8 = 0,
chrome: colors.ChromeTheme = colors.initial_chrome,
-/// Every drawn frame's timings (FrameStats: the Debug box, PARDES_FRAMES).
-frames: FrameStats = .{},
+/// Every drawn frame's timings (FrameStats: the Debug box, PARDES_FRAMES):
+/// its runner's (`Options.frames`), which its frontend writes as it draws
+/// and reads input, never the core's memory; a core with no runner (a
+/// test's) has its own.
+frames: *FrameStats = undefined,
+own_frames: FrameStats = .{},
quit: bool = false,
/// A detached session with no frontend attached: nothing renders, so
/// no input ever dismisses a message (Messages.expireUnattended).
@@ -334,9 +338,6 @@ boot: Boot = .shell,
/// Is there a frame worth drawing? Cleared once one is presented, set by
/// anything that can change what is on screen. The first frame always is.
needs_frame: bool = true,
-/// Set by a shell whose present was skipped (no swapchain image): the
-/// frame is still owed, and the next pump draws it again.
-present_skipped: bool = false,
clock: Clock = .{},
/// Builtins announce themselves on the message row. Off while startup
/// configuration is applied: those lines are nobody clicking, and should
@@ -388,6 +389,9 @@ restore_req: ?[]const u8 = null,
restore_buf: [1024]u8 = @splat(0),
surface: Surface = .{},
+/// What a frontend reads beside the frame's cells (surface.Facts), filled
+/// as it is placed (draw.place); the frame points at it.
+facts: pardes.Facts = .{},
/// A replica's predicted echo (core/term/echo.zig), drawn over its terminals:
/// presentation, its own, in no digest and no rollback copy. Null on a
/// session's own core.
@@ -427,9 +431,11 @@ diff_output: pardes.ansi.DiffOutput = .{},
pub const replica = .{
.local = .{
// A frame, and the timings that make it.
- "surface", "frames", "chrome",
+ "surface", "facts", "frames",
+ "own_frames",
+ "chrome",
"frame_arena", "scratch", "needs_frame",
- "present_skipped", "echo",
+ "echo",
// Drained by every pump before its digest; a replica's queues
// are its own.
"effects",
@@ -522,6 +528,7 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes {
.fallback = .{ .gpa = gpa },
.db = .{ .kind = opts.state },
};
+ p.frames = opts.frames orelse &p.own_frames;
errdefer p.deinit();
p.fs.started = ctlfs.events.now();
for (opts.mounts) |mount| try p.fs.mount(gpa, mount.name, mount.dial);
@@ -1499,23 +1506,23 @@ pub fn pump(p: *Pardes, host: Host) !void {
if (v.watched) |f| if (!f(h.ctx)) return;
// The one view this process shows (a replica client's is its own
// process's to draw), drawn as it is if another's is live.
+ // Not shown by the frontend (Host.present): owed.
+ var skipped = false;
const shown = Views.shown(p);
if (shown != p.live) {
- if (shown) |k| try Views.drawOne(p, k, .{ .ctx = h.ctx, .f = v.present });
+ if (shown) |k| skipped = !try Views.drawOne(p, k, .{ .ctx = h.ctx, .f = v.present });
} else {
_ = p.frame_arena.reset(.{ .retain_with_limit = memory.limits.frame_kept });
p.frames.mark_update = FrameStats.nowNs();
p.frames.view = if (p.panes[p.view().active]) |pane| pane.scroll() else 0;
const surface = try p.render(p.frame_arena.allocator());
p.frames.mark_render = FrameStats.nowNs();
- if (v.present) |f| f(h.ctx, surface);
+ if (v.present) |f| skipped = !f(h.ctx, surface);
Stream.askAhead(p);
}
// Settled before post_present: a shell ticks there, and what that
// tick moves owes the next frame.
- const skipped = p.present_skipped;
- p.needs_frame = p.present_skipped;
- p.present_skipped = false;
+ p.needs_frame = skipped;
if (v.post_present) |f| f(h.ctx);
// Still moving: the next frame is owed a period from now.
const owed = if (p.nextWake()) |due| due <= p.clock.stepped_ns + frame_ns else false;
@@ -2234,7 +2241,9 @@ pub const Boot = enum {
};
pub const Options = struct {
- pub const replica = .{ .local = .{"distrusted"} };
+ /// Not taped: the client's list of distrusted kinds, and where its
+ /// runner keeps its frame statistics.
+ pub const replica = .{ .local = .{ "distrusted", "frames" } };
tty_only: bool = false,
/// The first view's frontend is a window (`Pardes.frontend`), as a
/// window's build says: an option, taped with the rest, so that a
@@ -2285,6 +2294,8 @@ pub const Options = struct {
/// Where each frame's Surface text is built. Hosts pass a purpose-built
/// stack-fallback arena; null means the general allocator.
frame_allocator: ?std.mem.Allocator = null,
+ /// The runner's frame statistics (`Pardes.frames`); null: the core's own.
+ frames: ?*FrameStats = null,
cols: u16 = 80,
rows: u16 = 24,
};
@@ -2715,8 +2726,9 @@ test "a frame no one watches is not drawn, and is drawn once someone does" {
var presents: usize = 0;
var seen = false;
const vtable: Host.VTable = .{ .present = present, .watched = watched };
- fn present(_: ?*anyopaque, _: *const Surface) void {
+ fn present(_: ?*anyopaque, _: *const Surface) bool {
presents += 1;
+ return true;
}
fn watched(_: ?*anyopaque) bool {
return seen;
diff --git a/core/draw.zig b/core/draw.zig
index f4b08635..f41674cb 100644
--- a/core/draw.zig
+++ b/core/draw.zig
@@ -36,6 +36,47 @@ const MAX_COLS = pardes.MAX_COLS;
const MAX_TAG_ROWS = pardes.MAX_TAG_ROWS;
const NOTICE_LAYER_BASE = pardes.NOTICE_LAYER_BASE;
+/// What a frontend reads beside the cells (surface.Facts), of the live
+/// view as it is now: with each frame (`place`), and by a runner after an
+/// input it applied, outside any step, writing nothing of the core's.
+pub fn facts(p: *const Pardes, f: *pardes.Facts) void {
+ viewFacts(p, f);
+ for (p.panes, 0..) |slot, id| if (slot) |pane| paneFacts(p, f, id, pane);
+}
+
+/// The view's facts; its panes' table emptied (`paneFacts` fills it).
+fn viewFacts(p: *const Pardes, f: *pardes.Facts) void {
+ const v = p.view();
+ // Field by field: the panes' table is written only where a pane is.
+ f.screen_w = v.screen_w;
+ f.screen_h = v.screen_h;
+ f.cell_pixels = v.cell_pixels;
+ f.row_metrics = v.row_metrics;
+ f.open = 0;
+ f.active = @intCast(v.active);
+ f.back = v.jumps.n > 0 and v.jumps.cur > 0;
+ f.forward = v.jumps.n > 0 and v.jumps.cur + 1 < v.jumps.n;
+ f.cursor_blink = p.settings.cursor_blink;
+ f.jump_trail = p.settings.jump_trail;
+ f.pet = p.settings.pet;
+ f.inactive_dim = p.settings.inactive_dim;
+ f.tagline_percent = p.settings.font.tagline_percent;
+}
+
+/// Open pane `id`'s facts.
+fn paneFacts(p: *const Pardes, f: *pardes.Facts, id: usize, pane: *const Pane) void {
+ f.open |= @as(u64, 1) << @intCast(id);
+ f.panes[id] = .{
+ .rect = p.view().rects[id],
+ .tag_rows = pane.tag_rows,
+ .context_rows = pane.context_rows,
+ .serial = pane.serial,
+ .kind = if (pane.addon != null) .addon else if (pane.isTerminal()) .terminal else .text,
+ .program_wheel = pane.isTerminal() and panes.Term.modes(pane.terminal).wheel,
+ .normal = pane.body.mode == .normal,
+ };
+}
+
/// Where every part of the frame goes, decided once before anything is
/// painted: the page; each pane's grip, tag, body, rail (with its thumb)
/// and notice chips; each column's grip and tag; the workspace tag. The
@@ -44,9 +85,13 @@ pub fn place(p: *Pardes, s: *Surface) void {
const v = p.view();
s.nregions = 0;
s.nrail_ticks = 0;
+ // The facts filled in the walk the frame's places take anyway.
+ viewFacts(p, &p.facts);
+ s.facts = &p.facts;
s.addRegion(.{ .kind = .page, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = s.rows } });
for (&p.panes, 0..) |*slot, id| {
const pane = slot.* orelse continue;
+ paneFacts(p, &p.facts, id, pane);
Messages.collectNotices(p, pane, v.rects[id], id);
const r = v.rects[id];
if (r.w <= config.GUTTER or r.h == 0) continue;
diff --git a/core/replica.zig b/core/replica.zig
index 993c1f09..31a06214 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -1230,20 +1230,14 @@ pub const Replica = struct {
/// Its own view drawn and presented through `present`, between steps
/// (views.drawOne): nothing the digest covers moves. The epoch's trees
/// held while a copy is (a render can make or drop a syntax tree).
- pub fn draw(r: *Replica, present: pardes.views.Present) void {
+ pub fn draw(r: *Replica, present: pardes.views.Present) bool {
rollback.Epoch.select(&r.epoch);
defer rollback.Epoch.select(null);
- pardes.views.drawOne(r.core(), r.view, present) catch {};
- }
-
- /// `f(ctx, core)` with its own view live, outside any step, as `draw`
- /// draws it (views.within): what its frontend reads of its own view
- /// (its pointer's cells, its size) while another client's input was the
- /// session's last.
- pub fn within(r: *Replica, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) void {
- rollback.Epoch.select(&r.epoch);
- defer rollback.Epoch.select(null);
- pardes.views.within(r.core(), r.view, ctx, f) catch {};
+ // A frame drawing owes another is this process's, not the core's.
+ const c = r.core();
+ const needs = c.needs_frame;
+ defer c.needs_frame = needs;
+ return pardes.views.drawOne(c, r.view, present) catch true;
}
/// One of the authority's terminal messages (`Screens.flush`, or an
@@ -4180,14 +4174,14 @@ test "a replica joined from a themed dump paints its taglines in the restored th
try std.testing.expectEqualStrings("rose_pine_moon", r.core().theme().name);
try std.testing.expectEqual(expected.tag_bg, r.core().chromeTheme().tag_bg);
try std.testing.expectEqual(expected.tag_fg, r.core().chromeTheme().tag_fg);
- r.draw(.{ .ctx = null, .f = null });
+ _ = r.draw(.{ .ctx = null, .f = null });
try std.testing.expectEqual(expected.tag_bg, r.core().surface.chrome.tag_bg);
try std.testing.expectEqual(expected.tag_fg, r.core().surface.chrome.tag_fg);
try std.testing.expectEqual(digestOf(a), r.digest());
// A later theme is an ordinary confirmed unit, its chrome set at once.
r.confirm(try a.local(.{ .command = "Theme monokai_pro_classic" }));
r.settle();
- r.draw(.{ .ctx = null, .f = null });
+ _ = r.draw(.{ .ctx = null, .f = null });
const changed = pardes.colors.ChromeTheme.fromTheme(a.core.theme());
try std.testing.expectEqual(changed.tag_bg, r.core().surface.chrome.tag_bg);
try std.testing.expectEqual(changed.tag_fg, r.core().surface.chrome.tag_fg);
@@ -4962,9 +4956,10 @@ test "a closed terminal with a kitty image brought back on a client: its image d
r.confirm(try a.local(.{ .focus = true }));
const Seen = struct {
px: ?[4]u8 = null,
- fn take(ctx: ?*anyopaque, s: *const pardes.Surface) void {
+ fn take(ctx: ?*anyopaque, s: *const pardes.Surface) bool {
const seen: *@This() = @ptrCast(@alignCast(ctx.?));
for (s.placements.items) |pl| seen.px = pl.raster.bytes()[0..4].*;
+ return true;
}
};
var sent: std.ArrayListUnmanaged([]u8) = .empty;
@@ -4976,13 +4971,13 @@ test "a closed terminal with a kitty image brought back on a client: its image d
try key(r, 'o', &sent);
try std.testing.expect(r.copy.held);
var seen: Seen = .{};
- r.draw(.{ .ctx = &seen, .f = Seen.take });
+ _ = r.draw(.{ .ctx = &seen, .f = Seen.take });
try std.testing.expectEqual([4]u8{ 0x11, 0x22, 0x33, 0xff }, seen.px.?);
// The session's own key first: back to the copy, the key applied again.
r.confirm(try a.local(.{ .key = .{ .cp = 'l', .text = "l" } }));
r.settle();
seen = .{};
- r.draw(.{ .ctx = &seen, .f = Seen.take });
+ _ = r.draw(.{ .ctx = &seen, .f = Seen.take });
try std.testing.expectEqual([4]u8{ 0x11, 0x22, 0x33, 0xff }, seen.px.?);
r.confirm(try a.take(sent.items[0]));
r.settle();
diff --git a/core/rollback.zig b/core/rollback.zig
index a17e47ba..a6c6e5bd 100644
--- a/core/rollback.zig
+++ b/core/rollback.zig
@@ -525,7 +525,7 @@ fn annotatedStruct(comptime T: type) bool {
/// step reads what the authority holds of them off the tape
/// (tape.authority), never a replica's.
fn unsaved(comptime name: []const u8) bool {
- return std.mem.eql(u8, name, "effects") or std.mem.eql(u8, name, "in_q") or std.mem.eql(u8, name, "frames") or
+ return std.mem.eql(u8, name, "effects") or std.mem.eql(u8, name, "in_q") or std.mem.eql(u8, name, "frames") or std.mem.eql(u8, name, "own_frames") or
std.mem.eql(u8, name, "shell_rows") or std.mem.eql(u8, name, "echo") or std.mem.eql(u8, name, "store") or
std.mem.eql(u8, name, "recent");
}
diff --git a/core/root.zig b/core/root.zig
index c10a2598..04909bd7 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -51,6 +51,7 @@ pub const NativeGeometry = @import("surface.zig").NativeGeometry;
pub const containGeometry = @import("surface.zig").containGeometry;
pub const RectCell = @import("surface.zig").RectCell;
pub const Surface = @import("surface.zig").Surface;
+pub const Facts = @import("surface.zig").Facts;
pub const Region = @import("surface.zig").Region;
pub const Chrome = @import("surface.zig").Chrome;
pub const RailTick = @import("surface.zig").RailTick;
diff --git a/core/surface.zig b/core/surface.zig
index eb552cf1..fdcb52c8 100644
--- a/core/surface.zig
+++ b/core/surface.zig
@@ -186,6 +186,53 @@ pub const Chrome = struct {
rail_px: u8 = 12,
};
+/// What a frontend takes from the core beside the cells to draw a frame and
+/// to turn its input into events, filled with the frame (`draw.place`, in
+/// the core's `facts`, which the frame points at: a Surface made for a
+/// moment, a tag line's, copies no record): the
+/// view's size and its panes' places as they were drawn, and the settings
+/// a frontend draws by. A frontend reads this and the rest of the Surface,
+/// never the core, so a replica client needs no view of its own made live
+/// to read them.
+pub const Facts = struct {
+ pub const Pane = struct {
+ /// The pane's whole rectangle in the view, tag rows and body.
+ rect: layout.Rect = .{},
+ tag_rows: u16 = 0,
+ /// The rows a scrolling body holds at its top (Pane.context_rows).
+ context_rows: u16 = 0,
+ serial: u32 = 0,
+ kind: enum(u8) { text, terminal, addon } = .text,
+ /// A terminal whose program takes the wheel (codex, htop, less).
+ program_wheel: bool = false,
+ /// Its body in normal mode (not insert or raw).
+ normal: bool = false,
+ };
+ screen_w: u16 = 0,
+ screen_h: u16 = 0,
+ cell_pixels: pardes.CellPixels = .{},
+ row_metrics: pardes.RowMetrics = .{},
+ /// The open pane slots, and what each is.
+ open: u64 = 0,
+ panes: [MAX_PANES]Pane = undefined,
+ active: u8 = 0,
+ /// The view's jumps can go back, forward.
+ back: bool = false,
+ forward: bool = false,
+ cursor_blink: bool = true,
+ jump_trail: bool = false,
+ pet: config.Runtime.Pet = .off,
+ inactive_dim: u8 = 0,
+ tagline_percent: u8 = 100,
+
+ /// A frame no core placed (a tag line's, a test's).
+ pub const none: Facts = .{};
+
+ pub fn pane(f: *const Facts, id: usize) ?*const Pane {
+ return if (id < MAX_PANES and f.open & (@as(u64, 1) << @intCast(id)) != 0) &f.panes[id] else null;
+ }
+};
+
/// The canonical interface: what a frame of pardes IS. The tui shell writes
/// these cells to vaxis one-to-one; the SDL shells rasterize them.
pub const Surface = struct {
@@ -193,6 +240,9 @@ pub const Surface = struct {
/// `box` is acme's boxcursor, shown while a pane or a column is carried
/// by its grip (cols.c:485, rows.c:151).
pub const PointerShape = enum(u8) { arrow, link, target, box };
+ /// What a frontend reads beside the cells (Facts): the core's, filled
+ /// as this frame was placed.
+ facts: *const Facts = &Facts.none,
gpu_frames: [MAX_PANES]?GpuFrame = @splat(null),
pointer_shape: PointerShape = .arrow,
body_layers: [MAX_PANES]Layer = @splat(.{}),
diff --git a/core/tape.zig b/core/tape.zig
index 2b9272a6..270147c2 100644
--- a/core/tape.zig
+++ b/core/tape.zig
@@ -176,7 +176,7 @@ pub const shape = blk: {
};
/// Fields a host writes straight into the core between its calls.
-const watched = .{ "frontend", "present_skipped", "needs_frame", "quit", "active", "unattended" };
+const watched = .{ "frontend", "needs_frame", "quit", "active", "unattended" };
/// Watched field `name` of `p`: the live view's, or the session's.
fn watchedOf(p: *Pardes, comptime name: []const u8) *Watched(name) {
diff --git a/core/views.zig b/core/views.zig
index b8698854..9d627a17 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -473,7 +473,7 @@ pub fn deinit(p: *Pardes) void {
for (&p.views) |*slot| if (slot.*) |*v| freeView(p, v);
}
-pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) void };
+pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *const pardes.Surface) bool };
/// The view this process's frontend shows: the one open view that is no
/// replica client's (`undrawn`) and kept for none (`away`), if there is one.
@@ -482,23 +482,28 @@ pub fn shown(p: *const Pardes) ?u8 {
return null;
}
-fn drawLive(present: Present, p: *Pardes) anyerror!void {
+fn drawLive(drawn: *Drawn, p: *Pardes) anyerror!void {
_ = p.frame_arena.reset(.{ .retain_with_limit = pardes.memory.limits.frame_kept });
const surface = try p.render(p.frame_arena.allocator());
- if (present.f) |f| f(present.ctx, surface);
+ if (drawn.present.f) |f| drawn.shown = f(drawn.present.ctx, surface);
}
+const Drawn = struct { present: Present, shown: bool = true };
+
/// View `k` drawn and presented outside any step (the pump's other views,
/// a replica client's own): the live view put back after exactly as it
-/// was, so the digest is the same. No post_present.
-pub fn drawOne(p: *Pardes, k: u8, present: Present) !void {
- try within(p, k, present, drawLive);
+/// was, so the digest is the same. No post_present. Whether the frontend
+/// showed it (Host.present).
+pub fn drawOne(p: *Pardes, k: u8, present: Present) !bool {
+ var drawn: Drawn = .{ .present = present };
+ try within(p, k, &drawn, drawLive);
+ return drawn.shown;
}
/// `f(ctx, p)` with view `k` live, outside any step, and the live view put
-/// back after exactly as it was, as `drawOne` draws one: what a replica
-/// client's frontend reads of its own view (its pointer's cells, its size)
-/// while another client's input was the session's last. What going into
+/// back after exactly as it was: how `drawOne` draws one while another
+/// client's input was the session's last (a frontend reads what it needs
+/// of its view from the frame: surface.Facts). What going into
/// `k` and drawing it made of it (its layout worked out, a cursor brought
/// inside a changed text) is not kept: it is done again, in every replica
/// alike, when `k` is next live by an input.
@@ -791,7 +796,7 @@ test "drawing another view leaves the live one as it was, to the digest" {
p.toView(0);
cursorTo(p, pane, 95);
const before = pardes.walk.digest(Pardes, p);
- try drawOne(p, k, .{ .ctx = null, .f = null });
+ _ = try drawOne(p, k, .{ .ctx = null, .f = null });
try testing.expectEqual(@as(u8, 0), p.live);
try testing.expectEqual(before, pardes.walk.digest(Pardes, p));
p.toView(k);
@@ -809,7 +814,7 @@ test "a view drawn while another is live keeps its own cursors" {
try testing.expectEqual(@as(u16, 1), pane.body.nsel);
p.toView(0);
const before = pardes.walk.digest(Pardes, p);
- try drawOne(p, k, .{ .ctx = null, .f = null });
+ _ = try drawOne(p, k, .{ .ctx = null, .f = null });
try testing.expectEqual(before, pardes.walk.digest(Pardes, p));
p.toView(k);
try testing.expectEqual(@as(u16, 1), pane.body.nsel);