diff options
| -rw-r--r-- | docs/typ/builtins-gui.json | 1 | ||||
| -rw-r--r-- | docs/typ/builtins-tui.json | 1 | ||||
| -rw-r--r-- | docs/typ/reference.typ | 1 | ||||
| -rw-r--r-- | src/config.zig | 7 | ||||
| -rw-r--r-- | src/gui/gui.zig | 77 | ||||
| -rw-r--r-- | src/jump_trail.zig | 87 | ||||
| -rw-r--r-- | src/tui/tui.zig | 87 |
7 files changed, 252 insertions, 9 deletions
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json index fbfcfd3c..1c435a63 100644 --- a/docs/typ/builtins-gui.json +++ b/docs/typ/builtins-gui.json @@ -49,6 +49,7 @@ {"name": "Index", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Run the file's language indexer at its project root, writing the index.scip the language words ask first."}, {"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the active pane's column into the one on its right, keeping its panes."}, {"name": "JumpScope", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "file, all", "doc": "What Back and Forward keep to: file, the focused pane's file until it runs out that way, or all, every place in order."}, + {"name": "JumpTrail", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A jump of the cursor leaves a short trail that fades, on or off."}, {"name": "Jumplist", "leader": "SPC j l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the places jumped from, each a place to go."}, {"name": "Kill", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "acme's Kill: stop the commands pardes started -- the lines it typed into a terminal, from an exec, a middle click or a pty/run, while their shell says they run (C mark to D)."}, {"name": "Last", "leader": "SPC j j", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Go back to the last place jumped from in another pane."}, diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json index 6c979754..4bb2837b 100644 --- a/docs/typ/builtins-tui.json +++ b/docs/typ/builtins-tui.json @@ -45,6 +45,7 @@ {"name": "Index", "leader": null, "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Run the file's language indexer at its project root, writing the index.scip the language words ask first."}, {"name": "Joincol", "leader": "SPC c j", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "Fold the active pane's column into the one on its right, keeping its panes."}, {"name": "JumpScope", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "file, all", "doc": "What Back and Forward keep to: file, the focused pane's file until it runs out that way, or all, every place in order."}, + {"name": "JumpTrail", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": "on, off", "doc": "A jump of the cursor leaves a short trail that fades, on or off."}, {"name": "Jumplist", "leader": "SPC j l", "also": [], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "List the places jumped from, each a place to go."}, {"name": "Kill", "leader": null, "also": [], "arg": true, "scope": "root", "setting": false, "choices": null, "doc": "acme's Kill: stop the commands pardes started -- the lines it typed into a terminal, from an exec, a middle click or a pty/run, while their shell says they run (C mark to D)."}, {"name": "Last", "leader": "SPC j j", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Go back to the last place jumped from in another pane."}, diff --git a/docs/typ/reference.typ b/docs/typ/reference.typ index 90bea27a..85f093a9 100644 --- a/docs/typ/reference.typ +++ b/docs/typ/reference.typ @@ -462,6 +462,7 @@ a repeated field's last value wins. The settings survive #word("Dump") and #word Source analysis is cached for 64 files and 64 MiB. *Effects.* #word("Motion") `off|crisp|smooth|bouncy|playful` (default `smooth`), +#word("JumpTrail") (off: a jump of the cursor leaves a short trail that fades, in a truecolor terminal and the window), #word("CursorBlink"), #word("GripWidth") `<50-300>`, the GUI's. No effect may lower the contrast of text, the selection or a focus indicator. diff --git a/src/config.zig b/src/config.zig index a7520b38..46a5f7c3 100644 --- a/src/config.zig +++ b/src/config.zig @@ -167,6 +167,7 @@ pub const leader_path = paths: { if (builtins.capabilities.window_blur) table.set(.WindowBlur, null); if (builtins.capabilities.ligatures) table.set(.Ligatures, null); if (builtins.capabilities.lift) table.set(.CursorBlink, null); + table.set(.JumpTrail, null); table.set(.ProgramEsc, null); table.set(.Motion, null); if (builtins.capabilities.lift) table.set(.GripWidth, null); @@ -724,6 +725,9 @@ pub const Runtime = struct { /// solid while typing and for half a second after, eased at each edge, /// solid again after ten idle seconds. cursor_blink: bool = true, + /// A jump of the cursor leaves a short trail that fades: a setting + /// alone, each frontend draws it (jump_trail.zig). + jump_trail: bool = false, /// In a raw terminal, Esc goes to the program and Shift-Esc backs out /// (off, the default: Esc backs out and Shift-Esc is the program's). program_esc: bool = false, @@ -872,7 +876,7 @@ pub const Runtime = struct { /// The message timings a setting word sets, each in milliseconds. pub const MessageTime = enum { linger, fall, dissolve }; - pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, pager_color, verbose, message_animation, ligatures, cursor_blink, program_esc }; + pub const Toggle = enum { colors, wrap, tree_context_tag_style, tag_bottom, debug, focus_tint, syntax_bold, pager_color, verbose, message_animation, ligatures, cursor_blink, jump_trail, program_esc }; pub const Action = union(enum) { toggle: Toggle, @@ -939,6 +943,7 @@ pub const Runtime = struct { .{ .word = "MessageAnimation", .action = .{ .toggle = .message_animation }, .doc = "A message falls into its row and dissolves out of it, on or off." }, .{ .word = "Ligatures", .action = .{ .toggle = .ligatures }, .doc = "A font's programming ligatures draw across their cells, on or off." }, .{ .word = "CursorBlink", .action = .{ .toggle = .cursor_blink }, .doc = "The cursor blinks, solid while typing, on or off." }, + .{ .word = "JumpTrail", .action = .{ .toggle = .jump_trail }, .doc = "A jump of the cursor leaves a short trail that fades, on or off." }, .{ .word = "ProgramEsc", .action = .{ .toggle = .program_esc }, .doc = "In a raw terminal, Esc goes to the program and Shift-Esc backs out, on; off (the default) swaps them." }, .{ .word = "Motion", .action = .motion, .doc = "How animations move: off, crisp, smooth, bouncy or playful." }, .{ .word = "GripWidth", .action = .grip_width, .doc = "The grip and scrollbar width, as a percent of the theme's rail." }, diff --git a/src/gui/gui.zig b/src/gui/gui.zig index e5ca645d..c2a4cb4e 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -14,6 +14,7 @@ const message = pardes.Messages.Message; const file_watch = @import("../file_watch.zig"); const deck = @import("deck.zig"); const pet = @import("pet.zig"); +const JumpTrail = @import("../jump_trail.zig"); const fonts = @import("../fonts.zig"); // the fallback faces const selection_pipe = @import("../selection_pipe.zig"); const c_heap = @import("c_heap"); @@ -240,9 +241,9 @@ const LoadedFallback = struct { const max_touch_points: usize = 16; const touch_scroll_tick: f32 = 0.02; -// The triangle overlay holds only the pet and the cursor's glide quad: the -// chrome is decor. -const max_overlay_vertices: usize = pet.max_vertices + 6; +// The triangle overlay holds only the pet, a jump's trail and the cursor's +// glide quad: the chrome is decor. +const max_overlay_vertices: usize = pet.max_vertices + 5 * 6 + 6; const font_px_step: f32 = 2.0; const font_px_min: f32 = 8.0; @@ -994,6 +995,8 @@ const Gui = struct { touch: Touch = .{}, /// The workspace tag's pet (Pet), on the window's own clock. pet_state: pet.State = .{}, + /// The cursor's jump trail (JumpTrail), on the window's own clock. + trail: JumpTrail = .{}, live_ctrl: bool = false, live_alt: bool = false, @@ -4553,7 +4556,7 @@ fn stepGlide(g: *Gui, core: *pardes.Pardes, gpa: std.mem.Allocator) void { const glide = &g.glide; // The glide runs on the core's continuous path: frames every loop, and // a virtual clock carried on. - defer core.shell_continuous = glide.moving(); + defer core.shell_continuous = glide.moving() or g.trail.active; const notch = g.scroll_notch; g.scroll_notch = 0; var wheeled: ?usize = null; @@ -5421,7 +5424,9 @@ fn renderFrame( if (!pdf_focus) core.frames.scroll = g.glide.follow.offset; core.frames.caret = caretRow(g, surface) orelse 0; const cursors_shown = !quad_mode; - var overlay_count = buildOverlay(g, core.settings.pet, surface, sw, sh); + var overlay_count = buildOverlay(g, core.settings.pet, core.settings.jump_trail and core.settings.motion != .off, surface, sw, sh); + // A trail fading asks for the frames it fades through. + if (g.trail.active) core.shell_continuous = true; if (overlay_count != 0 and !uploadOverlayGpu(g, cmd, overlay_count)) overlay_count = 0; if (!prepareNativeImages(g, gpa, cmd, surface, &groups, sw, sh)) { @@ -8060,6 +8065,7 @@ fn cursorDecor(g: *Gui, gpa: std.mem.Allocator, surface: *const pardes.Surface, fn buildOverlay( g: *Gui, which: pardes.config.Runtime.Pet, + trail_on: bool, surface: *const pardes.Surface, sw: u32, sh: u32, @@ -8067,10 +8073,71 @@ fn buildOverlay( if (g.overlay_vertices.len == 0 or sw == 0 or sh == 0) return 0; var builder = OverlayBuilder{ .vertices = g.overlay_vertices, .win_w = @floatFromInt(sw), .win_h = @floatFromInt(sh) }; appendWorkspacePet(g, which, surface, &builder); + appendJumpTrail(g, trail_on, surface, monoNs(), &builder); appendCursorGlide(g, surface, &builder); return @intCast(builder.len); } +/// A jump's trail (jump_trail.zig): the cells behind the cursor in its +/// body, on the page's own ground, drawn over toward the text's colour. +fn appendJumpTrail(g: *Gui, on: bool, surface: *const pardes.Surface, now_ns: u64, builder: *OverlayBuilder) void { + var at: [5]JumpTrail.Cell = undefined; + const lit = g.trail.see(if (surface.cursor) |cu| .{ cu.x, cu.y } else null, on, now_ns, &at); + if (lit.len == 0) return; + const cursor = surface.cursor.?; + const body = for (surface.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; + const page = surface.chrome.page orelse bg_default; + const w: f32 = @floatFromInt(g.cell_w); + const h: f32 = @floatFromInt(g.cell_h); + 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 under = &surface.cells[@as(usize, @intCast(cell.y)) * surface.cols + @as(usize, @intCast(cell.x))]; + // On the page's own ground alone: never a selection or a match. + const ground: [3]u8 = if (under.default) page else switch (under.style.bg) { + .rgb => |rgb| rgb, + else => page, + }; + if (!std.mem.eql(u8, &ground, &page)) continue; + var color = overlayRgb(surface.chrome.fg orelse fg_default); + color.a = cell.strength; + const x0 = @as(f32, @floatFromInt(cell.x)) * w; + const y0 = @as(f32, @floatFromInt(cell.y)) * h; + builder.addRect(x0, y0, x0 + w, y0 + h, color); + } +} + +test "a jump's trail is drawn behind the cursor in its body, and gone by 120 ms" { + var cells: [80 * 4]pardes.Cell = @splat(.{}); + var surface: pardes.Surface = .{ .cols = 80, .rows = 4, .cells = &cells }; + surface.regions[0] = .{ .kind = .body, .rect = .{ .x = 2, .y = 0, .w = 78, .h = 4 } }; + surface.nregions = 1; + var g = testGui(10, 20, 8, 16); + var vertices: [5 * 6]OverlayVertex = undefined; + var builder: OverlayBuilder = .{ .vertices = &vertices, .win_w = 800, .win_h = 80 }; + const ms = std.time.ns_per_ms; + surface.cursor = .{ .x = 4, .y = 1 }; + appendJumpTrail(&g, true, &surface, 1000 * ms, &builder); + try std.testing.expectEqual(@as(usize, 0), builder.len); + surface.cursor = .{ .x = 14, .y = 1 }; + appendJumpTrail(&g, true, &surface, 1016 * ms, &builder); + try std.testing.expect(builder.len >= 3 * 6 and builder.len <= 5 * 6); + // On the cursor's row, behind it, never its own cell. + for (vertices[0..builder.len]) |v| { + const x = (v.x + 1) * 400; + const y = (1 - v.y) * 40; + try std.testing.expect(y >= 20 - 0.01 and y <= 40 + 0.01); + try std.testing.expect(x >= 50 - 0.01 and x <= 140 + 0.01); + } + try std.testing.expect(g.trail.active); + builder.len = 0; + appendJumpTrail(&g, true, &surface, 1150 * ms, &builder); + try std.testing.expectEqual(@as(usize, 0), builder.len); + try std.testing.expect(!g.trail.active); +} + /// The workspace tag's pet (the Pet setting, gui/pet.zig): in the blank /// end of the grid's first row, past the tag's text, in the tag's colours, /// on the window's own clock. Nothing of it reaches the core. diff --git a/src/jump_trail.zig b/src/jump_trail.zig new file mode 100644 index 00000000..25eba636 --- /dev/null +++ b/src/jump_trail.zig @@ -0,0 +1,87 @@ +//! JumpTrail: a jump of the cursor, three cells or more between two frames, +//! leaves a trail of three to five cells behind it along its path, most +//! beside the cursor, all fading out over 120 ms. A frontend's own: it sees +//! the cursor of the Surface it shows, frame after frame, and times the fade +//! on its own clock; the tty tints those cells' ground toward the text, the +//! window draws over them. Nothing of it reaches the core, which keeps the +//! setting alone (config.Runtime.jump_trail). +const std = @import("std"); + +pub const life_ns: u64 = 120 * std.time.ns_per_ms; + +/// A cell of the trail, and how far toward the text it is drawn (0 to 1). +pub const Cell = struct { x: i32, y: i32, strength: f32 }; + +last: ?[2]u16 = null, +from: [2]u16 = .{ 0, 0 }, +to: [2]u16 = .{ 0, 0 }, +start_ns: u64 = 0, +/// Fading: a frontend draws frames until it is not. +active: bool = false, + +const JumpTrail = @This(); + +/// A frame shows the cursor at `cursor` (null: none) at `now_ns`: the +/// trail's cells in it, the one beside the cursor first, or none. +pub fn see(trail: *JumpTrail, cursor: ?[2]u16, on: bool, now_ns: u64, out: *[5]Cell) []const Cell { + const here = cursor orelse { + trail.* = .{}; + return out[0..0]; + }; + 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.* = .{ .from = was, .to = here, .start_ns = now_ns, .active = true }; + } + trail.last = here; + const age = now_ns -| trail.start_ns; + if (!on or !trail.active or age >= life_ns or !std.meta.eql(trail.to, here)) { + trail.active = false; + return out[0..0]; + } + const t = @as(f32, @floatFromInt(age)) / @as(f32, @floatFromInt(life_ns)); + const fade = (1 - t) * (1 - t); + const dx: f32 = @floatFromInt(@as(i32, trail.from[0]) - trail.to[0]); + const dy: 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 len: usize = 0; + 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; + const strength = 0.55 * fade * (1 - @as(f32, @floatFromInt(k - 1)) / @as(f32, @floatFromInt(n))); + if (strength < 0.02) continue; + out[len] = .{ .x = x, .y = y, .strength = strength }; + len += 1; + } + return out[0..len]; +} + +test "a jump leaves a few cells behind the cursor, fading in 120 ms; a step, or off, leaves none" { + const ms = std.time.ns_per_ms; + var trail: JumpTrail = .{}; + var out: [5]Cell = undefined; + try std.testing.expectEqual(@as(usize, 0), trail.see(.{ 2, 1 }, true, 1000 * ms, &out).len); + // Ten cells right: a trail back toward where it was, on its row, behind + // it, never its own cell, strongest beside it. + const lit = trail.see(.{ 12, 1 }, true, 1016 * ms, &out); + try std.testing.expect(trail.active and lit.len >= 3 and lit.len <= 5); + for (lit, 0..) |cell, i| { + try std.testing.expectEqual(@as(i32, 1), cell.y); + try std.testing.expect(cell.x > 2 and cell.x < 12); + if (i > 0) try std.testing.expect(cell.strength < lit[i - 1].strength and cell.x < lit[i - 1].x); + } + // Gone by 120 ms. + try std.testing.expectEqual(@as(usize, 0), trail.see(.{ 12, 1 }, true, 1150 * ms, &out).len); + try std.testing.expect(!trail.active); + // A step of a cell leaves none; nor does a jump with it off. + try std.testing.expectEqual(@as(usize, 0), trail.see(.{ 13, 1 }, true, 1200 * ms, &out).len); + try std.testing.expectEqual(@as(usize, 0), trail.see(.{ 2, 1 }, false, 1216 * ms, &out).len); + try std.testing.expect(!trail.active); +} 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 |
