diff options
Diffstat (limited to 'core/views.zig')
| -rw-r--r-- | core/views.zig | 43 |
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())); } |
