diff options
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/9p_io.zig | 4 | ||||
| -rw-r--r-- | runtime/upgrade.zig | 42 |
2 files changed, 15 insertions, 31 deletions
diff --git a/runtime/9p_io.zig b/runtime/9p_io.zig index 50011690..7933f87d 100644 --- a/runtime/9p_io.zig +++ b/runtime/9p_io.zig @@ -2241,7 +2241,7 @@ test "a runtime directory that makes the socket's path pass sun_path is refused // The session's own words, where its pane shows them; no listener. try testing.expect(start(testing.io, testing.allocator, p) == null); const pane = p.panes[0].?; - try testing.expect(std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "9p: the socket path is ")); + try testing.expect(std.mem.startsWith(u8, p.messages.saidBy(pane), "9p: the socket path is ")); } test "a runtime directory open to others is refused in words, never a silent session with no socket" { @@ -2258,7 +2258,7 @@ test "a runtime directory open to others is refused in words, never a silent ses try testing.expect(std.mem.indexOf(u8, words, "must be a directory of yours alone (mode 755") != null); try testing.expect(start(testing.io, testing.allocator, p) == null); const pane = p.panes[0].?; - try testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "chmod 700 it") != null); + try testing.expect(std.mem.indexOf(u8, p.messages.saidBy(pane), "chmod 700 it") != null); try testing.expectEqual(@as(c_int, 0), libc.chmod(&rt.directory, 0o700)); try testing.expect(noSocket("x", &buf) == null); } diff --git a/runtime/upgrade.zig b/runtime/upgrade.zig index 12163743..7e836141 100644 --- a/runtime/upgrade.zig +++ b/runtime/upgrade.zig @@ -479,16 +479,11 @@ pub fn load(gpa: std.mem.Allocator, core_gpa: std.mem.Allocator, opts: pardes.Op } } -/// An Upgrade is the session's news, not the asking view's: said in every -/// view at the pane its keyboard is on (each client reads it on its own -/// screen), a pane two views are on once; the live view is only the one -/// whose input came last before the dump. +/// An Upgrade is the session's news, not the asking view's: said once, of +/// no pane in particular, it is on every view's notice row (each client +/// reads it on its own screen). fn tellEveryView(p: *pardes.Pardes, text: []const u8) void { - var told: [pardes.MAX_PANES]bool = @splat(false); - for (p.views) |v| if (v) |view| if (!told[view.active]) { - told[view.active] = true; - p.setMessage(.at(view.active), text); - }; + pardes.Messages.say(p, .notice, pardes.MAX_PANES, text); } test "an upgrade's outcome is said in every view, at the pane its keyboard is on, whichever view's input came last" { @@ -514,7 +509,7 @@ test "an upgrade's outcome is said in every view, at the pane its keyboard is on try std.testing.expect(q.views[0].?.active != q.views[k.index()].?.active); } -test "an upgrade's outcome waits in each view kept for its client until that client is back for it: no other view's key and no clock take it" { +test "an upgrade's outcome stays on every view's notice row until something else is said: no key and no clock take it" { const gpa = std.testing.allocator; const p = try pardes.Pardes.init(gpa, .{ .tty_only = true }); defer p.deinit(); @@ -531,35 +526,24 @@ test "an upgrade's outcome waits in each view kept for its client until that cli for (kept) |k| p.awayView(k); const q = try upgradedForTest(gpa, p); defer q.deinit(); - // As the daemon's tests run (MessageLinger 0): a dismissal is at once. - q.settings.message_linger_ms = 0; const key: pardes.Event = .{ .key = .{ .cp = 'j', .text = "j" } }; - // A key in the session's own view: its outcome goes, not theirs. q.update(key); - try std.testing.expect(!saysOutcome(q, q.live)); - for (kept) |k| try std.testing.expect(saysOutcome(q, k.index())); - // Nobody attached: the clock takes nothing a kept view waits for. q.unattended = true; q.update(.tick); - for (kept) |k| try std.testing.expect(saysOutcome(q, k.index())); q.unattended = false; - // A client back for its view has it (its join's dump); the next key, - // anyone's, takes it. try std.testing.expect(q.rejoinView(kept[0])); - try std.testing.expect(saysOutcome(q, kept[0].index())); q.update(key); - try std.testing.expect(!saysOutcome(q, kept[0].index())); - try std.testing.expect(saysOutcome(q, kept[1].index())); - // One never back: once its view's kept time is up, as anyone's. q.advance(q.views[kept[1].index()].?.away_ns + pardes.views.away_kept_ns); - q.update(key); - try std.testing.expect(!saysOutcome(q, kept[1].index())); + for (kept) |k| try std.testing.expect(saysOutcome(q, k.index())); + try std.testing.expect(saysOutcome(q, q.live)); } -/// Whether view `k`'s keyboard pane says the Upgrade's outcome. +/// Whether view `k`'s notice row says the Upgrade's outcome (every view +/// has the session's one). fn saysOutcome(q: *const pardes.Pardes, k: usize) bool { - const pane = q.panes[q.views[k].?.active].?; - return std.mem.startsWith(u8, pane.msg[0..pane.msg_len], "Upgrade: now pardes "); + if (q.views[k] == null) return false; + const said = q.messages.headline() orelse return false; + return std.mem.startsWith(u8, said.text.slice(), "Upgrade: now pardes "); } /// `p` dumped and loaded as an Upgrade's new process loads it (`load`). @@ -648,5 +632,5 @@ test "an older build's dump named by a path past 4096 bytes is refused in words defer q.deinit(); try std.testing.expect(rec.fresh); const pane = q.panes[q.view().active].?; - try std.testing.expect(std.mem.indexOf(u8, pane.msg[0..pane.msg_len], "Upgrade: no build could load the session") != null); + try std.testing.expect(std.mem.indexOf(u8, q.messages.saidBy(pane), "Upgrade: no build could load the session") != null); } |
