summaryrefslogtreecommitdiff
path: root/src/Messages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 13:08:44 -0300
committerGabriel Schneider <[email protected]>2026-11-05 15:21:15 -0300
commit1b2ac091200e9192f3677abe161217ba82463606 (patch)
tree8fe35cf6edaa032e4650a631598dfab2fc4aabb5 /src/Messages.zig
parent1870d06248f884439cb2ec4ef8f1b03952df2eb8 (diff)
downloadpardes-1b2ac091200e9192f3677abe161217ba82463606.tar.gz
pardes-1b2ac091200e9192f3677abe161217ba82463606.zip
effects out, the message animations: a message no longer falls into its row and dissolves out of it; it shows at once and goes when it has lingered, its lifetime the one deadline the core keeps for it (MessageLinger, a wait nextWake jumps in one step); MessageAnimation, MessageFall and MessageDissolve go with their settings, the entering and leaving phases (Pane.MessagePhase is shown or lingering), Messages.messageMotion and noticeLife, the notice band's colour blend toward the page, Layer.slide and fade, and the window's offset band, its clip to the body and its rule's fade; no frontend fades a message of its own (the window would have to see a notice come and go between frames for a 150 ms fade); the snapshot harness's, kitty harness's and casts' inits lose `MessageAnimation off`; the message tests keep their linger and stacking and lose the fall and dissolve, and `a notice leaves quicker than it arrives` goes; GUI goldens 10 and 12 to 17 change, the golden session having run with MessageAnimation on by default: a message dismissed while it fell stayed up (its dismissal undone by the next announcement), and FocusTint's stood on in every scene after; the tree before this change with MessageAnimation off draws exactly these frames, all sixteen byte for byte
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Messages.zig')
-rw-r--r--src/Messages.zig251
1 files changed, 41 insertions, 210 deletions
diff --git a/src/Messages.zig b/src/Messages.zig
index 98e005be..0ab10dab 100644
--- a/src/Messages.zig
+++ b/src/Messages.zig
@@ -1,5 +1,5 @@
//! The message row: messages and statuses a pane shows between its body and
-//! its tagline, how each line falls in, lingers and dissolves, the notices
+//! its tagline, how each line lingers once dismissed, the notices
//! built from them every frame, and the log of everything said.
const pardes = @import("pardes.zig");
const memory = @import("memory.zig");
@@ -189,23 +189,14 @@ fn showMessage(p: *Pardes, id: usize, text: []const u8, stack: bool) void {
pane.msg_announcement = false;
pane.msg_sent = false;
pane.msg_status = !stack;
- const arrives = pane.msg_len == 0 or pane.msg_life.phase == .leaving;
for (text[0..n], pane.msg[0..n]) |c, *cell| cell.* = if (c < 0x20 or c == 0x7f) ' ' else c;
pane.msg_len = @intCast(n);
// The clock when it was said (the session clock is the last pump's,
// and a 9P write after an idle hour would say it an hour ago).
pane.msg_said_ms = pardes.tape.value(.clock, nowMs, .{});
p.needs_frame = true;
- if (arrives) {
- pane.msg_life = .{ .phase = if (p.settings.message_animation and n > 0) .entering else .shown };
- } else if (pane.msg_life.phase == .lingering or
- (pane.msg_life.phase == .entering and !p.settings.message_animation))
- {
- // The same line again, or a status update: fresh, so it stays.
- pane.msg_life = .{};
- } else {
- pane.msg_life.dismissed = false;
- }
+ // New, the same line again or a status update: fresh, so it stays.
+ pane.msg_life = .{};
}
/// With no frontend attached no input dismisses a message, and a detached
@@ -239,8 +230,8 @@ pub fn expireUnattended(p: *Pardes) void {
}
/// The key or click that used to clear the message row now starts each
-/// line's exit: it stays `message_linger_ms`, then dissolves. A line
-/// already on its way out keeps its own timing.
+/// line's exit: it stays `message_linger_ms`, then goes. A line already
+/// on its way out keeps its own timing.
pub fn dismissMessage(p: *Pardes, pane: *Pane) void {
if (pane.msg_len > 0 and dismissLine(p, &pane.msg_life)) {
pane.msg_len = 0;
@@ -252,30 +243,16 @@ pub fn dismissMessage(p: *Pardes, pane: *Pane) void {
}
}
-/// Start one line's exit; true when it is gone at once (no linger, no
-/// animation).
+/// Start one line's exit; true when it is gone at once (no linger).
fn dismissLine(p: *const Pardes, life: *Pane.MessageLife) bool {
- switch (life.phase) {
- .lingering, .leaving => return false,
- // A falling line lands first, then lingers -- unless falling was
- // just turned off, and nothing will land it.
- .entering => if (p.settings.message_animation) {
- life.dismissed = true;
- return false;
- },
- .shown => {},
- }
- life.frame = 0;
- if (p.settings.message_linger_ms > 0) {
- life.phase = .lingering;
- } else if (p.settings.message_animation) {
- life.phase = .leaving;
- } else return true;
+ if (life.phase == .lingering) return false;
+ if (p.settings.message_linger_ms == 0) return true;
+ life.* = .{ .phase = .lingering };
return false;
}
-/// One animation frame of every message line. Each one that moves owes
-/// a frame, the one that finishes included: a tick asks for none itself.
+/// One frame of every lingering message line. The one that goes owes a
+/// frame: a tick asks for none itself.
pub fn advanceMessages(p: *Pardes) void {
for (p.panes) |slot| {
const pane = slot orelse continue;
@@ -294,22 +271,11 @@ pub fn advanceMessages(p: *Pardes) void {
}
}
-/// One frame of one line's life; true once it has left.
+/// One frame of one line's life; true once it has gone.
fn advanceLine(p: *const Pardes, life: *Pane.MessageLife) bool {
if (life.phase == .shown) return false;
life.frame +|= 1;
- switch (life.phase) {
- .shown => {},
- .entering => if (life.frame >= messageFrames(p.settings.message_fall_ms)) {
- life.* = .{ .phase = if (life.dismissed) .lingering else .shown };
- },
- .lingering => if (life.frame >= messageFrames(p.settings.message_linger_ms)) {
- if (!p.settings.message_animation) return true;
- life.* = .{ .phase = .leaving };
- },
- .leaving => if (life.frame >= messageFrames(p.settings.message_dissolve_ms)) return true,
- }
- return false;
+ return life.frame >= messageFrames(p.settings.message_linger_ms);
}
/// Move every lingering message line `frames` along its linger at once:
@@ -325,68 +291,25 @@ pub fn holdMessages(p: *Pardes, frames: u64) void {
}
}
-/// Frames until this pane's message lines next change: 1 while a line
-/// falls in or dissolves, the rest of its linger while one only waits, null
-/// when every line just shows.
+/// Frames until this pane's message lines next change: the rest of a
+/// linger, null when every line just shows.
pub fn messageWake(p: *const Pardes, pane: *const Pane) ?u64 {
var soonest: ?u64 = null;
const linger = messageFrames(p.settings.message_linger_ms);
for (0..@as(usize, pane.msg_older_len) + 1) |i| {
const life = if (i < pane.msg_older_len) pane.msg_older[i].life else if (pane.msg_len > 0) pane.msg_life else continue;
- const frames: u64 = switch (life.phase) {
- .shown => continue,
- .entering, .leaving => 1,
- .lingering => @max(1, linger -| life.frame),
- };
+ if (life.phase == .shown) continue;
+ const frames: u64 = @max(1, linger -| life.frame);
soonest = if (soonest) |n| @min(n, frames) else frames;
}
return soonest;
}
-/// How present a message is (1 = fully) and how far above its row it
-/// still is (rows): a fall that decelerates into place with its colour
-/// arriving ahead of it, and a dissolve.
-pub const MessageMotion = struct { alpha: f32 = 1, slide: f32 = 0 };
-
/// Animation frames a message timing lasts; at least one.
pub fn messageFrames(ms: u16) u16 {
return @intCast(@max(1, (@as(u32, ms) + animation.frame_ms - 1) / animation.frame_ms));
}
-pub fn messageMotion(p: *const Pardes, life: Pane.MessageLife) MessageMotion {
- const fall_frames = messageFrames(p.settings.message_fall_ms);
- const dissolve_frames = messageFrames(p.settings.message_dissolve_ms);
- return switch (life.phase) {
- .shown, .lingering => .{ .alpha = 1, .slide = 0 },
- .entering => blk: {
- const t = @as(f32, @floatFromInt(@min(life.frame, fall_frames))) / @as(f32, @floatFromInt(fall_frames));
- // Out of the gate fast and easing into its row (a cubic
- // ease-out), so it is there the moment it is said and the
- // last frames only settle it. No overshoot: at a row's height
- // and a dozen frames, a follow-through is a pixel or two that
- // reads as a jitter, not a bounce.
- // The drop follows the Motion flavour (its wind-up, overshoot
- // and all) over the fall's length.
- const left = 1 - animation.Motion.of(p.settings.motion).ease(t);
- // The colour leads the motion: solid by half way, so what
- // lands is already legible rather than still fading up.
- const faded = 1 - @min(1, 2 * t);
- // And never behind it, however fast the flavour leaves.
- break :blk .{ .alpha = @max(1 - faded * faded, std.math.clamp(1 - left, 0, 1)), .slide = -left };
- },
- .leaving => blk: {
- // Counted to its last frame rather than past it, so that frame
- // shows it gone and it never blinks out from part way.
- const last = @max(1, dissolve_frames - 1);
- const t = @as(f32, @floatFromInt(@min(life.frame, last))) / @as(f32, @floatFromInt(last));
- // An exit eases in: still readable for a beat, then away
- // faster and faster. It stays where it is -- the lines
- // stacked around it do not move either.
- break :blk .{ .alpha = 1 - t * t, .slide = 0 };
- },
- };
-}
-
/// What notice band `i` says. The grid pass and the band layers both
/// read it here, so a terminal and a pixel shell show the same line.
pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[16]u8) []const u8 {
@@ -398,15 +321,6 @@ pub fn noticeText(p: *const Pardes, pane: *const Pane, i: usize, leader_buf: *[1
};
}
-/// The life of the message line notice `i` shows, if it shows one.
-pub fn noticeLife(pane: *const Pane, i: usize) ?Pane.MessageLife {
- return switch (pane.notices.kinds[i]) {
- .message => pane.msg_life,
- .older => pane.msg_older[pane.notices.index[i]].life,
- .leader, .prompt => null,
- };
-}
-
fn logMessage(p: *Pardes, id: usize, text: []const u8) void {
if (text.len == 0) return;
const serial: u32 = if (p.fs.session_write) 0 else if (id < MAX_PANES) if (p.panes[id]) |pane| pane.serial else 0 else 0;
@@ -707,13 +621,12 @@ test "Msg writes the transient row by hand, bare or with text, and input ends it
try std.testing.expect(p.executeBuiltinLine(2, "Msg"));
try std.testing.expectEqualStrings("Msg: no message", row(p, 2));
- // Input starts its exit: it lingers, dissolves, and is gone.
+ // Input starts its exit: it lingers, and is gone.
p.update(.{ .key = .{ .cp = Key.escape } });
try std.testing.expectEqualStrings("Msg: no message", row(p, 2));
for (0..200) |_| p.update(.tick);
try std.testing.expectEqualStrings("", row(p, 2));
- // ...and with neither linger nor animation it is as old as your last input.
- try std.testing.expect(p.executeBuiltinLine(2, "MessageAnimation off"));
+ // ...and with no linger it is as old as your last input.
try std.testing.expect(p.executeBuiltinLine(2, "MessageLinger 0"));
try std.testing.expect(p.executeBuiltinLine(2, "Msg gone"));
p.update(.{ .key = .{ .cp = 'h' } });
@@ -754,49 +667,16 @@ test "with no frontend attached a message goes once it has lingered, on the cloc
try std.testing.expect(pane.msg_len > 0);
}
-test "a message falls in, lingers past the input that dismisses it, and dissolves" {
+test "a message lingers past the input that dismisses it, and goes" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 80, .rows = 24 });
defer p.deinit();
while (p.nextEffect()) |_| {}
const pane = p.panes[p.active].?;
- try std.testing.expect(p.settings.message_animation);
- // Crisp: the flavour whose drop leaves at full speed and lands without
- // passing its row (the others are the Motion tests').
- p.settings.motion = .crisp;
try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160"));
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
- try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase);
- try std.testing.expect(p.animationActive());
- // An ease-out fall: starts a whole row up and unseen, covers most of the
- // way at once and settles into its row, landing exactly on it without
- // passing it. Its colour is whole by half way.
- const start = messageMotion(p, pane.msg_life);
- try std.testing.expectEqual(@as(f32, -1), start.slide);
- try std.testing.expectEqual(@as(f32, 0), start.alpha);
- const fall = messageFrames(p.settings.message_fall_ms);
- var last = start;
- var first_step: f32 = 0;
- var last_step: f32 = 0;
- for (0..fall) |frame| {
- p.needs_frame = false;
- p.update(.tick);
- // Every tick that moves it owes a frame, the landing one included.
- try std.testing.expect(p.needs_frame);
- const now = messageMotion(p, pane.msg_life);
- try std.testing.expect(now.slide >= last.slide and now.slide <= 0);
- try std.testing.expect(now.alpha >= last.alpha);
- if (frame == 0) first_step = now.slide - last.slide;
- // Never slower to colour up than to arrive, and solid by half way.
- try std.testing.expect(now.alpha >= 1 + now.slide);
- if (2 * (frame + 1) >= fall) try std.testing.expectEqual(@as(f32, 1), now.alpha);
- last_step = now.slide - last.slide;
- last = now;
- }
- try std.testing.expect(first_step > 4 * last_step);
+ // Shown at once, until input; the same line again stays shown.
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
- try std.testing.expectEqual(@as(f32, 0), messageMotion(p, pane.msg_life).slide);
try std.testing.expect(!p.animationActive());
- // Shown until input, like always; the same line again does not re-enter.
for (0..100) |_| p.update(.tick);
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
@@ -809,57 +689,24 @@ test "a message falls in, lingers past the input that dismisses it, and dissolve
p.update(.{ .key = .{ .cp = 'h' } });
}
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
+ // ...then it is gone, and the tick that clears it owes the frame that
+ // shows it gone.
+ p.needs_frame = false;
p.update(.tick);
- // ...then an ease-in dissolve: it lets go slowly and goes faster and
- // faster, in place, its last frame showing it gone.
- try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase);
- const dissolve = messageFrames(p.settings.message_dissolve_ms);
- var alpha: f32 = 1;
- var first_drop: f32 = 0;
- var last_drop: f32 = 0;
- for (0..dissolve) |frame| {
- const now = messageMotion(p, pane.msg_life);
- try std.testing.expect(now.alpha <= alpha);
- try std.testing.expectEqual(@as(f32, 0), now.slide);
- if (frame == 1) first_drop = alpha - now.alpha;
- last_drop = alpha - now.alpha;
- alpha = now.alpha;
- p.needs_frame = false;
- p.update(.tick);
- }
- try std.testing.expectEqual(@as(f32, 0), alpha);
- try std.testing.expect(first_drop > 0 and first_drop < last_drop);
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
- try std.testing.expect(!p.animationActive());
- // The tick that clears it still owes the frame that shows it gone.
try std.testing.expect(p.needs_frame);
-
- // Dismissed mid-fall: it lands, then lingers.
+ try std.testing.expect(!p.animationActive());
+ // Shown again while lingering: fresh, so it stays; a status update to a
+ // line on screen swaps its text in place.
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
- try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase);
- p.update(.tick);
p.update(.{ .key = .{ .cp = 'h' } });
- try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase);
- for (0..messageFrames(p.settings.message_fall_ms)) |_| p.update(.tick);
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
- // Shown again while lingering: fresh, so it stays; a status update to a
- // line on screen swaps its text in place instead of falling again.
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
setStatus(p, p.active, "progress 50%");
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expectEqualStrings("progress 50%", pane.msg[0..pane.msg_len]);
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
- // The fall and the dissolve are timings of their own, in milliseconds.
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageFall 48"));
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageDissolve 0"));
- try std.testing.expectEqual(@as(u16, 3), messageFrames(p.settings.message_fall_ms));
- try std.testing.expectEqual(@as(u16, 1), messageFrames(p.settings.message_dissolve_ms));
- // The DumpConfig report reads back as configuration.
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageAnimation"));
- try std.testing.expect(!p.settings.message_animation);
- try std.testing.expect(p.executeBuiltinLine(p.active, "Msg plain"));
- try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
}
test "messages stack, oldest on top, each on its own timing" {
@@ -869,37 +716,35 @@ test "messages stack, oldest on top, each on its own timing" {
const pane = p.panes[p.active].?;
try std.testing.expect(p.executeBuiltinLine(p.active, "Verbose off"));
try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 160"));
- // A dissolve longer than a fall, so the second is caught mid-way.
- try std.testing.expect(p.executeBuiltinLine(p.active, "MessageDissolve 300"));
// `Verbose off` announced itself before it took effect.
pane.msg_len = 0;
pane.msg_life = .{};
- const fall = messageFrames(p.settings.message_fall_ms);
setMessage(p, p.active, "first");
- for (0..fall) |_| p.update(.tick);
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
// A second message stacks under the first instead of replacing it.
setMessage(p, p.active, "second");
try std.testing.expectEqual(@as(u8, 1), pane.msg_older_len);
try std.testing.expectEqualStrings("first", pane.msg_older[0].slice());
try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]);
- try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase);
collectNotices(p, pane, p.rects[p.active], p.active);
try std.testing.expectEqual(Pane.Notices.Kind.older, pane.notices.kinds[0]);
try std.testing.expectEqual(Pane.Notices.Kind.message, pane.notices.kinds[1]);
- // One key dismisses both, but each runs its own clock: the first starts
- // lingering now, the second only once it has landed.
+ // One key dismisses both, each on its own clock: a line already
+ // lingering keeps its timing.
p.update(.{ .key = .{ .cp = 'h' } });
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_older[0].life.phase);
- try std.testing.expectEqual(Pane.MessagePhase.entering, pane.msg_life.phase);
+ try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
+ p.update(.tick);
+ setMessage(p, p.active, "third");
+ try std.testing.expectEqual(@as(u8, 2), pane.msg_older_len);
+ p.update(.{ .key = .{ .cp = 'h' } });
const linger = messageFrames(p.settings.message_linger_ms);
- const dissolve = messageFrames(p.settings.message_dissolve_ms);
- for (0..linger + dissolve) |_| p.update(.tick);
- // The first is gone; the second, a fall later, is still dissolving.
+ for (0..linger - 1) |_| p.update(.tick);
+ // The first two are gone; the third, a frame later, still lingers.
try std.testing.expectEqual(@as(u8, 0), pane.msg_older_len);
- try std.testing.expectEqualStrings("second", pane.msg[0..pane.msg_len]);
- try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase);
- for (0..fall) |_| p.update(.tick);
+ try std.testing.expectEqualStrings("third", pane.msg[0..pane.msg_len]);
+ try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
+ p.update(.tick);
try std.testing.expectEqual(@as(u16, 0), pane.msg_len);
try std.testing.expect(!p.animationActive());
// A status ticking in place does not pile up.
@@ -1033,11 +878,8 @@ test "an idle core wants no wake and a lingering message sleeps to its linger's
p.advance(1_000_000);
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
const pane = p.panes[p.active].?;
+ // Shown, a message asks for no wake.
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg hello"));
- // Falling in: a frame from now.
- try std.testing.expectEqual(@as(?u64, p.stepped_ns + frame), p.nextWake());
- const fall = messageFrames(p.settings.message_fall_ms);
- p.advance(p.stepped_ns + fall * frame);
try std.testing.expectEqual(Pane.MessagePhase.shown, pane.msg_life.phase);
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
// A key starts the 800 ms linger: the core sleeps to its end, not a
@@ -1052,9 +894,6 @@ test "an idle core wants no wake and a lingering message sleeps to its linger's
try std.testing.expectEqual(@as(?u64, due), p.nextWake());
try std.testing.expectEqual(Pane.MessagePhase.lingering, pane.msg_life.phase);
p.advance(due);
- try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase);
- try std.testing.expectEqual(@as(?u64, due + frame), p.nextWake());
- p.advance(due + 10 * std.time.ns_per_s);
try std.testing.expectEqual(@as(usize, 0), pane.msg_len);
try std.testing.expectEqual(@as(?u64, null), p.nextWake());
@@ -1062,17 +901,9 @@ test "an idle core wants no wake and a lingering message sleeps to its linger's
// the cap on catching up with moving frames.
try std.testing.expect(p.executeBuiltinLine(p.active, "MessageLinger 5000"));
try std.testing.expect(p.executeBuiltinLine(p.active, "Msg again"));
- p.advance(p.stepped_ns + fall * frame);
p.update(.{ .key = .{ .cp = 'x' } });
const long_due = p.stepped_ns + messageFrames(5000) * frame;
try std.testing.expectEqual(@as(?u64, long_due), p.nextWake());
p.advance(long_due);
- try std.testing.expectEqual(Pane.MessagePhase.leaving, pane.msg_life.phase);
-}
-
-test "a notice leaves quicker than it arrives, each within its ยง8.1 band" {
- const settings: config.Runtime = .{};
- try std.testing.expect(settings.message_dissolve_ms < settings.message_fall_ms);
- try std.testing.expect(settings.message_fall_ms >= 150 and settings.message_fall_ms <= 220);
- try std.testing.expect(settings.message_dissolve_ms >= 100 and settings.message_dissolve_ms <= 160);
+ try std.testing.expectEqual(@as(usize, 0), pane.msg_len);
}