summaryrefslogtreecommitdiff
path: root/src/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:19:25 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:03:40 -0300
commitf2ede98aee0265e3506f5afd6039c70be7812767 (patch)
tree284a64fc9fcf7ba777a20fad75cc6295d70695fb /src/views.zig
parent08c9415dde1a1d5da2c20124c4fcd4c92783b290 (diff)
downloadpardes-f2ede98aee0265e3506f5afd6039c70be7812767.tar.gz
pardes-f2ede98aee0265e3506f5afd6039c70be7812767.zip
remote clients: a pointer's hit carries the place it was made on (Layer.Place, on the wire, version 17) and a step resolves it from that, never from this process's frame (`surface`, `.local`), which a session never draws for a client: a window's pointer over a tag diverged it at once (the user's `tape byte 119`, 15 rejoins in 25 s) and a click there aborted it; a replay that meets a site its tape lacks, or makes a syscall that is none, is a divergence that goes on harmless (poisonOf), not a panic, and a speculation that makes one waits (Tty's shell lookup, untaped, is a value site now, as Shell's was); a copy over a queue is refused, not asserted; a session's last client, while no one else watches it, leaves it its layout (leaveView, settled as closeView is), which its rejoin copies; a redial waits only after an Upgrade's `refused` (a divergence's redialled a gone session 20 s); a dying session shuts its clients' links before its trace, and an --attach client ends its ssh and socket whatever way it exits; a far join's hashing stops at a blob once its client is let go (its leave waits for it in the step); a confirmed speculation's state is checked against its unit's digest, and the trace gives a key's and a pointer's words; test/daemon.py: 200 far joins level, a window's pointer swept over tags and body, ssh stand-in clients refused and detached, a client of a killed session ending in 2 s; in-process tests for each
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/views.zig')
-rw-r--r--src/views.zig67
1 files changed, 66 insertions, 1 deletions
diff --git a/src/views.zig b/src/views.zig
index 34644a96..ac274621 100644
--- a/src/views.zig
+++ b/src/views.zig
@@ -422,7 +422,7 @@ pub fn open(p: *Pardes) ?u8 {
};
const slot = p.parked[k].?;
slot.* = .{ .view = .{ .screen_w = p.screen_w, .screen_h = p.screen_h } };
- inline for (.{ "screen_w", "screen_h", "cell_pixels", "row_metrics", "ncol", "col_weight", "col_panes", "col_n", "col_serial", "finder", "active", "active_column", "jumps", "njumps", "jcur", "windowed", "native_images", "native_image_patches" }) |name|
+ inline for (sized ++ laid_out ++ .{ "windowed", "native_images", "native_image_patches" }) |name|
@field(slot.view, name) = @field(p, name);
slot.view.col_tags = @splat(.{ .what = .column, .gpa = p.gpa });
for (p.panes, 0..) |s, id| {
@@ -435,6 +435,39 @@ pub fn open(p: *Pardes) ?u8 {
return k;
}
+/// How a view is laid out and focused: what a new one takes of the live
+/// one (`open`), and what one going leaves the view that stays (`closeKeeping`).
+const laid_out = .{ "ncol", "col_weight", "col_panes", "col_n", "col_serial", "finder", "active", "active_column", "jumps", "njumps", "jcur" };
+const sized = .{ "screen_w", "screen_h", "cell_pixels", "row_metrics" };
+
+/// View `k` gone, and the view that stays live laid out as `k` was: its
+/// columns, its focus, its panes where they were scrolled and its cursors
+/// where they were. For a session's last client while no one else watches
+/// it (replica.Peers.leave): the client's rejoin (an Upgrade's, a diverged
+/// one's) copies the live view (`open`), so it finds its own again.
+pub fn closeKeeping(p: *Pardes, k: u8) void {
+ if (!isOpen(p, k) or count(p) == 1) return;
+ to(p, k);
+ const other: u8 = for (0..max) |i| {
+ if (i != k and isOpen(p, @intCast(i))) break @intCast(i);
+ } else unreachable;
+ const slot = p.parked[other].?;
+ // Its size too: the terminals it sized keep theirs, no shell redrawn for
+ // a size it is given back at the rejoin.
+ inline for (sized ++ laid_out) |name| @field(slot.view, name) = @field(p, name);
+ for (p.panes, 0..) |s, id| {
+ const pane = s orelse {
+ slot.serials[id] = 0;
+ continue;
+ };
+ if (pane.pv_known & (@as(u8, 1) << @intCast(other)) != 0 and pane.pv[other].body.sels.len > 0) p.gpa.free(pane.pv[other].body.sels);
+ slot.serials[id] = pane.serial;
+ pane.pv[other] = fresh(pane);
+ pane.pv_known |= @as(u8, 1) << @intCast(other);
+ }
+ close(p, k);
+}
+
/// View `k` gone, and all it held; the live one moves to another first.
/// The last view stays: a session without a client keeps its own.
pub fn close(p: *Pardes, k: u8) void {
@@ -771,6 +804,38 @@ test "a view closing leaves the others as they were" {
try testing.expectEqual(@as(i32, 70), pane.body.cur_row);
}
+test "the last client's view going leaves the session its layout, which a rejoin copies" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
+ defer p.deinit();
+ const text = try numbered(gpa, 100);
+ defer gpa.free(text);
+ const pane = try p.setTestFile(text);
+ const k = p.openView().?;
+ p.toView(k);
+ p.update(.{ .resize = .{ .cols = 120, .rows = 40 } });
+ p.update(.{ .command = "Newcol" });
+ p.update(.{ .command = "New" });
+ const made = p.active;
+ const ncol = p.ncol;
+ p.active = 0;
+ p.sync();
+ cursorTo(p, pane, 60);
+ p.leaveView(k);
+ try testing.expectEqual(@as(usize, 1), count(p));
+ try testing.expectEqual(ncol, p.ncol);
+ try testing.expect(layout.findPane(p, made) != null);
+ try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
+ try testing.expectEqual(@as(u16, 120), p.screen_w);
+ // Its client back (a view copied from the live one): all of it again.
+ const again = p.openView().?;
+ p.toView(again);
+ try testing.expectEqual(ncol, p.ncol);
+ try testing.expect(layout.findPane(p, made) != null);
+ try testing.expectEqual(@as(usize, 0), p.active);
+ try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
+}
+
test "drawing the other views leaves the live one as it was, to the digest" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });