summaryrefslogtreecommitdiff
path: root/src/tui
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-05 12:56:09 -0300
committerGabriel Schneider <[email protected]>2026-11-05 15:18:26 -0300
commit88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda (patch)
treec4c805e0e729f485b8fc1ae6a26c547b2fb7d356 /src/tui
parente65ada6bfab3e3851281be253b5e8187b652b66b (diff)
downloadpardes-88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda.tar.gz
pardes-88ae8456407e0ce9a2dd70ced0c53d8aa5f63fda.zip
the jump trail back, the frontends' alone: a jump of the cursor, three cells or more between two frames, leaves three to five cells behind it that fade in 120 ms, as the terminal's did, now seen by each frontend in the cursor of the Surface it shows and timed on its own clock (src/jump_trail.zig, shared by both); the tty tints those cells' ground toward the text again (truecolor terminals, COLORTERM read again for it), and the window draws over them in its overlay, both only on the page's own ground in the cursor's body; JumpTrail is a plain setting again (config.Runtime.jump_trail, off by default, dumped and replicated, in /ctl), which the frontends read; a frontend's trail asks for frames while it fades (shell_continuous, as its glide does)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/tui')
-rw-r--r--src/tui/tui.zig87
1 files changed, 84 insertions, 3 deletions
diff --git a/src/tui/tui.zig b/src/tui/tui.zig
index b2a198c7..2a067ed3 100644
--- a/src/tui/tui.zig
+++ b/src/tui/tui.zig
@@ -5,6 +5,7 @@ const posix = std.posix;
const libc = std.c;
const vaxis = @import("vaxis");
const pardes = @import("../pardes.zig");
+const JumpTrail = @import("../jump_trail.zig");
const vaxis_input = @import("../vaxis_input.zig");
const tracy = @import("../tracy.zig");
const look = @import("../look.zig");
@@ -1409,6 +1410,8 @@ const Screen = struct {
size: ?vaxis.Winsize = null,
/// The view's glide, the GUI's motion drawn at whole rows (anim 12).
glide: pardes.glide.Glide = .{},
+ /// The cursor's jump trail (JumpTrail), on the tty's own clock.
+ trail: JumpTrail = .{},
/// `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.
@@ -2608,12 +2611,15 @@ const Shell = struct {
_ = s.frame.reset(.retain_capacity);
const tz_cells = tracy.zone(@src(), "surface->vaxis");
const win = vx.window();
- // Each of the shell's own motions below asks for frames while it runs.
if (sc.glide.pending) sc.glide.measure(s.gpa, canonical);
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 shown = glideRows(s.frame.allocator(), canonical, &sc.glide) catch canonical;
+ const glided = glideRows(s.frame.allocator(), canonical, &sc.glide) catch canonical;
+ const truecolor = vx.caps.rgb or colortermTruecolor();
+ const trail_on = s.core.settings.jump_trail and truecolor and s.core.settings.motion != .off;
+ const shown = trailCells(s.frame.allocator(), glided, &sc.trail, trail_on, s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds)) catch glided;
+ // Each of the shell's own motions asks for frames while it runs.
+ s.core.shell_continuous = sc.glide.moving() or sc.trail.active;
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();
@@ -3343,6 +3349,81 @@ fn noticeLine(win: vaxis.Window, text: []const u8, cols: u16, rows: u16) void {
/// (pardes's patch to Vaxis.zig in build.zig), since a blank's ink shows
/// nowhere. Deciding that here cost every cell of every frame a look at the
/// frame before; vaxis already makes that comparison.
+/// The tty's picture of a jump's trail (jump_trail.zig): the cells behind
+/// the cursor in its body, on the page's own ground, that ground drawn
+/// toward the text's colour; a copy of `shown` while it fades.
+fn trailCells(arena: std.mem.Allocator, shown: *const pardes.Surface, trail: *JumpTrail, on: bool, now_ns: u64) !*const pardes.Surface {
+ var at: [5]JumpTrail.Cell = undefined;
+ const lit = trail.see(if (shown.cursor) |cu| .{ cu.x, cu.y } else null, on, now_ns, &at);
+ if (lit.len == 0) return shown;
+ const cursor = shown.cursor.?;
+ const body = for (shown.regionList()) |region| {
+ if (region.kind == .body and cursor.x >= region.rect.x and cursor.x < @as(u32, region.rect.x) + region.rect.w and
+ cursor.y >= region.rect.y and cursor.y < @as(u32, region.rect.y) + region.rect.h) break region.rect;
+ } else return shown;
+ const ink = shown.chrome.fg orelse .{ 0xcc, 0xcc, 0xcc };
+ const page = shown.chrome.page orelse pardes.colors.null_page;
+ const out = try arena.create(pardes.Surface);
+ out.* = shown.*;
+ out.cells = try arena.dupe(pardes.Cell, shown.cells);
+ for (lit) |cell| {
+ if (cell.x < body.x or cell.y < body.y or cell.x >= @as(i32, body.x) + body.w or cell.y >= @as(i32, body.y) + body.h) continue;
+ const c = &out.cells[@as(usize, @intCast(cell.y)) * out.cols + @as(usize, @intCast(cell.x))];
+ // On the page's own ground alone: never a selection or a match.
+ const ground: [3]u8 = if (c.default) page else switch (c.style.bg) {
+ .rgb => |rgb| rgb,
+ else => page,
+ };
+ if (!std.mem.eql(u8, &ground, &page)) continue;
+ if (c.default) c.style = .{};
+ c.default = false;
+ c.style.bg = .{ .rgb = pardes.colors.mixOklab(ground, ink, cell.strength) };
+ }
+ return out;
+}
+
+test "a jump's trail tints the ground behind the cursor in its body, and is gone by 120 ms" {
+ std.testing.refAllDecls(JumpTrail);
+ 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.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 = .{};
+ const ms = std.time.ns_per_ms;
+ s.cursor = .{ .x = body.x + 2, .y = body.y + 1 };
+ _ = try trailCells(arena.allocator(), s, &trail, true, 1000 * ms);
+ // Ten cells right: a trail back toward where it was.
+ s.cursor = .{ .x = body.x + 12, .y = body.y + 1 };
+ const lit = try trailCells(arena.allocator(), s, &trail, true, 1016 * ms);
+ var changed: usize = 0;
+ for (lit.cells, s.cells, 0..) |a, b, i| {
+ if (std.meta.eql(a, b)) 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);
+ try std.testing.expect(trail.active);
+ try std.testing.expect(try trailCells(arena.allocator(), s, &trail, true, 1150 * ms) == s);
+ try std.testing.expect(!trail.active);
+}
+
+/// Truecolor by COLORTERM (truecolor or 24bit), for a terminal that does
+/// not answer vaxis's query.
+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");
+}
+
/// 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