xonecas.io
79113
Ma

mini-coding-agent / commit 0ad8387

fix: add the missing diff footer

xonecas2026-10-19 0ad8387389d80bf510c11e5f4bcf905d2e247794 parent 66c105b

3 files changed

src/tui/diff_view.zig+20−10
@@ -6,6 +6,12 @@ const render = @import("render.zig");
66
77 const BodyLine = render.BodyLine;
88
9+pub const Rendered = struct {
10+ lines: []const BodyLine = &.{},
11+ added: usize = 0,
12+ removed: usize = 0,
13+};
14+
915 fn diffHunk() theme.Style {
1016 return .{ .fg = theme.current.prompt };
1117 }
@@ -59,17 +65,17 @@ fn rebaseSpans(a: std.mem.Allocator, spans: []const highlight.Span, lo: u32, hi:
5965 return out.items;
6066 }
6167
62-pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const u8, max_diff_lines: usize) []const BodyLine {
68+pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const u8, max_diff_lines: usize) Rendered {
6369 if (lines.len > max_diff_lines) {
6470 var warn: std.ArrayList(BodyLine) = .empty;
6571 warn.append(a, .{
6672 .text = "Diff too large to render efficiently. Full contents in session.jsonl",
6773 .style = .{ .fg = theme.current.comment },
6874 }) catch {};
69- return warn.items;
75+ return .{ .lines = warn.items };
7076 }
7177 var joined: std.ArrayList(u8) = .empty;
72- var starts = a.alloc(u32, lines.len) catch return &.{};
78+ var starts = a.alloc(u32, lines.len) catch return .{};
7379 for (lines, 0..) |l, i| {
7480 if (i > 0) joined.append(a, '\n') catch {};
7581 starts[i] = @intCast(joined.items.len);
@@ -83,9 +89,9 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
8389 }.lt);
8490
8591 var code: std.ArrayList(u8) = .empty;
86- var kinds = a.alloc(DiffKind, lines.len) catch return &.{};
87- var los = a.alloc(u32, lines.len) catch return &.{};
88- var his = a.alloc(u32, lines.len) catch return &.{};
92+ var kinds = a.alloc(DiffKind, lines.len) catch return .{};
93+ var los = a.alloc(u32, lines.len) catch return .{};
94+ var his = a.alloc(u32, lines.len) catch return .{};
8995 var cursor: usize = 0;
9096 for (lines, 0..) |l, i| {
9197 while (cursor < nodes.len and nodes[cursor].end <= starts[i]) cursor += 1;
@@ -108,13 +114,17 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
108114 const spans = highlight.spansFor(a, langFor(path), code.items);
109115
110116 var out: std.ArrayList(BodyLine) = .empty;
117+ var added: usize = 0;
118+ var removed: usize = 0;
111119 for (lines, 0..) |l, i| {
112120 switch (kinds[i]) {
113121 .hunk => out.append(a, .{ .text = l, .style = diffHunk() }) catch {},
114122 .note => out.append(a, .{ .text = l, .style = .{ .fg = theme.current.comment } }) catch {},
115123 .ctx => out.append(a, .{ .text = l, .style = .{ .fg = theme.current.comment } }) catch {},
116124 .add, .del => {
117- const bg = if (kinds[i] == .add) theme.current.diff_add else theme.current.diff_delete;
125+ const is_add = kinds[i] == .add;
126+ if (is_add) added += 1 else removed += 1;
127+ const bg = if (is_add) theme.current.diff_add else theme.current.diff_delete;
118128 const content = l[1..];
119129 const painted = highlight.paint(a, content, rebaseSpans(a, spans, los[i], his[i]), .{ .bg = bg });
120130 out.append(a, .{
@@ -124,10 +134,10 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
124134 },
125135 }
126136 }
127- return out.items;
137+ return .{ .lines = out.items, .added = added, .removed = removed };
128138 }
129139
130-pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff, max_diff_lines: usize) []const BodyLine {
140+pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff, max_diff_lines: usize) Rendered {
131141 if (d.patch) |patch| {
132142 const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
133143 var it = std.mem.splitScalar(u8, trimmed, '\n');
@@ -137,5 +147,5 @@ pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff, max_diff_lines: usize)
137147 }
138148 var out: std.ArrayList(BodyLine) = .empty;
139149 if (d.note) |note| out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
140- return out.items;
150+ return .{ .lines = out.items };
141151 }
src/tui/tool_view.zig+15−3
@@ -58,7 +58,18 @@ pub fn callBody(a: std.mem.Allocator, name: []const u8, summary: []const u8) []c
5858 return out.items;
5959 }
6060
61-pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8, max_diff_lines: usize) []const BodyLine {
61+pub const Result = struct {
62+ lines: []const BodyLine,
63+ footer: ?[]const u8 = null,
64+};
65+
66+pub fn diffFooter(a: std.mem.Allocator, r: diff_view.Rendered) ?[]const u8 {
67+ if (r.added == 0 and r.removed == 0) return null;
68+ const stats = std.fmt.allocPrint(a, "+{d} -{d}", .{ r.added, r.removed }) catch return null;
69+ return metaLine(a, stats);
70+}
71+
72+pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8, max_diff_lines: usize) Result {
6273 const trimmed = std.mem.trimEnd(u8, text, " \t\r\n");
6374 var lines: std.ArrayList([]const u8) = .empty;
6475 var it = std.mem.splitScalar(u8, trimmed, '\n');
@@ -77,12 +88,13 @@ pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8, max
7788 if (verb.len > 0) {
7889 const path = lines.items[0][verb.len..];
7990 _ = lines.orderedRemove(0);
80- return diff_view.diffLines(a, path, lines.items, max_diff_lines);
91+ const r = diff_view.diffLines(a, path, lines.items, max_diff_lines);
92+ return .{ .lines = r.lines, .footer = diffFooter(a, r) };
8193 }
8294 }
8395 var out: std.ArrayList(BodyLine) = .empty;
8496 for (lines.items) |l| out.append(a, .{ .text = l }) catch {};
85- return out.items;
97+ return .{ .lines = out.items };
8698 }
8799
88100 pub fn metaLine(a: std.mem.Allocator, meta: []const u8) []const u8 {
src/tui/tui.zig+6−3
@@ -511,20 +511,23 @@ const Tui = struct {
511511 const width = @max(self.term.width() - BODY_PREFIX.len, 1);
512512 const is_bash = std.mem.eql(u8, name, "bash");
513513 const bash_exit: ?[]const u8 = if (is_bash) tool_view.exitLine(self.s, shown) else null;
514- const lines = tool_view.resultLines(self.s, name, shown, self.cfg.max_diff_lines);
515- const rows = if (std.mem.eql(u8, name, "edit")) render.plainRows(self.s, lines) else render.bodyRows(self.s, lines, width);
514+ const result = tool_view.resultLines(self.s, name, shown, self.cfg.max_diff_lines);
515+ const rows = if (std.mem.eql(u8, name, "edit")) render.plainRows(self.s, result.lines) else render.bodyRows(self.s, result.lines, width);
516516 const mark_error = is_error and bash_exit == null;
517517 for (rows, 0..) |row, i| {
518518 const prefix = if (mark_error and i == rows.len - 1) styles.err(self.s, ERROR_PREFIX) else styles.comment(self.s, BODY_PREFIX);
519519 self.push(std.fmt.allocPrint(self.s, "{s}{s}", .{ prefix, row }) catch row);
520520 }
521521 if (bash_exit) |status_line| self.push(status_line);
522+ if (result.footer) |footer| self.push(footer);
522523 }
523524 for (diffs) |d| {
524525 self.push(tool_view.diffHead(self.s, name, d.path));
525- for (render.plainRows(self.s, diff_view.diffBody(self.s, d, self.cfg.max_diff_lines))) |row| {
526+ const r = diff_view.diffBody(self.s, d, self.cfg.max_diff_lines);
527+ for (render.plainRows(self.s, r.lines)) |row| {
526528 self.push(std.fmt.allocPrint(self.s, "{s}{s}", .{ styles.comment(self.s, BODY_PREFIX), row }) catch row);
527529 }
530+ if (tool_view.diffFooter(self.s, r)) |footer| self.push(footer);
528531 }
529532 self.scrollback.separator = true;
530533 }