diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-30 06:25:57 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-30 12:45:02 -0300 |
| commit | cb2688602b3f668790a9c35890973af80143697f (patch) | |
| tree | 384f147de8b8971471b59ed29879ede6e35a1ea2 /src/views.zig | |
| parent | 11e67e636b39b9b2901ec5cc49a13a012088650f (diff) | |
| download | pardes-cb2688602b3f668790a9c35890973af80143697f.tar.gz pardes-cb2688602b3f668790a9c35890973af80143697f.zip | |
gui: the window a replica client (pardes-gui --attach=<socket>:<name> and <host>:<name>, as the tty's, far through ssh as amort's: its blobs by hash and its stream in zstd) and a window session serving replicas (a terminal's client or a window's): the client feeds its replica what its window does, read over its own view (views.within) and applied after, draws its view between steps, takes the stream on its own reader and rejoins as the tty's does (replica.Link, the client's half shared with it, the far path's Have with it); the session takes clients at its step boundary, one person's input a wait, a client's view no window of its own, its font and opacity answers taped; a client says its frontend first (Event.frontend, in wire 16 beside the far word) and the tty and window builds step alike (one desktop semantics: each has the other's words, which a view takes by its own frontend, builtins.registry.here); a check asked 300 ms after the last input and check, not per wake; test/daemon.py --window-clients
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/views.zig')
| -rw-r--r-- | src/views.zig | 54 |
1 files changed, 42 insertions, 12 deletions
diff --git a/src/views.zig b/src/views.zig index 361d14a3..b9731089 100644 --- a/src/views.zig +++ b/src/views.zig @@ -523,6 +523,19 @@ pub const Present = struct { ctx: ?*anyopaque, f: ?*const fn (?*anyopaque, *cons /// are the slot's again (else a frame drawn would take them from a view, /// and a replica that draws nothing would keep them). fn drawParked(p: *Pardes, k: u8, present: Present) !void { + try unparked(p, k, present, drawLive); + copy(&drawn_fields, &p.parked[k].?.view, p); +} + +fn drawLive(present: Present, 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); +} + +/// `f(ctx, p)` with parked view `k` unparked, its slot's selections its own +/// again after (`drawParked`). +fn unparked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) !void { var sels: [MAX_PANES]struct { []Text.SelRange, u16 } = undefined; for (p.panes, 0..) |s, id| if (s) |pane| { sels[id] = .{ pane.pv[k].body.sels, pane.pv[k].body.nsel }; @@ -532,10 +545,7 @@ fn drawParked(p: *Pardes, k: u8, present: Present) !void { pane.pv[k].body.sels = sels[id][0]; pane.pv[k].body.nsel = sels[id][1]; }; - _ = 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); - copy(&drawn_fields, &p.parked[k].?.view, p); + try f(ctx, p); } /// View `k` drawn and presented outside any step, by a replica client @@ -543,12 +553,32 @@ fn drawParked(p: *Pardes, k: u8, present: Present) !void { /// view put back after exactly as it was, so the replica's digest is the /// authority's still. No post_present, as there. pub fn drawOne(p: *Pardes, k: u8, present: Present) !void { - if (k == p.view or !isOpen(p, k)) { - _ = 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); - return; - } + if (k == p.view or !isOpen(p, k)) return drawLive(present, p); + const Draw = struct { + fn draw(pr: Present, q: *Pardes, kk: u8) anyerror!void { + try drawParked(q, kk, pr); + } + }; + try withParked(p, k, present, Draw.draw); +} + +/// `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. `f` reads only. +pub fn within(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes) anyerror!void) !void { + if (k == p.view or !isOpen(p, k)) return f(ctx, p); + const Read = struct { + fn read(x: @TypeOf(ctx), q: *Pardes, kk: u8) anyerror!void { + try unparked(q, kk, x, f); + } + }; + try withParked(p, k, ctx, Read.read); +} + +/// The live view parked, `f(ctx, p, k)`, and the live view put back after +/// exactly as it was. +fn withParked(p: *Pardes, k: u8, ctx: anytype, comptime f: fn (@TypeOf(ctx), *Pardes, u8) anyerror!void) !void { const live = p.view; park(p); defer { @@ -562,10 +592,10 @@ pub fn drawOne(p: *Pardes, k: u8, present: Present) !void { pane.cols = pv.cols; pane.rows = pv.rows; } - if (pane.file) |*f| f.scroll = pv.scroll; + if (pane.file) |*file| file.scroll = pv.scroll; }; } - try drawParked(p, k, present); + try f(ctx, p, k); } // ---- tests ---- |
