summaryrefslogtreecommitdiff
path: root/anim/src/aligned.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-13 01:24:16 -0300
committerGabriel Schneider <[email protected]>2026-11-13 01:34:46 -0300
commit5a40dca5adb6e9e650f55f3ec6f254a13bf50493 (patch)
tree5fdffebd75ed3fbac1eae5dec0a3f2d491450342 /anim/src/aligned.zig
parent4b4113a0217ee27c78e7efddb66ff5a455d49083 (diff)
downloadcomputeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.tar.gz
computeranim-5a40dca5adb6e9e650f55f3ec6f254a13bf50493.zip
debugger: align source and add rich Vim-style navigation
Diffstat (limited to 'anim/src/aligned.zig')
-rw-r--r--anim/src/aligned.zig51
1 files changed, 51 insertions, 0 deletions
diff --git a/anim/src/aligned.zig b/anim/src/aligned.zig
index ce2f5a0..24601c2 100644
--- a/anim/src/aligned.zig
+++ b/anim/src/aligned.zig
@@ -37,6 +37,57 @@ const theme = ui.theme;
const Rect = ui.Rect;
const t = theme.color.text;
+pub const LiveRow = struct {
+ instruction: ?usize,
+ source: ?@import("ztrace").store.Line = null,
+ again: bool = false,
+};
+
+/// The same column alignment for a bounded live listing. Source-only gaps have no address.
+pub fn livePlan(lines: []const ?@import("ztrace").store.Line, out: []LiveRow) []LiveRow {
+ var n: usize = 0;
+ var previous: ?@import("ztrace").store.Line = null;
+ for (lines, 0..) |line, i| {
+ const head = if (line) |l| previous == null or previous.?.file != l.file or previous.?.line != l.line else false;
+ if (head and previous != null) {
+ const before = previous.?;
+ const after = line.?;
+ if (before.file == after.file and after.line > before.line and after.line - before.line <= 8) {
+ var number = before.line + 1;
+ while (number < after.line and n < out.len) : (number += 1) {
+ out[n] = .{ .instruction = null, .source = .{ .file = after.file, .line = number } };
+ n += 1;
+ }
+ }
+ }
+ if (n == out.len) break;
+ var again = false;
+ if (head) for (lines[0..i]) |old| {
+ if (old) |l| if (l.file == line.?.file and l.line == line.?.line) {
+ again = true;
+ break;
+ };
+ };
+ out[n] = .{ .instruction = i, .source = if (head) line else null, .again = again };
+ n += 1;
+ previous = line;
+ }
+ return out[0..n];
+}
+
+test "live columns retain repeated runs and source-only gaps" {
+ const Line = @import("ztrace").store.Line;
+ const a: Line = .{ .file = 1, .line = 4 };
+ const b: Line = .{ .file = 1, .line = 7 };
+ var out: [16]LiveRow = undefined;
+ const got = livePlan(&.{ a, a, b, a, null }, &out);
+ try std.testing.expectEqual(@as(usize, 7), got.len);
+ try std.testing.expect(got[1].source == null);
+ try std.testing.expect(got[2].instruction == null and got[2].source.?.line == 5);
+ try std.testing.expect(got[5].again);
+ try std.testing.expect(got[6].source == null);
+}
+
const size = theme.size.mono.context;
const adv = ui.advance(size);
const pitch = theme.metric.context.row;