summaryrefslogtreecommitdiff
path: root/core/views.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 01:00:47 -0300
committerGabriel Schneider <[email protected]>2026-11-21 01:08:24 -0300
commit76565c605defb03ab6aa8300b93f306054a67efd (patch)
tree706cc64e23ae33ec6be1d6b9164750ba42da712b /core/views.zig
parent6d937cd125ca04a2edb92b2d014014ee6c2eb45d (diff)
parentdac87eaa1d57acfc5b2dd8427e7fbacfe065e613 (diff)
downloadpardes-76565c605defb03ab6aa8300b93f306054a67efd.tar.gz
pardes-76565c605defb03ab6aa8300b93f306054a67efd.zip
integration: the terminals' side line on the landed main: pardes-term-join-4 (terminals by the pty's bytes: a client's emulator fed the session's bytes, reload at a join, the lag bound; the query rows' paint decided on replicated state; views.park's leak; a view kept for its client's rejoin; C and Alt-C on a long text walking on from the row last tried: 306 G instructions to 194 M; the soak's witness and watchdog) and main (pardes-new-upgrade); seven conflicts: the wire's version (the side line's 24 is 26 here: 24 is the bye's close byte, 25 the 9P state), Peers' join (the view typed, the lag limit a field's default), a peer's end (the view's index; cut joins again), the client's and the soak's bye (the struct, again or lagged), daemon.py's WIRE; three more the compiler found (a test's view typed: its index where a u8 is asked)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/views.zig')
-rw-r--r--core/views.zig43
1 files changed, 41 insertions, 2 deletions
diff --git a/core/views.zig b/core/views.zig
index 89dcb454..2ddbb523 100644
--- a/core/views.zig
+++ b/core/views.zig
@@ -29,6 +29,13 @@ const MAX_PANES = pardes.MAX_PANES;
/// Views at once: a window or terminal each.
pub const max = 4;
+/// How long a view kept for its client's rejoin (`away`) is that client's
+/// alone: a join with no room is refused meanwhile, and takes it after
+/// (Pardes.openView). A client that said it joins again dials at once, and
+/// its join waits for its dump to cross: the soak's far link (1 Mbit/s,
+/// 200 ms each way) has taken up to 18.3 s from one of its joins to the
+/// next (a flood, joins for its lag). Past 30 s, it is taken as gone.
+pub const away_kept_ns: u64 = 30 * std.time.ns_per_s;
/// A pane's fields that are each view's own: where it is in the view's
/// layout, which of its texts has the keyboard, how far it is scrolled, and
@@ -324,7 +331,11 @@ pub fn gone(p: *Pardes, id: usize) void {
fn park(p: *Pardes) void {
for (p.panes) |s| if (s) |pane| {
+ // The slot owns the live text's selections now: known, so that
+ // the pane's end or the view's frees them (a pane made while one
+ // view was open had no view known).
pane.pv[p.live] = extract(pane);
+ pane.pv_known |= bit(p.live);
};
}
@@ -466,6 +477,7 @@ pub fn away(p: *Pardes, k: u8) void {
if (!isOpen(p, k)) return;
if (k == p.live) if (looked(p, k) orelse open(p)) |other| to(p, other);
p.views_away |= bit(k);
+ p.views[k].?.away_ns = p.clock.now_ns;
}
/// The session's end: what each view holds.
@@ -601,6 +613,25 @@ test "each view has its own cursor and scroll, and an edit in one is in the othe
try testing.expectEqual(Text.Mode.normal, pane.body.mode);
}
+// A pane made while one view is open is its share there alone; the
+// ranges beside its primary that a key makes are the live text's, and
+// the view's slot owns them once another view is live (park): freed with
+// the pane, or with that view.
+test "a text's ranges beside its primary, made while one view was open, are freed once another view has been live" {
+ const gpa = testing.allocator;
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer p.deinit();
+ const text = try numbered(gpa, 20);
+ defer gpa.free(text);
+ const pane = try p.setTestFile(text);
+ // A second cursor below, and a key typed in insert mode at both.
+ typeKeys(p, "Cix");
+ escape(p);
+ try testing.expect(pane.body.sels.len > 0);
+ try testing.expectEqual(@as(?View.Id, .at(1)), p.openView());
+ p.toView(.at(1));
+}
+
test "each view has its own layout and focus over the same panes" {
const gpa = testing.allocator;
const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 100, .rows = 30 });
@@ -742,7 +773,7 @@ test "the last client's view going leaves the session its layout, which a rejoin
try testing.expectEqual(@as(i32, 60), pane.body.cur_row);
}
-test "a client's view kept for its rejoin: through an Upgrade's dump, each client back in its own; a join with no room lets one go" {
+test "a client's view kept for its rejoin: through an Upgrade's dump, each client back in its own; a join with no room lets one go only once it has been kept away_kept_ns" {
const gpa = testing.allocator;
const opts: pardes.Options = .{ .tty_only = true, .cols = 100, .rows = 30 };
const p = try Pardes.init(gpa, opts);
@@ -775,9 +806,17 @@ test "a client's view kept for its rejoin: through an Upgrade's dump, each clien
try testing.expect(layout.findPane(q, made[1 - i]) == null);
}
try testing.expect(!q.rejoinView(ks[0]));
- // A client that never comes back: its view goes when a join has no room.
+ // A client that said it joins again is coming back (a far one's join
+ // for its lag waits seconds for its dump): a join with no room is
+ // refused, its view not let go, until `away_kept_ns` has passed.
p.toView(.at(0));
try testing.expectEqual(@as(?View.Id, .at(3)), p.openView());
+ try testing.expectEqual(@as(?View.Id, null), p.openView());
+ p.advance(p.clock.now_ns + away_kept_ns - 1);
+ try testing.expectEqual(@as(?View.Id, null), p.openView());
+ try testing.expect(isAway(p, ks[0].index()) and isAway(p, ks[1].index()));
+ // One that never comes back: its view goes once the bound has passed.
+ p.advance(p.clock.now_ns + 1);
try testing.expectEqual(ks[0], p.openView());
try testing.expect(!isAway(p, ks[0].index()) and isAway(p, ks[1].index()));
}