From 3093eb55ac4a7054f51f06ea2786b5f9c9ec73f6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 11 Nov 2026 14:43:13 -0300 Subject: canim: a minimap in each pane; source wherever it can be had, libc's included From the user. Each pane with more than it shows carries a strip of its whole column at its right edge, the pane's window outlined and what happens off it marked there; the corner minimap is gone and the dive folds each column of the map into its pane's strip. The source panel follows the pc into any file the build has: glibc's own, from the distro's debuginfod by an optional step that caches them by build id (zig build sources; nothing else touches the network), and musl's, from Zig's lib directory. The syscalls scene shows open64.c on the way down, and a new scene follows the same call through a Zig-built musl. A graph's counts and inks are as of the moment shown. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa --- anim/src/source.zig | 115 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 39 deletions(-) (limited to 'anim/src/source.zig') diff --git a/anim/src/source.zig b/anim/src/source.zig index 0705f5b..5a5f1cd 100644 --- a/anim/src/source.zig +++ b/anim/src/source.zig @@ -41,41 +41,59 @@ pub const Source = struct { const u = context.at(f, placed, box); const rec = p.cursor.rec; const now = p.cursor.now(placed); - const text = prepared(rec.source, rec.file) orelse return; // Its window, and on the map the lines of both its boxes (`continued`): this one from `skip` lines in. const head = theme.layout.rowsIn(p.stage.box(placed, .source).h); const tail = theme.layout.rowsIn(p.stage.box(placed, .source_more).h); const fit: u32 = @intCast(theme.layout.rowsIn(box.h)); const span_fit: u32 = @intCast(head + tail); const skip: f32 = if (p.part == .source_more) @floatFromInt(head) else 0; - // The mark: leaving the line of one moment for that of the next. - const was = rec.own[now.marks[0]]; - const here = rec.own[now.marks[1]]; + // The mark: leaving the line of one moment for that of the next, in + // whichever file the pc is on a line of (a library's, where the + // build gave its source), else where it waits a frame up. + const at = [2]Recording.Shown{ rec.shown[now.marks[0]], rec.shown[now.marks[1]] }; + const was = at[0].line; + const here = at[1].line; // The window: where the line it is on has it, and (as the mark // moves on) gliding to where the next one does. It never cuts. const going = now.advancing(); - const windows = [2]f32{ @as(f32, @floatFromInt(rec.viewFirst(span_fit, was))) + skip, @as(f32, @floatFromInt(rec.viewFirst(span_fit, here))) + skip }; - // Farther than its own height (another function far off): what - // leaves has left before what replaces it arrives; a scroll of more - // lines than the window shows would be a blur, and say nothing. - const far = @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)); - const first = if (far) windows[if (going >= 0.5) 1 else 0] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); - const lit = if (far and going < 1) u.faded(@abs(2 * going - 1)) else u; + const windows = [2]f32{ @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[0]))) + skip, @as(f32, @floatFromInt(rec.shownFirst(span_fit, at[1]))) + skip }; + // Another file: the panel fades through (12 f out, 12 f in), its tag + // naming the file it comes to. Farther than its own height in one + // file (another function far off): its strip shows where it goes + // first (24 f), then what leaves has left before what replaces it + // arrives; a scroll of more lines than the window shows would be a + // blur, and say nothing. + const turn = at[0].src != at[1].src and going < 1; + const far = !turn and @abs(windows[1] - windows[0]) > @as(f32, @floatFromInt(fit)) and going < 1; + const side: usize = if (turn) @intFromBool(going >= 0.5) else if (far) @intFromBool(going >= 0.75) else @intFromBool(going >= 0.5); + const file = rec.sources[at[side].src]; + const text = prepared(file.text, file.path) orelse return; + const first = if (turn or far) windows[side] else std.math.lerp(windows[0], windows[1], cursors.glide(going)); + const fade: f32 = if (turn) @abs(2 * going - 1) else if (far) (if (going < 0.5) 1 else @abs(4 * going - 3)) else 1; + const lit = u.faded(fade); const from: u32 = @intFromFloat(@floor(first)); - const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), rec.line_count); - const shown_first: u32 = @intFromFloat(windows[if (going >= 0.5) 1 else 0]); - // Waiting: the pc is in code with no source, under this line's call. - const waits = p.descent and !rec.sourced(now.marked()) and rec.own[now.marked()] != 0; - const lines_note = if (rec.line_count > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, rec.line_count), rec.line_count }) else u.print("{d} lines", .{rec.line_count}); + const last: u32 = @min(from + @as(u32, @intCast(context.rowsOf(box))), file.lines); + // Waiting: the pc is in code with no source (a PLT stub, a library without it), under this line's call. + const waits = p.descent and !at[side].here and at[side].line != 0; + var lines_notes: [2][]const u8 = undefined; + for (at, windows, &lines_notes) |a, w, *note| { + const lines = rec.sources[a.src].lines; + const shown_first: u32 = @intFromFloat(w - skip); + note.* = if (lines > fit) u.print("lines {d} to {d} of {d}", .{ shown_first, @min(shown_first + fit - 1, lines), lines }) else u.print("{d} lines", .{lines}); + } // Where the pc is, said where it waits: a change of it (on through a // stub) crossfades over the 12 f before the advance, never in a frame. var notes: [2][]const u8 = undefined; - for (now.marks, ¬es) |mk, *note| note.* = if (p.descent and !rec.sourced(mk) and rec.own[mk] != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(firstOwn(rec, mk), "rip")), rec.own[mk], whereIs(u, rec, mk) }) else lines_note; - const swap = !std.mem.eql(u8, notes[0], notes[1]) and (notes[0].ptr != lines_note.ptr or notes[1].ptr != lines_note.ptr) and now.walking(); - const body = u.panel(box.w, box.h, if (p.part == .source_more) u.print("{s}, continued", .{rec.file}) else rec.file, .{ .focus = p.focus, .note = if (swap) "" else if (waits) notes[if (going >= 0.5) 1 else 0] else lines_note }); + for (now.marks, at, ¬es, lines_notes) |mk, a, *note, lines_note| note.* = if (p.descent and !a.here and a.line != 0) u.print("{s} waits at line {d} \u{00b7} the pc is in {s}", .{ context.frameName(u, rec, rec.register(lastShown(rec, mk), "rip")), a.line, whereIs(u, rec, mk) }) else lines_note; + const swap = !std.mem.eql(u8, notes[0], notes[1]) and now.walking(); + const titles = [2][]const u8{ rec.sources[at[0].src].name(), rec.sources[at[1].src].name() }; + const title = if (p.part == .source_more) u.print("{s}, continued", .{file.name()}) else file.name(); + const body = u.panel(box.w, box.h, if (turn) "" else title, .{ .focus = p.focus, .note = if (swap) "" else notes[side] }); + // Its tag's file and note change with the fade through it; a note otherwise over the 12 f before the advance. + if (turn) for (titles, [2]f32{ 1 - 2 * going, 2 * going - 1 }) |t, shows| u.faded(shows).tagTitle(t, p.focus); if (swap) { - const c = now.renaming(); - u.faded(1 - c).tagNote(box.w, notes[0]); + const c = if (turn) std.math.clamp(2 * going - 1, 0, 1) else now.renaming(); + u.faded(if (turn) 1 - 2 * going else 1 - c).tagNote(box.w, notes[0]); u.faded(c).tagNote(box.w, notes[1]); } const top = body.y + m.pad; @@ -86,7 +104,18 @@ pub const Source = struct { var mark_line = here; var mark_at: f32 = @floatFromInt(here); var shows: f32 = 1; - if (going < 1) { + if (turn or far) { + // It goes with the fade: out with the old window, in with the new. + mark_line = at[side].line; + mark_at = @floatFromInt(mark_line); + shows = fade; + // On the map, for the strip, it lights on its new line at once: the strip shows where the pane goes before it fades. + if (ui.mapping and far and going > 0) { + mark_line = here; + mark_at = @floatFromInt(here); + shows = 1; + } + } else if (going < 1) { if (!now.plan.wave and !cursors.jumps(rec, now.marks[0], now.marks[1])) { // A line near by: it slides, off promptly and settling on // the next. The step's follow-through. @@ -104,10 +133,9 @@ pub const Source = struct { } } const mark_y = top + (mark_at - first) * m.row; - // The numbers as wide as the program's largest: a scroll does not shift the text. - const widen = rows.numberRoom(rec.line_count); + // The numbers as wide as the widest file's largest: a scroll or another file does not shift the text. + const widen = rows.numberRoom(rec.most_lines); context.clipBody(u, box); - defer u.unclip(); // The plaque over the number. Fire: on the line about to run its // edges go out and come back, once, and nothing else moves. if (waits) { @@ -117,29 +145,35 @@ pub const Source = struct { } else if (shows > 0) u.faded(shows).current(.{ .x = theme.stroke.rule, .y = mark_y, .w = box.w - 2 * theme.stroke.rule, .h = m.row }, theme.metric.plaque.line + widen, now.fires(.source)); if (shows >= 1 and mark_y >= body.y and mark_y + m.row <= box.h) ties.anchor(u, .source, .{ .x = 0, .y = mark_y, .w = box.w, .h = m.row }); - // The trail: the last three other lines it was on, as the mark left - // them and as it finds them: a bar that moves crossfades with the advance. + // The trail: the last three other lines of its file it was on, as + // the mark left them and as it finds them: a bar that moves crossfades with the advance. var trails: [2][3]u32 = @splat(@splat(0)); var founds = [2]usize{ 0, 0 }; for (now.marks, &trails, &founds) |mk, *trail, *found| { - const on_line = rec.own[mk]; + const on = rec.shown[mk]; var back = mk; while (back > 0 and found.* < trail.len) { back -= 1; - const l = rec.own[back]; - if (l == 0 or l == on_line or std.mem.indexOfScalar(u32, trail[0..found.*], l) != null) continue; - trail[found.*] = l; + const l = rec.shown[back]; + if (l.line == 0 or l.src != on.src or l.line == on.line or std.mem.indexOfScalar(u32, trail[0..found.*], l.line) != null) continue; + trail[found.*] = l.line; found.* += 1; } } + if (turn) { + // Another file's trail is not this one's. + trails[1 - side] = @splat(0); + founds[1 - side] = 0; + } const lines_of = struct { - fn of(at: f32, n: u32, lines: u32) [2]u64 { - const a: u32 = @intFromFloat(at); - return .{ a, @min(a + n - 1, lines) }; + fn of(a: f32, n: u32, lines: u32) [2]u64 { + const l: u32 = @intFromFloat(a); + return .{ l, @min(l + n - 1, lines) }; } }.of; - map.window(.source, lines_of(windows[1], fit, rec.line_count), lines_of(windows[0], fit, rec.line_count), cursors.glide(going)); + // On the strip the window glides there; a window fading through goes before the fade, so the strip shows where it went first. + map.window(.source, lines_of(windows[1], fit, rec.sources[at[1].src].lines), lines_of(windows[0], fit, rec.sources[at[0].src].lines), if (turn) @floatFromInt(side) else cursors.glide(if (far) @min(2 * going, 1) else going)); var line = @max(from, 1); while (line <= last) : (line += 1) { const y = top + (@as(f32, @floatFromInt(line)) - first) * m.row; @@ -149,18 +183,21 @@ pub const Source = struct { const k = if (going >= 0.5) ks[1] else ks[0]; const on = shows >= 0.5 and line == mark_line; const fading = !std.meta.eql(ks[0], ks[1]) and going > 0 and going < 1; - rows.line(lit, y, box.w, line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); + rows.line(lit, y, map.content(box.w), line, widen, text.bytes[span[0]..span[1]], text.styles[span[0]..span[1]], if (on and !waits) .marked else if (fading) .plain else if (k) |n| .{ .trail = n } else .plain); if (fading and !(on and !waits)) for (ks, [2]f32{ 1 - going, going }) |kk, amount| if (kk) |n| lit.faded(amount).trail(theme.stroke.rule, y, n); } // The source is read at a run; at a sprint it is veiled too. context.veiled(u, box, now.sprint_veil); + u.unclip(); + // Another file is another column: its strip fades through as the pane does. + map.strip(.source, if (turn) u.faded(map.through(now, travel)) else u, box); } }; -/// The last moment at or before `i` whose pc was on a line of the program's source. -fn firstOwn(rec: *const Recording, i: u64) u64 { +/// The last moment at or before `i` whose pc was on a line the panel can show. +fn lastShown(rec: *const Recording, i: u64) u64 { var at = i; - while (at > 0 and !rec.sourced(at)) at -= 1; + while (at > 0 and !rec.shown[at].here) at -= 1; return at; } -- cgit v1.3