summaryrefslogtreecommitdiff
path: root/src/draw.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 11:34:44 -0300
committerGabriel Schneider <[email protected]>2026-11-05 15:15:07 -0300
commit2bd4066a932ec8fc401e4b85e9f8441b17df3cfb (patch)
tree024f6180ed665fbe821e4a4a46e54551e6a0b31e /src/draw.zig
parent7ec1181244c039db72986eec46f21a9d5ac2e171 (diff)
downloadpardes-2bd4066a932ec8fc401e4b85e9f8441b17df3cfb.tar.gz
pardes-2bd4066a932ec8fc401e4b85e9f8441b17df3cfb.zip
effects out, Lift and InactiveDim: the core's per-pane lift springs (Pardes.lifts, lift_serials, Region.lift, Chrome.lift_style) and the unfocused panes' recede (draw.zig's dim, its contrast memo and linear blend) go with the words, their settings and tests; the window loses its soft shadows (addSoft, the lift and rim casting, the shadow a sliding pane cast, the contrast ceilings, decor.frag's Gaussian path) and Chrome.sel_fg and sel_bg, which only the ceilings read; a pane closed mid-lift left its spring unsettled and continuous() true for ever, so a window could never go idle (monkey-gui failed `never settled` in the Lift combinations, and passes now); GUI golden 18-mid-transition changes, its sliding pane casting no shadow (the scene leaves with the transitions); root_ctl's out-of-range case is SearchRows', settings' GUI-only case GripWidth's, the window monkey loses its Lift axis
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/draw.zig')
-rw-r--r--src/draw.zig443
1 files changed, 1 insertions, 442 deletions
diff --git a/src/draw.zig b/src/draw.zig
index 68e1fb41..2ddb8faf 100644
--- a/src/draw.zig
+++ b/src/draw.zig
@@ -119,29 +119,6 @@ pub fn place(p: *Pardes, s: *Surface) void {
s.addRegion(.{ .kind = .workspace_tag, .rect = .{ .x = 0, .y = 0, .w = s.cols, .h = p.topBarHeight() } });
// A column carried to the window's right edge shows where it lands as a
// rail in the last cell: the layers under it stop a cell short.
- // Lift: the focused pane rises, the others settle back, each on its
- // spring; a notice floats while Lift is on.
- const lift = liftStyle(p);
- for (&p.panes, &p.lifts, &p.lift_serials, 0..) |slot, *spring, *serial, id| {
- const pane = slot orelse continue;
- if (serial.* != pane.serial) {
- serial.* = pane.serial;
- spring.* = .{};
- }
- // How focused it is, which both a lift and a dim follow: at this
- // frame's own time, not the stepped animations' 16 ms grid. A grid
- // snaps (it has no in-between), and so does nothing that shows it.
- const shown = lift != .off or inactiveDim(p) != 0;
- const motion = animation.Motion.of(if (shown and builtins.frontend.lift) p.settings.motion else .off);
- // A flavour exaggerates what is only a few pixels (Motion.gain).
- spring.retarget(if (id == p.active) animation.Motion.of(p.settings.motion).gain else 0, p.now_ns, motion);
- _ = spring.step(p.now_ns);
- }
- for (s.regions[0..s.nregions]) |*region| switch (region.kind) {
- .grip, .tag, .body, .rail => region.lift = if (lift != .off) std.math.clamp(p.lifts[region.owner].value(p.now_ns), -1, 2) else 0,
- .notice => region.lift = if (lift != .off) 1 else 0,
- else => {},
- };
if (p.drag == .column_move) rail: {
const d = p.drag.column_move;
const source = layout.columnBySerial(p, d.serial) orelse break :rail;
@@ -345,154 +322,6 @@ fn paneFrame(s: *const Surface, serial: u32, rect: Rect) PaneFrame {
return .{ .to = still, .at = still };
}
-/// The Lift style as drawn: `auto` is a shadow on a light page, and on a
-/// dark one, where a shadow has nothing to darken, no lift at all (the other
-/// panes recede instead, `inactiveDim`).
-pub fn liftStyle(p: *const Pardes) config.Runtime.LiftStyle {
- return switch (p.settings.lift) {
- .auto => if (darkPage(p)) .off else .shadow,
- else => |style| style,
- };
-}
-
-/// How far, in percent, the unfocused panes' text fades toward its ground:
-/// InactiveDim, or under `Lift auto` on a dark page `auto_dim` while that
-/// is unset.
-fn inactiveDim(p: *const Pardes) u8 {
- if (p.settings.inactive_dim != 0) return p.settings.inactive_dim;
- return if (p.settings.lift == .auto and darkPage(p)) config.Runtime.auto_dim else 0;
-}
-
-fn darkPage(p: *const Pardes) bool {
- return if (p.theme().bg) |bg| colors.relativeLuminance(bg) < 0.18 else true;
-}
-
-/// Pane `id`'s text, `amount` (0 to 1) of the way to its ground, on the grid
-/// and on every layer of it: its tag, its body, its notices. Its grip keeps
-/// its colour, which already says it is not the focused one. The focused
-/// pane, still brightening, is faded in its body's text alone: its tag and
-/// a selection are focus indicators, which no effect may alter.
-fn recede(p: *Pardes, s: *Surface, id: usize, amount: f32, focused: bool) void {
- const th = p.theme();
- const chrome = p.chromeTheme();
- const r = p.rects[id];
- const palette = th.palette;
- var memo: Memo = .{};
- const text_x = r.x + @min(config.GUTTER, r.w);
- var row = r.y;
- while (row < @min(@as(u32, r.y) + r.h, s.rows)) : (row += 1) {
- var col = text_x;
- while (col < @min(@as(u32, r.x) + r.w, s.cols)) : (col += 1) {
- const cell = s.at(col, row);
- if (cell.default) continue;
- const tagline_role = cell.style.font_role == .tagline;
- if (focused and (tagline_role or selected(cell, th.sel_bg))) continue;
- fadeStyle(&cell.style, if (tagline_role) chrome.tag_fg else th.fg, if (tagline_role) chrome.tag_bg else th.bg, palette, amount, &memo);
- }
- }
- const body = &s.body_layers[id];
- if (body.rows != 0) for (body.cells[0 .. @as(usize, body.cols) * body.rows]) |*cell| {
- if (!(focused and selected(cell, th.sel_bg))) fadeStyle(&cell.style, th.fg, th.bg, palette, amount, &memo);
- };
- if (focused) return;
- const tag = &s.tag_layers[id];
- if (tag.rows != 0) for (tag.cells[0 .. @as(usize, tag.cols) * tag.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, tag.bg, palette, amount, &memo);
- for (0..Pane.Notices.max) |i| {
- const notice = &s.tag_layers[NOTICE_LAYER_BASE + id * Pane.Notices.max + i];
- if (notice.rows != 0) for (notice.cells[0 .. @as(usize, notice.cols) * notice.rows]) |*cell| fadeStyle(&cell.style, chrome.tag_fg, notice.bg, palette, amount, &memo);
- }
-}
-
-fn selected(cell: *const Cell, sel_bg: [3]u8) bool {
- return switch (cell.style.bg) {
- .rgb => |rgb| std.mem.eql(u8, &rgb, &sel_bg),
- else => false,
- };
-}
-
-/// The few ink and paper pairs a pane has, each faded once a frame.
-const Memo = struct {
- keys: [32]?[6]u8 = @splat(null),
- values: [32][3]u8 = undefined,
-
- fn faded(memo: *Memo, ink: [3]u8, paper: [3]u8, amount: f32) [3]u8 {
- const key = ink ++ paper;
- const slot = (@as(usize, ink[0]) *% 31 +% ink[1] *% 7 +% ink[2] +% @as(usize, paper[0]) *% 13 +% paper[1] *% 3 +% paper[2]) % memo.keys.len;
- if (memo.keys[slot]) |held| if (std.mem.eql(u8, &held, &key)) return memo.values[slot];
- // Contrast falls as the ink nears its paper: the most of `amount`
- // that keeps the pair at its own contrast or 4.5, whichever is lower.
- const floor = @min(colors.contrast(ink, paper), 4.5);
- var t = amount;
- if (colors.contrast(blend(ink, paper, t), paper) < floor) {
- var lo: f32 = 0;
- var hi: f32 = t;
- for (0..8) |_| {
- const mid = (lo + hi) / 2;
- if (colors.contrast(blend(ink, paper, mid), paper) >= floor) lo = mid else hi = mid;
- }
- t = lo;
- }
- memo.keys[slot] = key;
- memo.values[slot] = blend(ink, paper, t);
- return memo.values[slot];
- }
-};
-
-/// A cell's ink blended `amount` of the way toward its paper, never below
-/// the pair's own contrast or 4.5, whichever is lower (docs/effects.md):
-/// faint resolved first, reverse honoured, as InactiveDim always did.
-fn fadeStyle(style: *CellStyle, default_fg: ?[3]u8, default_bg: ?[3]u8, palette: ?[16][3]u8, amount: f32, memo: *Memo) void {
- if (style.invisible) return;
- var fg = resolved(style.fg, default_fg, palette) orelse return;
- const bg = resolved(style.bg, default_bg, palette) orelse return;
- if (style.dim) for (&fg) |*channel| {
- channel.* = @intCast(@as(u16, channel.*) * 6 / 10);
- };
- const ink = if (style.reverse) bg else fg;
- const paper = if (style.reverse) fg else bg;
- const rgb = memo.faded(ink, paper, amount);
- if (style.reverse) {
- style.bg = .{ .rgb = rgb };
- if (style.dim) style.fg = .{ .rgb = fg };
- } else style.fg = .{ .rgb = rgb };
- style.dim = false;
-}
-
-/// `t` of the way from one colour to the other in linear light (ยง8.2), so a
-/// coloured ink does not muddy on its way to the paper.
-fn blend(from: [3]u8, to: [3]u8, t: f32) [3]u8 {
- var out: [3]u8 = undefined;
- for (&out, from, to) |*o, a, b| {
- const l = colors.to_linear[a] * (1 - t) + colors.to_linear[b] * t;
- o.* = encoded[@intFromFloat(@round(std.math.clamp(l, 0, 1) * (encoded.len - 1)))];
- }
- return out;
-}
-
-/// Linear light back to an sRGB channel, in 4096 steps.
-const encoded: [4096]u8 = blk: {
- @setEvalBranchQuota(1_000_000);
- var table: [4096]u8 = undefined;
- for (&table, 0..) |*out, i| {
- const l = @as(f64, @floatFromInt(i)) / 4095;
- const c = if (l <= 0.0031308) l * 12.92 else 1.055 * std.math.pow(f64, l, 1.0 / 2.4) - 0.055;
- out.* = @intFromFloat(@round(c * 255));
- }
- break :blk table;
-};
-
-fn resolved(color: Color, default: ?[3]u8, palette: ?[16][3]u8) ?[3]u8 {
- return switch (color) {
- .rgb => |rgb| rgb,
- .default => default,
- // A theme's own sixteen, as the painters give them (Terminal.palColor).
- .index => |index| if (palette != null and index < 16) palette.?[index] else blk: {
- const rgb = @import("ghostty-vt").color.default[index];
- break :blk .{ rgb.r, rgb.g, rgb.b };
- },
- };
-}
-
pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
const taped = pardes.tape.enter(p, .render);
defer pardes.tape.leave(p, taped);
@@ -546,9 +375,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
.scroll_thumb = chrome.scroll_thumb,
.match_tick = chrome.search_bg,
.match_current = p.theme().fg orelse chrome.tag_fg,
- .sel_fg = p.theme().sel_fg,
- .sel_bg = p.theme().sel_bg,
- .lift_style = @backingInt(liftStyle(p)),
.rule_px = p.theme().rule_px orelse 2,
.grip_border = boxBorder(p),
.grip_focus_ring = chrome.box,
@@ -590,16 +416,6 @@ pub fn render(p: *Pardes, arena: std.mem.Allocator) !*Surface {
if (region.kind == .notice) try joinNotice(p, s, arena, region);
}
- // Both ways on the same spring: the pane focus leaves dims as the one
- // it reaches brightens, so a focus change never pops (Motion off snaps
- // both).
- for (p.panes, p.lifts, 0..) |slot, spring, id| {
- if (slot == null) continue;
- const focus = spring.value(p.now_ns) / animation.Motion.of(p.settings.motion).gain;
- const amount = @as(f32, @floatFromInt(inactiveDim(p))) / 100 * std.math.clamp(1 - focus, 0, 1);
- if (amount > 0.001) recede(p, s, id, amount, id == p.active);
- }
-
try paintHeaders(p, s);
switch (p.drag) {
@@ -1696,167 +1512,7 @@ test "a notice wider than its band, as a shader's compile error is, draws its en
}
}
-test "a lift is sampled at each frame's own time, and asks for frames only while it moves" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
- defer p.deinit();
- // A grid has no in-between: there a lift snaps.
- if (!builtins.frontend.lift) return error.SkipZigTest;
- _ = try p.setTestFile("text\n");
- p.newScratchBelow(0);
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- const ms = std.time.ns_per_ms;
- p.settings.lift = .shadow;
- p.advance(1000 * ms);
- _ = try p.render(arena.allocator());
- p.advance(3000 * ms);
- _ = arena.reset(.retain_capacity);
- _ = try p.render(arena.allocator());
- try std.testing.expect(!p.continuous());
- p.active = 0;
- var lifts: [3]f32 = undefined;
- // 144 Hz: 6.9 ms apart, none of them on a 16 ms step of its own.
- for (&lifts, 0..) |*lift, i| {
- p.advance(3000 * ms + @as(u64, @intCast(i)) * 6_944_444);
- _ = arena.reset(.retain_capacity);
- const s = try p.render(arena.allocator());
- lift.* = for (s.regionList()) |region| {
- if (region.kind == .grip and region.owner == p.active) break region.lift;
- } else return error.TestExpectedGrip;
- try std.testing.expect(p.continuous());
- }
- try std.testing.expect(lifts[0] < lifts[1] and lifts[1] < lifts[2]);
- // Settled, it is exactly up, and the core is idle again.
- p.advance(5000 * ms);
- _ = arena.reset(.retain_capacity);
- _ = try p.render(arena.allocator());
- try std.testing.expect(!p.continuous());
- try std.testing.expectEqual(@as(?u64, null), p.nextWake());
-}
-
-/// The contrast a pane's first body glyph `g` is drawn at, on the grid.
-fn glyphContrast(p: *Pardes, s: *Surface, id: usize, g: u8) f32 {
- const r = p.rects[id];
- const th = p.theme();
- var row = p.bodyTop(p.panes[id].?, r);
- while (row < r.y + r.h) : (row += 1) {
- var col = r.x + config.GUTTER;
- while (col < r.x + r.w) : (col += 1) {
- const cell = s.at(col, row);
- if (cell.default or cell.len != 1 or cell.text[0] != g) continue;
- var fg = resolved(cell.style.fg, th.fg orelse .{ 255, 255, 255 }, th.palette).?;
- const bg = resolved(cell.style.bg, th.bg orelse .{ 0, 0, 0 }, th.palette).?;
- if (cell.style.dim) for (&fg) |*channel| {
- channel.* = @intCast(@as(u16, channel.*) * 6 / 10);
- };
- return colors.contrast(fg, bg);
- }
- }
- unreachable;
-}
-
-test "a focused pane's text is never at less contrast than an unfocused one's, in any Lift, dim or theme" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
- defer p.deinit();
- _ = try p.setTestFile("text\n");
- p.newScratchBelow(0);
- p.animate_theme_changes = false;
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- const s_ns = std.time.ns_per_s;
- var now: u64 = s_ns;
- for (0..pardes.themes.len) |theme| {
- colors.setThemeIndex(p, theme);
- for (std.enums.values(config.Runtime.LiftStyle)) |style| for ([_]u8{ 0, 100 }) |dim| {
- p.settings.lift = style;
- p.settings.inactive_dim = dim;
- var seen: [2]f32 = undefined;
- for (&seen, [_]usize{ 0, 1 }) |*c, focus| {
- p.active = focus;
- _ = arena.reset(.retain_capacity);
- _ = try p.render(arena.allocator());
- now += 2 * s_ns;
- p.advance(now);
- _ = arena.reset(.retain_capacity);
- c.* = glyphContrast(p, try p.render(arena.allocator()), 0, 't');
- }
- try std.testing.expect(seen[0] >= seen[1] - 1e-3);
- // And the unfocused one is still legible.
- try std.testing.expect(seen[1] >= @min(seen[0], 4.5) - 2e-2);
- };
- }
-}
-
-test "a dim leaves the focused pane's tag, grip and cells exactly as they were" {
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
- defer p.deinit();
- _ = try p.setTestFile("text\n");
- p.newScratchBelow(0);
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- p.active = 0;
- p.advance(std.time.ns_per_s);
- const plain = try p.render(arena.allocator());
- const r = p.rects[0];
- var before: std.ArrayList(Cell) = .empty;
- defer before.deinit(std.testing.allocator);
- for (r.y..r.y + r.h) |row| try before.appendSlice(std.testing.allocator, plain.cells[row * plain.cols + r.x ..][0..r.w]);
- const tag_bg = plain.tag_layers[0].bg;
- const tag_cells = try std.testing.allocator.dupe(Cell, plain.tag_layers[0].cells[0 .. @as(usize, plain.tag_layers[0].cols) * plain.tag_layers[0].rows]);
- defer std.testing.allocator.free(tag_cells);
- p.settings.inactive_dim = 100;
- p.advance(3 * std.time.ns_per_s);
- const dimmed = try p.render(arena.allocator());
- var i: usize = 0;
- for (r.y..r.y + r.h) |row| for (dimmed.cells[row * dimmed.cols + r.x ..][0..r.w]) |cell| {
- try std.testing.expect(cell.visuallyEqual(&before.items[i]));
- i += 1;
- };
- try std.testing.expectEqual(tag_bg, dimmed.tag_layers[0].bg);
- for (tag_cells, dimmed.tag_layers[0].cells[0..tag_cells.len]) |a, b| try std.testing.expect(a.visuallyEqual(&b));
-}
-
-test "a dim never takes a pair below its own contrast or 4.5" {
- for (pardes.themes) |theme| {
- const fg = theme.fg orelse continue;
- const bg = theme.bg orelse continue;
- for ([_]bool{ false, true }) |reverse| for ([_]bool{ false, true }) |faint| {
- var style: CellStyle = .{ .fg = .{ .rgb = fg }, .bg = .{ .rgb = bg }, .reverse = reverse, .dim = faint };
- var ink = fg;
- if (faint) for (&ink) |*channel| {
- channel.* = @intCast(@as(u16, channel.*) * 6 / 10);
- };
- var memo: Memo = .{};
- fadeStyle(&style, null, null, null, 1, &memo);
- const after = colors.contrast(style.fg.rgb, style.bg.rgb);
- try std.testing.expect(after >= @min(colors.contrast(ink, bg), 4.5) - 2e-2);
- };
- }
-}
-
-test "a dim leaves a pair already under 4.5 alone, and reads a theme's own sixteen" {
- var memo: Memo = .{};
- var low: CellStyle = .{ .fg = .{ .rgb = .{ 0x80, 0x80, 0x80 } }, .bg = .{ .rgb = .{ 0x60, 0x60, 0x60 } } };
- fadeStyle(&low, null, null, null, 1, &memo);
- try std.testing.expectEqual([3]u8{ 0x80, 0x80, 0x80 }, low.fg.rgb);
- // acme's bright white is black: faded, it stays a grey, never a white.
- const acme = for (pardes.themes) |theme| {
- if (std.mem.eql(u8, theme.name, "acme")) break theme;
- } else unreachable;
- var bright: CellStyle = .{ .fg = .{ .index = 15 } };
- memo = .{};
- fadeStyle(&bright, acme.fg, acme.bg, acme.palette, 0.3, &memo);
- const rgb = bright.fg.rgb;
- try std.testing.expect(rgb[0] == rgb[1] and rgb[0] < 0xc0);
- // Reverse: the paper moves, the ink stays.
- var reverse: CellStyle = .{ .fg = .{ .rgb = .{ 0, 0, 0 } }, .bg = .{ .rgb = .{ 255, 255, 255 } }, .reverse = true };
- memo = .{};
- fadeStyle(&reverse, null, null, null, 0.3, &memo);
- try std.testing.expectEqual([3]u8{ 0, 0, 0 }, reverse.fg.rgb);
- try std.testing.expect(reverse.bg.rgb[0] < 255);
-}
-
-test "with no lift, no dim and no motion a focus switch asks for no frames" {
+test "with no motion a focus switch asks for no frames" {
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
defer p.deinit();
_ = try p.setTestFile("text\n");
@@ -1873,46 +1529,6 @@ test "with no lift, no dim and no motion a focus switch asks for no frames" {
try std.testing.expect(!p.continuous());
}
-test "each Motion flavour reaches the lift as its own trajectory" {
- // A grid snaps; the flavours are a pixel shell's.
- if (!builtins.frontend.lift) return error.SkipZigTest;
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
- defer p.deinit();
- _ = try p.setTestFile("text\n");
- p.newScratchBelow(0);
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- p.settings.lift = .shadow;
- var peaks: [5]f32 = undefined;
- const ms = std.time.ns_per_ms;
- var start: u64 = std.time.ns_per_s;
- for (std.enums.values(animation.Motion.Flavour), &peaks) |flavour, *peak| {
- p.settings.motion = flavour;
- p.active = 1;
- p.advance(start);
- _ = arena.reset(.retain_capacity);
- _ = try p.render(arena.allocator());
- start += 3 * std.time.ns_per_s;
- p.advance(start);
- _ = try p.render(arena.allocator());
- p.active = 0;
- peak.* = 0;
- var t: u64 = 0;
- while (t <= 1500 * ms) : (t += 4 * ms) {
- p.advance(start + t);
- _ = arena.reset(.retain_capacity);
- const s = try p.render(arena.allocator());
- const lift = for (s.regionList()) |region| {
- if (region.kind == .grip and region.owner == 0) break region.lift;
- } else unreachable;
- peak.* = @max(peak.*, lift);
- }
- start += 3 * std.time.ns_per_s;
- }
- // Bouncy and playful pass their (exaggerated) mark; smooth never does.
- try std.testing.expect(peaks[2] <= 1.001 and peaks[3] > 1.25 and peaks[4] > peaks[3]);
-}
-
test "the caret is its own body: a page leaves it still under the moving text, a wheel scroll lands its springs on its line's new row" {
if (!builtins.frontend.lift) return error.SkipZigTest;
const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 30 });
@@ -2386,60 +2002,3 @@ test "focus moving to a pane with no cursor while the cursor glides lets the ses
_ = try p.render(arena.allocator());
try std.testing.expect(!p.cursor_glide.moving() and !p.continuous());
}
-
-test "a pane focus reaches brightens on the same spring the one it leaves dims on, and Motion off snaps" {
- if (!builtins.frontend.lift) return error.SkipZigTest;
- const p = try Pardes.init(std.testing.allocator, .{ .cols = 80, .rows = 24 });
- defer p.deinit();
- _ = try p.setTestFile(std.mem.asBytes(&@as([4][20]u8, @splat("some text on a line\n".*))));
- p.newScratchBelow(0);
- p.settings.inactive_dim = 40;
- p.settings.motion = .smooth;
- var arena: std.heap.ArenaAllocator = .init(std.testing.allocator);
- defer arena.deinit();
- const ink = struct {
- // The file's first glyph's ink, in whichever form its body has.
- fn of(s: *const Surface) [3]u8 {
- const body = &s.body_layers[0];
- const cells = if (body.rows != 0) body.cells[0 .. @as(usize, body.cols) * body.rows] else s.cells;
- for (cells) |cell| if (!cell.default and cell.len == 1 and cell.text[0] == 's' and cell.style.font_role == .body) return switch (cell.style.fg) {
- .rgb => |rgb| rgb,
- else => .{ 0, 0, 0 },
- };
- return .{ 0, 0, 0 };
- }
- }.of;
- p.active = 1;
- p.advance(std.time.ns_per_s);
- _ = try p.render(arena.allocator());
- p.advance(3 * std.time.ns_per_s);
- _ = arena.reset(.retain_capacity);
- const dimmed = ink(try p.render(arena.allocator()));
- p.active = 0;
- var now: u64 = 3 * std.time.ns_per_s;
- var last = dimmed[0];
- var steps: usize = 0;
- for (0..30) |_| {
- now += 16 * std.time.ns_per_ms;
- p.advance(now);
- _ = arena.reset(.retain_capacity);
- const at = ink(try p.render(arena.allocator()))[0];
- // Brighter frame by frame (a flavour may pass it a little), never
- // the whole way (46 levels here) at once.
- try std.testing.expect(@abs(@as(i32, at) - @as(i32, last)) <= 12);
- if (at != last) steps += 1;
- last = at;
- }
- try std.testing.expect(steps >= 4);
- p.advance(now + 2 * std.time.ns_per_s);
- _ = arena.reset(.retain_capacity);
- const bright = ink(try p.render(arena.allocator()));
- try std.testing.expect(bright[0] > dimmed[0]);
-
- // Motion off: both snap.
- p.settings.motion = .off;
- p.active = 1;
- p.advance(now + 3 * std.time.ns_per_s);
- _ = arena.reset(.retain_capacity);
- try std.testing.expectEqualSlices(u8, &dimmed, &ink(try p.render(arena.allocator())));
-}