summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/glide.zig121
-rw-r--r--src/tui/panel_compositor.zig526
-rw-r--r--src/tui/tui.zig348
3 files changed, 511 insertions, 484 deletions
diff --git a/src/glide.zig b/src/glide.zig
index 1605b2d3..ced0ca85 100644
--- a/src/glide.zig
+++ b/src/glide.zig
@@ -1,6 +1,6 @@
//! The view's glide (G6, anim 3, 9, 12): the text's picture following
//! its core's rows, one system on every shell. The GUI draws it at the
-//! pixel; the tty at whole rows (`shifted`).
+//! pixel; the tty at whole rows (panel_compositor.glideRows).
const std = @import("std");
const pardes = @import("pardes.zig");
@@ -282,44 +282,6 @@ pub const Glide = struct {
}
};
-/// The tty's picture of the glide (anim 12): the body's rows moved by the
-/// offset rounded to whole rows (the position rounded, never the step, so
-/// a slowing glide's steps come further apart), the rows that left in the
-/// gap it opens, and a caret whose line rode the scroll carried with it.
-/// `surface` itself while nothing is shifted.
-pub fn shifted(glide: *const Glide, arena: std.mem.Allocator, surface: *pardes.Surface) !*pardes.Surface {
- for (surface.panelTracks()) |track|
- if (track.active() and track.pane == glide.pane) return surface;
- const k: i32 = @intFromFloat(@round(glide.follow.offset));
- const w = glide.bw();
- const h = glide.body_h;
- const x0 = glide.rect.x + config.GUTTER;
- const y0 = glide.body_y;
- if (k == 0 or w == 0 or h == 0 or x0 + w > surface.cols or y0 + h > surface.rows) return surface;
- const out = try arena.create(pardes.Surface);
- out.* = surface.*;
- out.cells = try arena.dupe(pardes.Cell, surface.cells);
- const cols: usize = surface.cols;
- for (0..h) |r| {
- const from = @as(i32, @intCast(r)) + k;
- const to = out.cells[(y0 + r) * cols + x0 ..][0..w];
- const kept: ?[]const pardes.Cell = if (from >= 0 and from < h)
- surface.cells[(y0 + @as(usize, @intCast(from))) * cols + x0 ..][0..w]
- else if (from < 0 and -from - 1 < glide.nabove)
- glide.above[@as(usize, @intCast(-from - 1)) * w ..][0..w]
- else if (from >= h and from - h < glide.nbelow)
- glide.below[@as(usize, @intCast(from - h)) * w ..][0..w]
- else
- null;
- if (kept) |cells| @memcpy(to, cells) else @memset(to, .{});
- }
- if (out.cursor) |*c| if (glide.caret_rides and c.x >= x0 and c.x < x0 + w and c.y >= y0 and c.y < y0 + h) {
- const y = @as(i32, c.y) - k;
- if (y >= y0 and y < y0 + h) c.y = @intCast(y) else out.cursor = null;
- };
- return out;
-}
-
pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool {
for (a, b) |x, y| {
if (x.default != y.default) return false;
@@ -328,84 +290,3 @@ pub fn sameRow(a: []const pardes.Cell, b: []const pardes.Cell) bool {
}
return true;
}
-
-
-test "the tty draws a glide at whole rows: once a flick or a spin slows, its steps a tick never grow and its one-row steps come further apart, to where the core is" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 30, .tty_only = true });
- defer core.deinit();
- var text: std.ArrayList(u8) = .empty;
- defer text.deinit(gpa);
- for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i});
- _ = try core.setTestFile(text.items);
- core.settings.motion = .smooth;
- var arena: std.heap.ArenaAllocator = .init(gpa);
- defer arena.deinit();
- var glide: Glide = .{};
- defer glide.deinit(gpa);
- var now: u64 = std.time.ns_per_s;
- // One tick of the tty: its loop step, the frame, the picture.
- const tick = struct {
- fn f(c: *pardes.Pardes, g: *Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 {
- c.advance(t);
- g.step(c, std.testing.allocator, null, null);
- _ = a.reset(.retain_capacity);
- const s = try c.render(a.allocator());
- if (g.pending) g.measure(std.testing.allocator, s);
- if (g.moving()) g.advance(t, g.motion);
- _ = try shifted(g, a.allocator(), s);
- return @intFromFloat(@round(g.follow.offset));
- }
- }.f;
- _ = try tick(core, &glide, &arena, now);
- for ([_]usize{ 4, 24 }) |notches| {
- for (0..notches) |i| {
- core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } });
- if (i % 2 == 1) {
- now += pardes.animation.frame_ns;
- _ = try tick(core, &glide, &arena, now);
- }
- }
- var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns);
- now += pardes.animation.frame_ns;
- var last_step: i32 = std.math.maxInt(i32);
- var last_gap: usize = 0;
- var since: usize = 0;
- var ticks: usize = 0;
- while (glide.moving()) : (ticks += 1) {
- try std.testing.expect(ticks < 200);
- now += pardes.animation.frame_ns;
- const k = try tick(core, &glide, &arena, now);
- const step = k - drawn;
- drawn = k;
- since += 1;
- if (step == 0) continue;
- // Toward the core, never past it, each step no longer than the last.
- try std.testing.expect(step > 0 and k <= 0);
- try std.testing.expect(step <= last_step);
- if (step == 1 and last_step == 1) try std.testing.expect(since >= last_gap);
- if (step == 1) last_gap = since;
- last_step = step;
- since = 0;
- }
- try std.testing.expectEqual(@as(i32, 0), drawn);
- }
- // j held on the bottom row: the text glides a row a key under a caret
- // that stays on its cell (it does not ride: its row is kept).
- const keys = struct {
- fn j(c: *pardes.Pardes) void {
- c.update(.{ .key = .{ .cp = 'j', .text = "j" } });
- }
- };
- for (0..40) |_| keys.j(core);
- now += std.time.ns_per_s;
- _ = try tick(core, &glide, &arena, now);
- const row = (core.surface.cursor orelse return error.NoCursor).y;
- for (0..20) |i| {
- if (i % 2 == 0) keys.j(core);
- now += pardes.animation.frame_ns;
- _ = try tick(core, &glide, &arena, now);
- const out = try shifted(&glide, arena.allocator(), &core.surface);
- try std.testing.expectEqual(row, (out.cursor orelse return error.NoCursor).y);
- }
-}
diff --git a/src/tui/panel_compositor.zig b/src/tui/panel_compositor.zig
index 476a21c8..0375ffef 100644
--- a/src/tui/panel_compositor.zig
+++ b/src/tui/panel_compositor.zig
@@ -12,6 +12,30 @@ const animation = @import("../animation.zig");
const Box = animation.Box;
const Track = animation.Track;
+const Glide = pardes.glide.Glide;
+
+/// What the tty draws this frame: the canonical surface until a pass
+/// changes a cell or the cursor, then the one copy of it the first such
+/// pass makes (`own`), which every later pass changes in place.
+pub const Frame = struct {
+ arena: std.mem.Allocator,
+ canonical: *const pardes.Surface,
+ copy: ?*pardes.Surface = null,
+
+ pub fn shown(f: *const Frame) *const pardes.Surface {
+ return f.copy orelse f.canonical;
+ }
+
+ /// The copy, made at the first call.
+ pub fn own(f: *Frame) !*pardes.Surface {
+ if (f.copy) |c| return c;
+ const c = try f.arena.create(pardes.Surface);
+ c.* = f.canonical.*;
+ c.cells = try f.arena.dupe(pardes.Cell, f.canonical.cells);
+ f.copy = c;
+ return c;
+ }
+};
/// Kitty placements cannot be resampled through the character-grid transform.
/// Keep their transmitted pixels cached, but omit the placement while its pane
@@ -29,16 +53,12 @@ pub fn hidesAttachment(tracks: []const Track, serial: u32) bool {
return false;
}
-/// Return `source` unchanged when idle, otherwise an arena-owned Surface whose
-/// cells contain this frame's TTY presentation. Geometry exposed by a moving
-/// panel uses the theme's page background when it has one; null deliberately
-/// leaves the host terminal's default background showing.
-pub fn compose(
- arena: std.mem.Allocator,
- source: *pardes.Surface,
- tracks: []const Track,
- theme_bg: ?[3]u8,
-) !*pardes.Surface {
+/// This frame's TTY presentation of the panel tracks, drawn on the frame's
+/// copy (the canonical surface is left as it is when idle). Geometry exposed
+/// by a moving panel uses the theme's page background when it has one; null
+/// deliberately leaves the host terminal's default background showing.
+pub fn compose(frame: *Frame, tracks: []const Track, theme_bg: ?[3]u8) !void {
+ const source = frame.canonical;
var active = false;
var noncanonical = false;
for (tracks) |track| {
@@ -46,15 +66,13 @@ pub fn compose(
active = true;
noncanonical = noncanonical or track.amount() < 1.0;
}
- if (!active) return source;
+ if (!active) return;
// Every effect's last active sample is its exact canonical endpoint. Keep
// the real cursor and attachments in that sample instead of suppressing
// them for one extra frame that is otherwise pixel-identical.
- if (!noncanonical) return source;
+ if (!noncanonical) return;
- const out = try arena.create(pardes.Surface);
- out.* = source.*;
- out.cells = try arena.dupe(pardes.Cell, source.cells);
+ const out = try frame.own();
// A cursor has no pane/phase record of its own. All native backends hide
// it for the short transition rather than disagreeing about whether it
// should move, stay static, or cover an overlapping opening pane.
@@ -95,9 +113,233 @@ pub fn compose(
}
}
}
- return out;
}
+/// The tty's picture of the glide (glide.zig, anim 12): the body's rows
+/// moved by the offset rounded to whole rows (the position rounded, never
+/// the step, so a slowing glide's steps come further apart), the rows that
+/// left in the gap it opens, and a caret whose line rode the scroll carried
+/// with it. In place: the rows are walked from the side they move toward,
+/// so each is read before a move writes over it.
+pub fn glideRows(frame: *Frame, glide: *const Glide) !void {
+ const surface = frame.shown();
+ for (surface.panelTracks()) |track|
+ if (track.active() and track.pane == glide.pane) return;
+ const k: i32 = @intFromFloat(@round(glide.follow.offset));
+ const w = glide.bw();
+ const h = glide.body_h;
+ const x0 = glide.rect.x + pardes.config.GUTTER;
+ const y0 = glide.body_y;
+ if (k == 0 or w == 0 or h == 0 or x0 + w > surface.cols or y0 + h > surface.rows) return;
+ const out = try frame.own();
+ const cols: usize = out.cols;
+ for (0..h) |i| {
+ const r = if (k > 0) i else h - 1 - i;
+ const from = @as(i32, @intCast(r)) + k;
+ const to = out.cells[(y0 + r) * cols + x0 ..][0..w];
+ const kept: ?[]const pardes.Cell = if (from >= 0 and from < h)
+ out.cells[(y0 + @as(usize, @intCast(from))) * cols + x0 ..][0..w]
+ else if (from < 0 and -from - 1 < glide.nabove)
+ glide.above[@as(usize, @intCast(-from - 1)) * w ..][0..w]
+ else if (from >= h and from - h < glide.nbelow)
+ glide.below[@as(usize, @intCast(from - h)) * w ..][0..w]
+ else
+ null;
+ if (kept) |cells| @memcpy(to, cells) else @memset(to, .{});
+ }
+ if (out.cursor) |*c| if (glide.caret_rides and c.x >= x0 and c.x < x0 + w and c.y >= y0 and c.y < y0 + h) {
+ const y = @as(i32, c.y) - k;
+ if (y >= y0 and y < y0 + h) c.y = @intCast(y) else out.cursor = null;
+ };
+}
+
+/// T1 (§9.2): each notice chip casts a shadow one cell right and one down,
+/// inside its own pane's body: its ground 35% toward black in OKLab on a
+/// cell with text; on a blank one a half block (▌ on the right, ▀ below,
+/// ▘ at the corner) in the darker colour, so the shadow is half a cell
+/// thick and reads as one. Never the cursor's cell, a selection, a tag or
+/// another chip. Truecolor terminals only.
+pub fn chipShadows(frame: *Frame, core: *pardes.Pardes, truecolor: bool) !void {
+ if (!core.settings.chip_shadow or !truecolor) return;
+ const regions = frame.shown().regionList();
+ const any = for (regions) |region| {
+ if (region.kind == .notice) break true;
+ } else false;
+ if (!any) return;
+ const out = try frame.own();
+ const theme = core.theme();
+ const page = theme.bg orelse pardes.colors.null_page;
+ for (regions) |chip| {
+ if (chip.kind != .notice or chip.rect.w == 0) continue;
+ const body = for (regions) |region| {
+ if (region.kind == .body and region.owner == chip.owner) break region.rect;
+ } else continue;
+ const right = chip.rect.x + chip.rect.w;
+ const below = chip.rect.y + chip.rect.h;
+ // The column right of it (from its second row), the row below (from
+ // its second column), and the corner.
+ var y = chip.rect.y;
+ while (y <= below) : (y += 1) {
+ var x = chip.rect.x;
+ while (x <= right) : (x += 1) {
+ const side = x == right and y > chip.rect.y and y < below;
+ const foot = y == below and x > chip.rect.x and x < right;
+ const corner = x == right and y == below;
+ if (!side and !foot and !corner) continue;
+ if (x < body.x or y < body.y or x >= body.x + body.w or y >= body.y + body.h or x >= out.cols or y >= out.rows) continue;
+ if (out.cursor) |cu| if (cu.x == x and cu.y == y) continue;
+ const covered = for (regions) |region| {
+ if ((region.kind == .notice or region.kind == .tag or region.kind == .grip) and x >= region.rect.x and x < region.rect.x + region.rect.w and y >= region.rect.y and y < region.rect.y + region.rect.h) break true;
+ } else false;
+ if (covered) continue;
+ const cell = &out.cells[@as(usize, y) * out.cols + x];
+ const ground: [3]u8 = if (cell.default) page else switch (cell.style.bg) {
+ .rgb => |rgb| rgb,
+ else => page,
+ };
+ if (std.mem.eql(u8, &ground, &theme.sel_bg)) continue;
+ const dark = pardes.colors.mixOklab(ground, .{ 0, 0, 0 }, 0.35);
+ const blank = cell.default or cell.len == 0 or (cell.len == 1 and cell.text[0] == ' ');
+ if (blank) {
+ const glyph: []const u8 = if (corner) "▘" else if (side) "▌" else "▀";
+ cell.* = .{ .default = false, .style = .{ .fg = .{ .rgb = dark }, .bg = .{ .rgb = ground } } };
+ @memcpy(cell.text[0..glyph.len], glyph);
+ cell.len = @intCast(glyph.len);
+ } else {
+ cell.default = false;
+ cell.style.bg = .{ .rgb = dark };
+ }
+ }
+ }
+ }
+}
+
+/// T7 (§9.2): a pane whose view moved (Region.line) has its scroll thumb
+/// brighten, drawn most of the way to the text's colour, and fade back
+/// over 250 ms with an ease-out: where you are in the file, as you move.
+/// The rail is chrome, not a focus indicator. Truecolor terminals only.
+pub const ThumbFlash = struct {
+ lines: [pardes.MAX_PANES]i32 = @splat(std.math.minInt(i32)),
+ since: [pardes.MAX_PANES]u64 = @splat(0),
+
+ const life_ns: u64 = 250 * std.time.ns_per_ms;
+
+ pub fn apply(flash: *ThumbFlash, frame: *Frame, core: *pardes.Pardes, truecolor: bool) !void {
+ const on = core.settings.thumb_flash and truecolor and core.settings.motion != .off;
+ const theme = core.theme();
+ const ink = theme.fg orelse .{ 0xcc, 0xcc, 0xcc };
+ const regions = frame.shown().regionList();
+ for (regions) |body| {
+ if (body.kind != .body or body.owner >= flash.lines.len) continue;
+ const id = body.owner;
+ if (flash.lines[id] != std.math.minInt(i32) and flash.lines[id] != body.line) flash.since[id] = core.now_ns;
+ flash.lines[id] = body.line;
+ const age = core.now_ns -| flash.since[id];
+ if (!on or flash.since[id] == 0 or age >= life_ns) continue;
+ const rail = for (regions) |region| {
+ if (region.kind == .rail and region.owner == id) break region;
+ } else continue;
+ if (rail.thumb_h == 0) continue;
+ const t = @as(f32, @floatFromInt(age)) / @as(f32, @floatFromInt(life_ns));
+ const strength = 0.6 * (1 - t) * (1 - t);
+ const o = try frame.own();
+ var y = rail.rect.y + rail.thumb_y;
+ while (y < rail.rect.y + rail.thumb_y + rail.thumb_h and y < o.rows) : (y += 1) {
+ var x = rail.rect.x;
+ while (x < rail.rect.x + rail.rect.w and x < o.cols) : (x += 1) {
+ const cell = &o.cells[@as(usize, y) * o.cols + x];
+ const ground: [3]u8 = switch (cell.style.bg) {
+ .rgb => |rgb| rgb,
+ else => continue,
+ };
+ if (!std.mem.eql(u8, &ground, &core.chromeTheme().scroll_thumb)) continue;
+ cell.style.bg = .{ .rgb = pardes.colors.mixOklab(ground, ink, strength) };
+ }
+ }
+ core.shell_continuous = true;
+ }
+ }
+};
+
+/// T2 (docs/render-pipeline.md §9.2): the cursor jumping three cells or
+/// more leaves a trail of three to five cells along its path, just behind
+/// it, their ground drawn toward the text's colour, most beside the
+/// cursor, all fading out over 120 ms. Truecolor terminals only; a cell a
+/// frame changes, a few bytes. Never the cursor's own cell, a selection or
+/// anything outside the focused pane's body; off with Motion off.
+pub const JumpTrail = struct {
+ last: ?[2]u16 = null,
+ from: [2]u16 = .{ 0, 0 },
+ to: [2]u16 = .{ 0, 0 },
+ start_ns: u64 = 0,
+ active: bool = false,
+
+ const life_ns: u64 = 120 * std.time.ns_per_ms;
+
+ pub fn apply(trail: *JumpTrail, frame: *Frame, core: *pardes.Pardes, truecolor: bool) !void {
+ defer core.shell_continuous = trail.active or core.shell_continuous;
+ const on = core.settings.jump_trail and truecolor and core.settings.motion != .off;
+ const cursor = frame.shown().cursor orelse {
+ trail.active = false;
+ return;
+ };
+ const here: [2]u16 = .{ cursor.x, cursor.y };
+ if (trail.last) |was| {
+ const dx = @as(i32, here[0]) - was[0];
+ const dy = @as(i32, here[1]) - was[1];
+ if (on and @max(@abs(dx), @abs(dy)) >= 3) {
+ trail.* = .{ .last = here, .from = was, .to = here, .start_ns = core.now_ns, .active = true };
+ }
+ }
+ trail.last = here;
+ if (!on or !trail.active) {
+ trail.active = false;
+ return;
+ }
+ const age = core.now_ns -| trail.start_ns;
+ if (age >= life_ns or !std.meta.eql(trail.to, here)) {
+ trail.active = false;
+ return;
+ }
+ const out = try frame.own();
+ const theme = core.theme();
+ const ink = theme.fg orelse .{ 0xcc, 0xcc, 0xcc };
+ const page = theme.bg orelse pardes.colors.null_page;
+ const body = for (out.regionList()) |region| {
+ if (region.kind == .body and region.owner == core.active) break region.rect;
+ } else return;
+ const t = @as(f32, @floatFromInt(age)) / @as(f32, @floatFromInt(life_ns));
+ const fade = (1 - t) * (1 - t);
+ const dx = @as(f32, @floatFromInt(@as(i32, trail.from[0]) - trail.to[0]));
+ const dy = @as(f32, @floatFromInt(@as(i32, trail.from[1]) - trail.to[1]));
+ const span = @max(@abs(dx), @abs(dy));
+ const n: usize = @intFromFloat(std.math.clamp(@round(span / 4), 3, 5));
+ var k: usize = 1;
+ var last_cell: ?[2]i32 = null;
+ var step: f32 = 1;
+ while (k <= n and step <= span) : (step += 1) {
+ const x: i32 = @intFromFloat(@round(@as(f32, @floatFromInt(trail.to[0])) + dx * step / span));
+ const y: i32 = @intFromFloat(@round(@as(f32, @floatFromInt(trail.to[1])) + dy * step / span));
+ if (last_cell) |seen| if (seen[0] == x and seen[1] == y) continue;
+ last_cell = .{ x, y };
+ defer k += 1;
+ if (x < body.x or y < body.y or x >= @as(i32, body.x) + body.w or y >= @as(i32, body.y) + body.h) continue;
+ const cell = &out.cells[@as(usize, @intCast(y)) * out.cols + @as(usize, @intCast(x))];
+ const ground: [3]u8 = if (cell.default) page else switch (cell.style.bg) {
+ .rgb => |rgb| rgb,
+ else => page,
+ };
+ if (std.mem.eql(u8, &ground, &theme.sel_bg)) continue;
+ const strength = 0.55 * fade * (1 - @as(f32, @floatFromInt(k - 1)) / @as(f32, @floatFromInt(n)));
+ if (strength < 0.02) continue;
+ const was_default = cell.default;
+ cell.default = false;
+ if (was_default) cell.style = .{};
+ cell.style.bg = .{ .rgb = pardes.colors.mixOklab(ground, ink, strength) };
+ }
+ }
+};
+
/// Content effects have no honest frame without the frozen old grid. In
/// production the core drops such tracks before publishing Surface; retain
/// this guard at the backend boundary so a partial/custom caller also snaps
@@ -218,6 +460,14 @@ fn clipped(box: Box, cols: u16, rows: u16) ?GridBox {
return if (area.x0 < area.x1 and area.y0 < area.y1) area else null;
}
+/// `compose` over a frame of `surface` (the tests): what the frame shows,
+/// `surface` itself when nothing was drawn (read through `at`).
+fn composed(arena: std.mem.Allocator, surface: *pardes.Surface, tracks: []const Track, theme_bg: ?[3]u8) !*pardes.Surface {
+ var frame: Frame = .{ .arena = arena, .canonical = surface };
+ try compose(&frame, tracks, theme_bg);
+ return frame.copy orelse surface;
+}
+
/// Each of `cells` a one-byte glyph of `glyphs`, in order.
fn testGlyphs(cells: []pardes.Cell, glyphs: []const u8) void {
for (cells, glyphs) |*cell, glyph| {
@@ -249,7 +499,7 @@ test "TTY consumes core-composed ASCII cells without reinterpreting glyphs" {
.from = .{ .w = 4, .h = 2 },
.to = .{ .w = 4, .h = 2 },
};
- const animated = try compose(arena.allocator(), &surface, &.{track}, null);
+ const animated = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expect(animated != &surface);
try std.testing.expectEqualStrings("X", surface.at(0, 0).grapheme());
for (animated.cells) |cell| try std.testing.expectEqualStrings("X", cell.grapheme());
@@ -277,13 +527,13 @@ test "dissolve changes only diff cells from old to new" {
.to = .{ .w = 2, .h = 1 },
};
- const first = try compose(arena.allocator(), &surface, &.{track}, null);
+ const first = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("O", first.at(0, 0).grapheme());
try std.testing.expectEqual(cells[1], first.at(1, 0).*);
_ = arena.reset(.retain_capacity);
track.frame = track.effect.frames() - 1;
- const final = try compose(arena.allocator(), &surface, &.{track}, null);
+ const final = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqual(cells[0], final.at(0, 0).*);
try std.testing.expectEqual(cells[1], final.at(1, 0).*);
}
@@ -314,7 +564,7 @@ test "TTY content effects never touch cells outside the published diff" {
.from = .{ .w = 4, .h = 1 },
.to = .{ .w = 4, .h = 1 },
};
- const animated = try compose(arena.allocator(), &surface, &.{track}, null);
+ const animated = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqual(cells[1], animated.at(1, 0).*);
try std.testing.expectEqual(cells[3], animated.at(3, 0).*);
_ = arena.reset(.retain_capacity);
@@ -340,7 +590,7 @@ test "content transition without a diff snaps to canonical surface" {
.from = .{ .y = 1, .w = 1, .h = 1 },
.to = .{ .w = 1, .h = 1 },
};
- try std.testing.expectEqual(&surface, try compose(arena.allocator(), &surface, &.{track}, null));
+ try std.testing.expectEqual(&surface, try composed(arena.allocator(), &surface, &.{track}, null));
}
}
@@ -365,7 +615,7 @@ test "exact transition endpoint preserves the canonical cursor" {
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena.deinit();
- const result = try compose(arena.allocator(), &surface, &.{track}, null);
+ const result = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqual(&surface, result);
try std.testing.expect(result.cursor != null);
}
@@ -394,7 +644,7 @@ test "vertical opening rises through a fixed old-grid clip" {
.to = target,
};
- const first = try compose(arena.allocator(), &surface, &.{track}, null);
+ const first = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("1", first.at(0, 1).grapheme());
try std.testing.expectEqualStrings("2", first.at(0, 2).grapheme());
try std.testing.expectEqualStrings("a", first.at(0, 0).grapheme());
@@ -402,7 +652,7 @@ test "vertical opening rises through a fixed old-grid clip" {
_ = arena.reset(.retain_capacity);
track.frame = 2;
- const entering = try compose(arena.allocator(), &surface, &.{track}, null);
+ const entering = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("1", entering.at(0, 1).grapheme());
try std.testing.expectEqualStrings("b", entering.at(0, 2).grapheme());
try std.testing.expectEqualStrings("a", entering.at(0, 0).grapheme());
@@ -410,7 +660,7 @@ test "vertical opening rises through a fixed old-grid clip" {
_ = arena.reset(.retain_capacity);
track.frame = track.effect.frames() - 1;
- const final = try compose(arena.allocator(), &surface, &.{track}, null);
+ const final = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("b", final.at(0, 1).grapheme());
try std.testing.expectEqualStrings("c", final.at(0, 2).grapheme());
}
@@ -439,13 +689,13 @@ test "vertical closing drops frozen content over canonical cells" {
.to = animation.closingBox(.vertical, old_box),
};
- const first = try compose(arena.allocator(), &surface, &.{track}, null);
+ const first = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("1", first.at(0, 1).grapheme());
try std.testing.expectEqualStrings("2", first.at(0, 2).grapheme());
_ = arena.reset(.retain_capacity);
track.frame = 8;
- const leaving = try compose(arena.allocator(), &surface, &.{track}, null);
+ const leaving = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqualStrings("b", leaving.at(0, 1).grapheme());
try std.testing.expectEqualStrings("1", leaving.at(0, 2).grapheme());
try std.testing.expectEqualStrings("a", leaving.at(0, 0).grapheme());
@@ -453,7 +703,7 @@ test "vertical closing drops frozen content over canonical cells" {
_ = arena.reset(.retain_capacity);
track.frame = track.effect.frames() - 1;
- const final = try compose(arena.allocator(), &surface, &.{track}, null);
+ const final = try composed(arena.allocator(), &surface, &.{track}, null);
try std.testing.expectEqual(cells[3], final.at(0, 1).*);
try std.testing.expectEqual(cells[6], final.at(0, 2).*);
}
@@ -490,7 +740,7 @@ test "closing content paints after opening content regardless of track order" {
.to = box,
};
- const animated = try compose(arena.allocator(), &surface, &.{ closing, opening }, null);
+ const animated = try composed(arena.allocator(), &surface, &.{ closing, opening }, null);
try std.testing.expectEqualStrings("O", animated.at(0, 0).grapheme());
}
@@ -516,7 +766,7 @@ test "opening panel cannot erase an existing panel drawn underneath" {
.to = .{ .x = 4, .w = 4, .h = 1 },
},
};
- const animated = try compose(arena.allocator(), &surface, &tracks, null);
+ const animated = try composed(arena.allocator(), &surface, &tracks, null);
try std.testing.expectEqualStrings("A", animated.at(7, 0).grapheme());
}
@@ -541,7 +791,7 @@ test "geometry gap is a blank painted in an explicit theme background" {
.to = .{ .w = 4, .h = 1 },
};
const page_bg = [3]u8{ 248, 244, 232 };
- const animated = try compose(arena.allocator(), &surface, &.{track}, page_bg);
+ const animated = try composed(arena.allocator(), &surface, &.{track}, page_bg);
const gap = animated.at(0, 0);
try std.testing.expect(!gap.default);
@@ -567,7 +817,7 @@ test "geometry gap stays terminal-default for a transparent theme" {
.from = .{ .x = 1, .w = 1, .h = 1 },
.to = .{ .w = 2, .h = 1 },
};
- const animated = try compose(arena.allocator(), &surface, &.{track}, null);
+ const animated = try composed(arena.allocator(), &surface, &.{track}, null);
const gap = animated.at(0, 0);
try std.testing.expect(gap.default);
@@ -587,7 +837,7 @@ test "fractional geometry draws exactly the cell centres core can hit" {
.from = .{ .x = 0.9, .w = 1, .h = 1 },
.to = .{ .x = 0, .w = 1, .h = 1 },
};
- const animated = try compose(arena.allocator(), &surface, &.{track}, null);
+ const animated = try composed(arena.allocator(), &surface, &.{track}, null);
// Cell 0 lies in floor/ceil iteration bounds, but its centre (0.5) is
// outside [0.9, 1.9); cell 1 is the only presented/hit-testable cell.
try std.testing.expectEqualStrings(" ", animated.at(0, 0).grapheme());
@@ -638,3 +888,213 @@ test "active panel transition hides only its own native attachment" {
try std.testing.expect(hidesAttachment(&tracks, 45));
try std.testing.expect(!hidesAttachment(&tracks, 46));
}
+
+test "the tty draws a glide at whole rows: once a flick or a spin slows, its steps a tick never grow and its one-row steps come further apart, to where the core is" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .cols = 80, .rows = 30, .tty_only = true });
+ defer core.deinit();
+ var text: std.ArrayList(u8) = .empty;
+ defer text.deinit(gpa);
+ for (0..3000) |i| try text.print(gpa, "{d:0>5} line\n", .{i});
+ _ = try core.setTestFile(text.items);
+ core.settings.motion = .smooth;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var glide: Glide = .{};
+ defer glide.deinit(gpa);
+ var now: u64 = std.time.ns_per_s;
+ // One tick of the tty: its loop step, the frame, the picture.
+ const tick = struct {
+ fn f(c: *pardes.Pardes, g: *Glide, a: *std.heap.ArenaAllocator, t: u64) !i32 {
+ c.advance(t);
+ g.step(c, std.testing.allocator, null, null);
+ _ = a.reset(.retain_capacity);
+ const s = try c.render(a.allocator());
+ if (g.pending) g.measure(std.testing.allocator, s);
+ if (g.moving()) g.advance(t, g.motion);
+ var frame: Frame = .{ .arena = a.allocator(), .canonical = s };
+ try glideRows(&frame, g);
+ return @intFromFloat(@round(g.follow.offset));
+ }
+ }.f;
+ _ = try tick(core, &glide, &arena, now);
+ for ([_]usize{ 4, 24 }) |notches| {
+ for (0..notches) |i| {
+ core.update(.{ .mouse = .{ .button = .wheel_down, .kind = .press, .col = 20, .row = 10 } });
+ if (i % 2 == 1) {
+ now += pardes.animation.frame_ns;
+ _ = try tick(core, &glide, &arena, now);
+ }
+ }
+ var drawn = try tick(core, &glide, &arena, now + pardes.animation.frame_ns);
+ now += pardes.animation.frame_ns;
+ var last_step: i32 = std.math.maxInt(i32);
+ var last_gap: usize = 0;
+ var since: usize = 0;
+ var ticks: usize = 0;
+ while (glide.moving()) : (ticks += 1) {
+ try std.testing.expect(ticks < 200);
+ now += pardes.animation.frame_ns;
+ const k = try tick(core, &glide, &arena, now);
+ const step = k - drawn;
+ drawn = k;
+ since += 1;
+ if (step == 0) continue;
+ // Toward the core, never past it, each step no longer than the last.
+ try std.testing.expect(step > 0 and k <= 0);
+ try std.testing.expect(step <= last_step);
+ if (step == 1 and last_step == 1) try std.testing.expect(since >= last_gap);
+ if (step == 1) last_gap = since;
+ last_step = step;
+ since = 0;
+ }
+ try std.testing.expectEqual(@as(i32, 0), drawn);
+ }
+ // j held on the bottom row: the text glides a row a key under a caret
+ // that stays on its cell (it does not ride: its row is kept).
+ const keys = struct {
+ fn j(c: *pardes.Pardes) void {
+ c.update(.{ .key = .{ .cp = 'j', .text = "j" } });
+ }
+ };
+ for (0..40) |_| keys.j(core);
+ now += std.time.ns_per_s;
+ _ = try tick(core, &glide, &arena, now);
+ const row = (core.surface.cursor orelse return error.NoCursor).y;
+ for (0..20) |i| {
+ if (i % 2 == 0) keys.j(core);
+ now += pardes.animation.frame_ns;
+ _ = try tick(core, &glide, &arena, now);
+ var frame: Frame = .{ .arena = arena.allocator(), .canonical = &core.surface };
+ try glideRows(&frame, &glide);
+ try std.testing.expectEqual(row, (frame.shown().cursor orelse return error.NoCursor).y);
+ }
+}
+
+test "a jump leaves a trail of a few cells behind the cursor that fades in 120 ms" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer core.deinit();
+ _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*))));
+ try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
+ core.settings.jump_trail = true;
+ for (0..40) |_| core.update(.tick);
+ core.sync();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const s = try core.render(arena.allocator());
+ const body = for (s.regionList()) |region| {
+ if (region.kind == .body) break region.rect;
+ } else return error.NoBody;
+ var trail: JumpTrail = .{};
+ core.now_ns = std.time.ns_per_s;
+ s.cursor = .{ .x = body.x + 2, .y = body.y + 1 };
+ var frame: Frame = .{ .arena = arena.allocator(), .canonical = s };
+ try trail.apply(&frame, core, true);
+ // Ten cells right: a trail back toward where it was.
+ s.cursor = .{ .x = body.x + 12, .y = body.y + 1 };
+ core.now_ns += 16 * std.time.ns_per_ms;
+ frame = .{ .arena = arena.allocator(), .canonical = s };
+ try trail.apply(&frame, core, true);
+ const lit = frame.shown();
+ try std.testing.expect(trail.active and core.shell_continuous);
+ var changed: usize = 0;
+ for (lit.cells, s.cells, 0..) |a, b, i| {
+ if (std.meta.eql(a.style.bg, b.style.bg)) continue;
+ changed += 1;
+ // On the cursor's row, behind it, never its own cell.
+ try std.testing.expectEqual(@as(usize, body.y + 1), i / s.cols);
+ try std.testing.expect(i % s.cols < body.x + 12 and i % s.cols > body.x + 2);
+ }
+ try std.testing.expect(changed >= 3 and changed <= 5);
+ // Gone by 120 ms; a step of a cell leaves none; nor a terminal without
+ // truecolor.
+ core.now_ns += 130 * std.time.ns_per_ms;
+ core.shell_continuous = false;
+ frame = .{ .arena = arena.allocator(), .canonical = s };
+ try trail.apply(&frame, core, true);
+ try std.testing.expect(frame.copy == null and !trail.active and !core.shell_continuous);
+ s.cursor = .{ .x = body.x + 13, .y = body.y + 1 };
+ frame = .{ .arena = arena.allocator(), .canonical = s };
+ try trail.apply(&frame, core, true);
+ try std.testing.expect(frame.copy == null);
+ s.cursor = .{ .x = body.x + 2, .y = body.y + 1 };
+ frame = .{ .arena = arena.allocator(), .canonical = s };
+ try trail.apply(&frame, core, false);
+ try std.testing.expect(frame.copy == null);
+}
+
+test "a notice chip casts a cell's shadow right and down, inside its body, off the cursor" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer core.deinit();
+ _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*))));
+ try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
+ core.settings.chip_shadow = true;
+ try std.testing.expect(core.executeBuiltinLine(0, "Msg a notice"));
+ for (0..60) |_| core.update(.tick);
+ core.sync();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const s = try core.render(arena.allocator());
+ const chip = for (s.regionList()) |region| {
+ if (region.kind == .notice) break region.rect;
+ } else return error.NoNotice;
+ s.cursor = null;
+ var frame: Frame = .{ .arena = arena.allocator(), .canonical = s };
+ try chipShadows(&frame, core, true);
+ const out = frame.copy orelse return error.NoShadow;
+ var changed: usize = 0;
+ for (out.cells, s.cells, 0..) |a, b, i| {
+ if (std.meta.eql(a, b)) continue;
+ changed += 1;
+ const x = i % s.cols;
+ const y = i / s.cols;
+ // Right of the chip or below it, never inside it.
+ try std.testing.expect(x == chip.x + chip.w or y == chip.y + chip.h);
+ try std.testing.expect(!(x >= chip.x and x < chip.x + chip.w and y >= chip.y and y < chip.y + chip.h));
+ }
+ try std.testing.expect(changed >= chip.w - 1);
+ // Off, or without truecolor: the frame as it was.
+ frame = .{ .arena = arena.allocator(), .canonical = s };
+ try chipShadows(&frame, core, false);
+ try std.testing.expect(frame.copy == null);
+ core.settings.chip_shadow = false;
+ try chipShadows(&frame, core, true);
+ try std.testing.expect(frame.copy == null);
+}
+
+test "a scrolled pane's thumb brightens and fades back in 250 ms" {
+ const gpa = std.testing.allocator;
+ const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
+ defer core.deinit();
+ const pane = try core.setTestFile(std.mem.asBytes(&@as([200][20]u8, @splat("some text on a line\n".*))));
+ try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
+ core.settings.thumb_flash = true;
+ for (0..40) |_| core.update(.tick);
+ core.sync();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var flash: ThumbFlash = .{};
+ core.now_ns = std.time.ns_per_s;
+ var frame: Frame = .{ .arena = arena.allocator(), .canonical = try core.render(arena.allocator()) };
+ try flash.apply(&frame, core, true);
+ try std.testing.expect(frame.copy == null);
+ pane.scrollBy(20);
+ core.now_ns += 16 * std.time.ns_per_ms;
+ const moved = try core.render(arena.allocator());
+ frame = .{ .arena = arena.allocator(), .canonical = moved };
+ try flash.apply(&frame, core, true);
+ const lit = frame.copy orelse return error.NoFlash;
+ try std.testing.expect(core.shell_continuous);
+ var brighter: usize = 0;
+ for (lit.cells, moved.cells) |a, b| {
+ if (!std.meta.eql(a.style.bg, b.style.bg)) brighter += 1;
+ }
+ try std.testing.expect(brighter >= 1);
+ core.now_ns += 300 * std.time.ns_per_ms;
+ core.shell_continuous = false;
+ frame = .{ .arena = arena.allocator(), .canonical = try core.render(arena.allocator()) };
+ try flash.apply(&frame, core, true);
+ try std.testing.expect(frame.copy == null and !core.shell_continuous);
+}
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index 5cf402a5..8b4de782 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -1435,11 +1435,11 @@ const Screen = struct {
size: ?vaxis.Winsize = null,
tracks: []const pardes.animation.Track = &.{},
/// T2: the cursor's jump trail (JumpTrail).
- trail: JumpTrail = .{},
+ trail: panel_compositor.JumpTrail = .{},
/// The view's glide, the GUI's motion drawn at whole rows (anim 12).
glide: pardes.glide.Glide = .{},
/// T7: when each pane's view last moved (ThumbFlash).
- flash: ThumbFlash = .{},
+ flash: panel_compositor.ThumbFlash = .{},
/// `fd` made raw, as vaxis.Tty.init makes /dev/tty: the terminal of a
/// forked session is no controlling terminal of its, which /dev/tty is.
@@ -2716,12 +2716,10 @@ const Shell = struct {
return;
}
_ = s.frame.reset(.retain_capacity);
- const surface = panel_compositor.compose(
- s.frame.allocator(),
- @constCast(canonical),
- sc.tracks,
- s.core.theme().bg,
- ) catch return;
+ // Each pass below draws on the frame's one copy of the canonical
+ // surface, made by the first that changes anything.
+ var frame: panel_compositor.Frame = .{ .arena = s.frame.allocator(), .canonical = canonical };
+ panel_compositor.compose(&frame, sc.tracks, s.core.theme().bg) catch return;
const tz_cells = tracy.zone(@src(), "surface->vaxis");
const win = vx.window();
const truecolor = vx.caps.rgb or colortermTruecolor();
@@ -2730,15 +2728,16 @@ const Shell = struct {
if (sc.glide.moving()) sc.glide.advance(s.core.now_ns, sc.glide.motion);
s.core.shell_continuous = sc.glide.moving();
s.core.frames.scroll = @round(sc.glide.follow.offset);
- const glided = pardes.glide.shifted(&sc.glide, s.frame.allocator(), surface) catch surface;
- const shadowed = chipShadows(s.frame.allocator(), glided, s.core, truecolor) catch glided;
- const flashed = sc.flash.apply(s.frame.allocator(), shadowed, s.core, truecolor) catch shadowed;
- const trailed = sc.trail.apply(s.frame.allocator(), flashed, s.core, truecolor) catch flashed;
- paintCells(win, trailed.cells, trailed.cols, trailed.rows);
- if (s.remote) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), trailed.cols, trailed.rows);
+ panel_compositor.glideRows(&frame, &sc.glide) catch {};
+ panel_compositor.chipShadows(&frame, s.core, truecolor) catch {};
+ sc.flash.apply(&frame, s.core, truecolor) catch {};
+ sc.trail.apply(&frame, s.core, truecolor) catch {};
+ const shown = frame.shown();
+ paintCells(win, shown.cells, shown.cols, shown.rows);
+ if (s.remote) |c| if (c.link.notice_len > 0) noticeLine(win, c.link.notice(), shown.cols, shown.rows);
tz_cells.end();
- for (surface.images.items) |place| {
- if (panel_compositor.hidesAttachment(surface.panelTracks(), place.serial)) continue;
+ for (canonical.images.items) |place| {
+ if (panel_compositor.hidesAttachment(canonical.panelTracks(), place.serial)) continue;
if (comptime pardes.pdf_enabled) {
if (!kittyImageRepresentable(place)) continue;
}
@@ -2812,7 +2811,7 @@ const Shell = struct {
var stale_len: usize = 0;
var image_iterator = sc.kitty.iterator();
while (image_iterator.next()) |entry| {
- if (surfaceHasKittyKey(surface, entry.key_ptr.*)) continue;
+ if (surfaceHasKittyKey(canonical, entry.key_ptr.*)) continue;
stale[stale_len] = entry.key_ptr.*;
stale_len += 1;
if (stale_len == stale.len) break;
@@ -2821,7 +2820,7 @@ const Shell = struct {
vx.freeImage(sc.tty.writer(), removed.value.id);
if (stale_len < stale.len) break;
}
- if (glided.cursor) |cur| {
+ if (shown.cursor) |cur| {
win.showCursor(cur.x, cur.y);
win.setCursorShape(if (cur.bar) .beam else .default);
}
@@ -3516,322 +3515,9 @@ test "a fade sends the text it dims, not the blanks beside it" {
try std.testing.expect(std.mem.indexOfScalar(u8, sent[1], 'a') != null);
}
-/// T1 (§9.2): each notice chip casts a shadow one cell right and one down,
-/// inside its own pane's body: its ground 35% toward black in OKLab on a
-/// cell with text; on a blank one a half block (▌ on the right, ▀ below,
-/// ▘ at the corner) in the darker colour, so the shadow is half a cell
-/// thick and reads as one. Never the cursor's cell, a selection, a tag or
-/// another chip. Truecolor terminals only.
-fn chipShadows(arena: std.mem.Allocator, surface: *pardes.Surface, core: *pardes.Pardes, truecolor: bool) !*pardes.Surface {
- if (!core.settings.chip_shadow or !truecolor) return surface;
- const regions = surface.regionList();
- const any = for (regions) |region| {
- if (region.kind == .notice) break true;
- } else false;
- if (!any) return surface;
- const out = try arena.create(pardes.Surface);
- out.* = surface.*;
- out.cells = try arena.dupe(pardes.Cell, surface.cells);
- const theme = core.theme();
- const page = theme.bg orelse pardes.colors.null_page;
- for (regions) |chip| {
- if (chip.kind != .notice or chip.rect.w == 0) continue;
- const body = for (regions) |region| {
- if (region.kind == .body and region.owner == chip.owner) break region.rect;
- } else continue;
- const right = chip.rect.x + chip.rect.w;
- const below = chip.rect.y + chip.rect.h;
- // The column right of it (from its second row), the row below (from
- // its second column), and the corner.
- var y = chip.rect.y;
- while (y <= below) : (y += 1) {
- var x = chip.rect.x;
- while (x <= right) : (x += 1) {
- const side = x == right and y > chip.rect.y and y < below;
- const foot = y == below and x > chip.rect.x and x < right;
- const corner = x == right and y == below;
- if (!side and !foot and !corner) continue;
- if (x < body.x or y < body.y or x >= body.x + body.w or y >= body.y + body.h or x >= out.cols or y >= out.rows) continue;
- if (surface.cursor) |cu| if (cu.x == x and cu.y == y) continue;
- const covered = for (regions) |region| {
- if ((region.kind == .notice or region.kind == .tag or region.kind == .grip) and x >= region.rect.x and x < region.rect.x + region.rect.w and y >= region.rect.y and y < region.rect.y + region.rect.h) break true;
- } else false;
- if (covered) continue;
- const cell = &out.cells[@as(usize, y) * out.cols + x];
- const ground: [3]u8 = if (cell.default) page else switch (cell.style.bg) {
- .rgb => |rgb| rgb,
- else => page,
- };
- if (std.mem.eql(u8, &ground, &theme.sel_bg)) continue;
- const dark = pardes.colors.mixOklab(ground, .{ 0, 0, 0 }, 0.35);
- const blank = cell.default or cell.len == 0 or (cell.len == 1 and cell.text[0] == ' ');
- if (blank) {
- const glyph: []const u8 = if (corner) "▘" else if (side) "▌" else "▀";
- cell.* = .{ .default = false, .style = .{ .fg = .{ .rgb = dark }, .bg = .{ .rgb = ground } } };
- @memcpy(cell.text[0..glyph.len], glyph);
- cell.len = @intCast(glyph.len);
- } else {
- cell.default = false;
- cell.style.bg = .{ .rgb = dark };
- }
- }
- }
- }
- return out;
-}
-
-/// T7 (§9.2): a pane whose view moved (Region.line) has its scroll thumb
-/// brighten, drawn most of the way to the text's colour, and fade back
-/// over 250 ms with an ease-out: where you are in the file, as you move.
-/// The rail is chrome, not a focus indicator. Truecolor terminals only.
-const ThumbFlash = struct {
- lines: [pardes.MAX_PANES]i32 = @splat(std.math.minInt(i32)),
- since: [pardes.MAX_PANES]u64 = @splat(0),
-
- const life_ns: u64 = 250 * std.time.ns_per_ms;
-
- fn apply(flash: *ThumbFlash, arena: std.mem.Allocator, surface: *pardes.Surface, core: *pardes.Pardes, truecolor: bool) !*pardes.Surface {
- const on = core.settings.thumb_flash and truecolor and core.settings.motion != .off;
- var out: ?*pardes.Surface = null;
- const theme = core.theme();
- const ink = theme.fg orelse .{ 0xcc, 0xcc, 0xcc };
- for (surface.regionList()) |body| {
- if (body.kind != .body or body.owner >= flash.lines.len) continue;
- const id = body.owner;
- if (flash.lines[id] != std.math.minInt(i32) and flash.lines[id] != body.line) flash.since[id] = core.now_ns;
- flash.lines[id] = body.line;
- const age = core.now_ns -| flash.since[id];
- if (!on or flash.since[id] == 0 or age >= life_ns) continue;
- const rail = for (surface.regionList()) |region| {
- if (region.kind == .rail and region.owner == id) break region;
- } else continue;
- if (rail.thumb_h == 0) continue;
- const t = @as(f32, @floatFromInt(age)) / @as(f32, @floatFromInt(life_ns));
- const strength = 0.6 * (1 - t) * (1 - t);
- if (out == null) {
- const copy = try arena.create(pardes.Surface);
- copy.* = surface.*;
- copy.cells = try arena.dupe(pardes.Cell, surface.cells);
- out = copy;
- }
- const o = out.?;
- var y = rail.rect.y + rail.thumb_y;
- while (y < rail.rect.y + rail.thumb_y + rail.thumb_h and y < o.rows) : (y += 1) {
- var x = rail.rect.x;
- while (x < rail.rect.x + rail.rect.w and x < o.cols) : (x += 1) {
- const cell = &o.cells[@as(usize, y) * o.cols + x];
- const ground: [3]u8 = switch (cell.style.bg) {
- .rgb => |rgb| rgb,
- else => continue,
- };
- if (!std.mem.eql(u8, &ground, &core.chromeTheme().scroll_thumb)) continue;
- cell.style.bg = .{ .rgb = pardes.colors.mixOklab(ground, ink, strength) };
- }
- }
- core.shell_continuous = true;
- }
- return out orelse surface;
- }
-};
-
/// Truecolor by COLORTERM (truecolor or 24bit), for a terminal that does
/// not answer vaxis's query (§9.2: vaxis caps or COLORTERM).
fn colortermTruecolor() bool {
const value = std.mem.span(std.c.getenv("COLORTERM") orelse return false);
return std.mem.eql(u8, value, "truecolor") or std.mem.eql(u8, value, "24bit");
}
-
-/// T2 (docs/render-pipeline.md §9.2): the cursor jumping three cells or
-/// more leaves a trail of three to five cells along its path, just behind
-/// it, their ground drawn toward the text's colour, most beside the
-/// cursor, all fading out over 120 ms. Truecolor terminals only; a cell a
-/// frame changes, a few bytes. Never the cursor's own cell, a selection or
-/// anything outside the focused pane's body; off with Motion off.
-const JumpTrail = struct {
- last: ?[2]u16 = null,
- from: [2]u16 = .{ 0, 0 },
- to: [2]u16 = .{ 0, 0 },
- start_ns: u64 = 0,
- active: bool = false,
-
- const life_ns: u64 = 120 * std.time.ns_per_ms;
-
- fn apply(trail: *JumpTrail, arena: std.mem.Allocator, surface: *pardes.Surface, core: *pardes.Pardes, truecolor: bool) !*pardes.Surface {
- defer core.shell_continuous = trail.active or core.shell_continuous;
- const on = core.settings.jump_trail and truecolor and core.settings.motion != .off;
- const cursor = surface.cursor orelse {
- trail.active = false;
- return surface;
- };
- const here: [2]u16 = .{ cursor.x, cursor.y };
- if (trail.last) |was| {
- const dx = @as(i32, here[0]) - was[0];
- const dy = @as(i32, here[1]) - was[1];
- if (on and @max(@abs(dx), @abs(dy)) >= 3) {
- trail.* = .{ .last = here, .from = was, .to = here, .start_ns = core.now_ns, .active = true };
- }
- }
- trail.last = here;
- if (!on or !trail.active) {
- trail.active = false;
- return surface;
- }
- const age = core.now_ns -| trail.start_ns;
- if (age >= life_ns or !std.meta.eql(trail.to, here)) {
- trail.active = false;
- return surface;
- }
- const out = try arena.create(pardes.Surface);
- out.* = surface.*;
- out.cells = try arena.dupe(pardes.Cell, surface.cells);
- const theme = core.theme();
- const ink = theme.fg orelse .{ 0xcc, 0xcc, 0xcc };
- const page = theme.bg orelse pardes.colors.null_page;
- const body = for (surface.regionList()) |region| {
- if (region.kind == .body and region.owner == core.active) break region.rect;
- } else return out;
- const t = @as(f32, @floatFromInt(age)) / @as(f32, @floatFromInt(life_ns));
- const fade = (1 - t) * (1 - t);
- const dx = @as(f32, @floatFromInt(@as(i32, trail.from[0]) - trail.to[0]));
- const dy = @as(f32, @floatFromInt(@as(i32, trail.from[1]) - trail.to[1]));
- const span = @max(@abs(dx), @abs(dy));
- const n: usize = @intFromFloat(std.math.clamp(@round(span / 4), 3, 5));
- var k: usize = 1;
- var last_cell: ?[2]i32 = null;
- var step: f32 = 1;
- while (k <= n and step <= span) : (step += 1) {
- const x: i32 = @intFromFloat(@round(@as(f32, @floatFromInt(trail.to[0])) + dx * step / span));
- const y: i32 = @intFromFloat(@round(@as(f32, @floatFromInt(trail.to[1])) + dy * step / span));
- if (last_cell) |seen| if (seen[0] == x and seen[1] == y) continue;
- last_cell = .{ x, y };
- defer k += 1;
- if (x < body.x or y < body.y or x >= @as(i32, body.x) + body.w or y >= @as(i32, body.y) + body.h) continue;
- const cell = &out.cells[@as(usize, @intCast(y)) * out.cols + @as(usize, @intCast(x))];
- const ground: [3]u8 = if (cell.default) page else switch (cell.style.bg) {
- .rgb => |rgb| rgb,
- else => page,
- };
- if (std.mem.eql(u8, &ground, &theme.sel_bg)) continue;
- const strength = 0.55 * fade * (1 - @as(f32, @floatFromInt(k - 1)) / @as(f32, @floatFromInt(n)));
- if (strength < 0.02) continue;
- const was_default = cell.default;
- cell.default = false;
- if (was_default) cell.style = .{};
- cell.style.bg = .{ .rgb = pardes.colors.mixOklab(ground, ink, strength) };
- }
- return out;
- }
-};
-
-test "a jump leaves a trail of a few cells behind the cursor that fades in 120 ms" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*))));
- try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
- core.settings.jump_trail = true;
- for (0..40) |_| core.update(.tick);
- core.sync();
- var arena: std.heap.ArenaAllocator = .init(gpa);
- defer arena.deinit();
- const s = try core.render(arena.allocator());
- const body = for (s.regionList()) |region| {
- if (region.kind == .body) break region.rect;
- } else return error.NoBody;
- var trail: JumpTrail = .{};
- core.now_ns = std.time.ns_per_s;
- s.cursor = .{ .x = body.x + 2, .y = body.y + 1 };
- _ = try trail.apply(arena.allocator(), s, core, true);
- // Ten cells right: a trail back toward where it was.
- s.cursor = .{ .x = body.x + 12, .y = body.y + 1 };
- core.now_ns += 16 * std.time.ns_per_ms;
- const lit = try trail.apply(arena.allocator(), s, core, true);
- try std.testing.expect(trail.active and core.shell_continuous);
- var changed: usize = 0;
- for (lit.cells, s.cells, 0..) |a, b, i| {
- if (std.meta.eql(a.style.bg, b.style.bg)) continue;
- changed += 1;
- // On the cursor's row, behind it, never its own cell.
- try std.testing.expectEqual(@as(usize, body.y + 1), i / s.cols);
- try std.testing.expect(i % s.cols < body.x + 12 and i % s.cols > body.x + 2);
- }
- try std.testing.expect(changed >= 3 and changed <= 5);
- // Gone by 120 ms; a step of a cell leaves none; nor a terminal without
- // truecolor.
- core.now_ns += 130 * std.time.ns_per_ms;
- core.shell_continuous = false;
- const faded = try trail.apply(arena.allocator(), s, core, true);
- try std.testing.expect(faded == s and !trail.active and !core.shell_continuous);
- s.cursor = .{ .x = body.x + 13, .y = body.y + 1 };
- try std.testing.expect(try trail.apply(arena.allocator(), s, core, true) == s);
- s.cursor = .{ .x = body.x + 2, .y = body.y + 1 };
- try std.testing.expect(try trail.apply(arena.allocator(), s, core, false) == s);
-}
-
-test "a notice chip casts a cell's shadow right and down, inside its body, off the cursor" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer core.deinit();
- _ = try core.setTestFile(std.mem.asBytes(&@as([20][20]u8, @splat("some text on a line\n".*))));
- try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
- core.settings.chip_shadow = true;
- try std.testing.expect(core.executeBuiltinLine(0, "Msg a notice"));
- for (0..60) |_| core.update(.tick);
- core.sync();
- var arena: std.heap.ArenaAllocator = .init(gpa);
- defer arena.deinit();
- const s = try core.render(arena.allocator());
- const chip = for (s.regionList()) |region| {
- if (region.kind == .notice) break region.rect;
- } else return error.NoNotice;
- s.cursor = null;
- const out = try chipShadows(arena.allocator(), s, core, true);
- try std.testing.expect(out != s);
- var changed: usize = 0;
- for (out.cells, s.cells, 0..) |a, b, i| {
- if (std.meta.eql(a, b)) continue;
- changed += 1;
- const x = i % s.cols;
- const y = i / s.cols;
- // Right of the chip or below it, never inside it.
- try std.testing.expect(x == chip.x + chip.w or y == chip.y + chip.h);
- try std.testing.expect(!(x >= chip.x and x < chip.x + chip.w and y >= chip.y and y < chip.y + chip.h));
- }
- try std.testing.expect(changed >= chip.w - 1);
- // Off, or without truecolor: the frame as it was.
- try std.testing.expect(try chipShadows(arena.allocator(), s, core, false) == s);
- core.settings.chip_shadow = false;
- try std.testing.expect(try chipShadows(arena.allocator(), s, core, true) == s);
-}
-
-test "a scrolled pane's thumb brightens and fades back in 250 ms" {
- const gpa = std.testing.allocator;
- const core = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 });
- defer core.deinit();
- const pane = try core.setTestFile(std.mem.asBytes(&@as([200][20]u8, @splat("some text on a line\n".*))));
- try std.testing.expect(core.executeBuiltinLine(0, "Theme forge"));
- core.settings.thumb_flash = true;
- for (0..40) |_| core.update(.tick);
- core.sync();
- var arena: std.heap.ArenaAllocator = .init(gpa);
- defer arena.deinit();
- var flash: ThumbFlash = .{};
- core.now_ns = std.time.ns_per_s;
- const first = try core.render(arena.allocator());
- try std.testing.expect(try flash.apply(arena.allocator(), first, core, true) == first);
- pane.scrollBy(20);
- core.now_ns += 16 * std.time.ns_per_ms;
- const moved = try core.render(arena.allocator());
- const lit = try flash.apply(arena.allocator(), moved, core, true);
- try std.testing.expect(lit != moved and core.shell_continuous);
- var brighter: usize = 0;
- for (lit.cells, moved.cells) |a, b| {
- if (!std.meta.eql(a.style.bg, b.style.bg)) brighter += 1;
- }
- try std.testing.expect(brighter >= 1);
- core.now_ns += 300 * std.time.ns_per_ms;
- core.shell_continuous = false;
- const later = try core.render(arena.allocator());
- try std.testing.expect(try flash.apply(arena.allocator(), later, core, true) == later);
- try std.testing.expect(!core.shell_continuous);
-}