xonecas.io
79113
Ma

mini-coding-agent / commit 0bb2127

fix(tui diffs): show a header above each shell produced diff

xonecas2026-10-09 0bb21279383892aefa2727494d058b6367b0c93a parent 615df27

3 files changed

src/tui/diff_view.zig+9−13
@@ -119,19 +119,15 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
119119 return out.items;
120120 }
121121
122-pub fn diffRows(a: std.mem.Allocator, diffs: []const common.FileDiff) []const BodyLine {
123- var out: std.ArrayList(BodyLine) = .empty;
124- for (diffs) |d| {
125- out.append(a, .{ .text = d.path, .style = .{ .fg = theme.current.prompt } }) catch {};
126- if (d.patch) |patch| {
127- const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
128- var it = std.mem.splitScalar(u8, trimmed, '\n');
129- var body: std.ArrayList([]const u8) = .empty;
130- while (it.next()) |l| body.append(a, l) catch {};
131- out.appendSlice(a, diffLines(a, d.path, body.items)) catch {};
132- } else if (d.note) |note| {
133- out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
134- }
122+pub fn diffBody(a: std.mem.Allocator, d: common.FileDiff) []const BodyLine {
123+ if (d.patch) |patch| {
124+ const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
125+ var it = std.mem.splitScalar(u8, trimmed, '\n');
126+ var body: std.ArrayList([]const u8) = .empty;
127+ while (it.next()) |l| body.append(a, l) catch {};
128+ return diffLines(a, d.path, body.items);
135129 }
130+ var out: std.ArrayList(BodyLine) = .empty;
131+ if (d.note) |note| out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
136132 return out.items;
137133 }
src/tui/tool_view.zig+5−0
@@ -12,6 +12,11 @@ fn callHead(a: std.mem.Allocator, name: []const u8) []const u8 {
1212 return styles.teal(a, std.fmt.allocPrint(a, "-> {s}", .{name}) catch "->");
1313 }
1414
15+pub fn diffHead(a: std.mem.Allocator, name: []const u8, path: []const u8) []const u8 {
16+ const head = callHead(a, std.fmt.allocPrint(a, "{s} diff", .{name}) catch name);
17+ return std.fmt.allocPrint(a, "{s} {s}", .{ head, path }) catch path;
18+}
19+
1520 pub fn relativize(cwd: []const u8, path: []const u8) []const u8 {
1621 if (!std.fs.path.isAbsolute(path) or cwd.len == 0) return path;
1722 if (!std.mem.startsWith(u8, path, cwd)) return path;
src/tui/tui.zig+3−2
@@ -417,8 +417,9 @@ const Tui = struct {
417417 }
418418 if (bash_exit) |status_line| self.push(status_line);
419419 }
420- if (diffs.len > 0) {
421- for (render.plainRows(self.s, diff_view.diffRows(self.s, diffs))) |row| {
420+ for (diffs) |d| {
421+ self.push(tool_view.diffHead(self.s, name, d.path));
422+ for (render.plainRows(self.s, diff_view.diffBody(self.s, d))) |row| {
422423 self.push(std.fmt.allocPrint(self.s, "{s}{s}", .{ styles.dim(self.s, BODY_PREFIX), row }) catch row);
423424 }
424425 }