Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Make the merged TUI polish branches compile and fit the ceiling

Rach Pradhan8f6b0ef6f934
diff --git a/TUI/diff.zig b/TUI/diff.zig
index b59af0d9..5bce87c4 100644
--- a/TUI/diff.zig
+++ b/TUI/diff.zig
@@ -18,6 +18,8 @@
const std = @import("std");
+const markdown = @import("markdown.zig");
+const syntax = @import("syntax.zig");
const theme_mod = @import("theme.zig");
/// What one diff line is. `meta` is the file/index header block, `ctx` an
@@ -343,3 +345,42 @@ test "a glyph wider than the row still advances, and width 0 does not wrap" {
try std.testing.expectEqual(@as(usize, 0), std.mem.count(u8, unwrapped, "\n"));
try expectClosed(unwrapped, th);
}
+
+// The markdown side of the same contract: a fence that IS a patch is banded
+// by this module instead of taking the code canvas. Lives here for the
+// 600-line ceiling on markdown.zig.
+
+test "a diff fence bands its edits instead of taking the code canvas" {
+ const th = theme_mod.of(.night);
+ const src = "before\n```diff\n@@ -1,2 +1,2 @@\n const keep = 0;\n-const old = 1;\n+const new = 2;\n```\nafter";
+ const out = try markdown.renderThemed(std.testing.allocator, src, th, 40);
+ defer std.testing.allocator.free(out);
+ try std.testing.expect(std.mem.indexOf(u8, out, addBg(false)) != null);
+ try std.testing.expect(std.mem.indexOf(u8, out, delBg(false)) != null);
+ // A patch is not code: it never picks up the fence's own background.
+ try std.testing.expect(std.mem.indexOf(u8, out, syntax.codeBg(false)) == null);
+ var it = std.mem.splitScalar(u8, out, '\n');
+ while (it.next()) |ln| {
+ try std.testing.expect(theme_mod.visibleLen(ln) <= 40);
+ if (std.mem.indexOf(u8, ln, "after") == null) continue;
+ // The prose under the fence inherits neither band.
+ try std.testing.expect(std.mem.indexOf(u8, ln, addBg(false)) == null);
+ try std.testing.expect(std.mem.indexOf(u8, ln, delBg(false)) == null);
+ }
+}
+
+test "an undeclared fence that IS a patch bands; a bullet list never does" {
+ const th = theme_mod.of(.night);
+ const banded = try markdown.renderThemed(std.testing.allocator, "```\n--- a/x\n+++ b/x\n-gone\n+here\n```", th, 40);
+ defer std.testing.allocator.free(banded);
+ try std.testing.expect(std.mem.indexOf(u8, banded, addBg(false)) != null);
+ // Lines that merely START with `-` are a list, not a diff (#diff).
+ const list = try markdown.renderThemed(std.testing.allocator, "- one\n- two\n- three", th, 40);
+ defer std.testing.allocator.free(list);
+ try std.testing.expect(std.mem.indexOf(u8, list, delBg(false)) == null);
+ // …and a zig fence still gets syntax colors on the code canvas.
+ const code = try markdown.renderThemed(std.testing.allocator, "```zig\nconst x = 1;\n```", th, 40);
+ defer std.testing.allocator.free(code);
+ try std.testing.expect(std.mem.indexOf(u8, code, syntax.codeBg(false)) != null);
+ try std.testing.expect(std.mem.indexOf(u8, code, addBg(false)) == null);
+}
diff --git a/TUI/markdown.zig b/TUI/markdown.zig
index ce564cef..4c9abfde 100644
--- a/TUI/markdown.zig
+++ b/TUI/markdown.zig
@@ -585,38 +585,3 @@ test "a wide table fits the terminal: grid intact, one visual line per row (#tab
try std.testing.expectEqual(@as(usize, 5), rows); // top rule, header, mid rule, body, bottom rule
try std.testing.expect(std.mem.indexOf(u8, out, "\u{2026}") != null); // over-long cells clip with an ellipsis
}
-
-test "a diff fence bands its edits instead of taking the code canvas" {
- const th = theme_mod.of(.night);
- const src = "before\n```diff\n@@ -1,2 +1,2 @@\n const keep = 0;\n-const old = 1;\n+const new = 2;\n```\nafter";
- const out = try renderThemed(std.testing.allocator, src, th, 40);
- defer std.testing.allocator.free(out);
- try std.testing.expect(std.mem.indexOf(u8, out, diff.addBg(false)) != null);
- try std.testing.expect(std.mem.indexOf(u8, out, diff.delBg(false)) != null);
- // A patch is not code: it never picks up the fence's own background.
- try std.testing.expect(std.mem.indexOf(u8, out, syntax.codeBg(false)) == null);
- var it = std.mem.splitScalar(u8, out, '\n');
- while (it.next()) |ln| {
- try std.testing.expect(theme_mod.visibleLen(ln) <= 40);
- if (std.mem.indexOf(u8, ln, "after") == null) continue;
- // The prose under the fence inherits neither band.
- try std.testing.expect(std.mem.indexOf(u8, ln, diff.addBg(false)) == null);
- try std.testing.expect(std.mem.indexOf(u8, ln, diff.delBg(false)) == null);
- }
-}
-
-test "an undeclared fence that IS a patch bands; a bullet list never does" {
- const th = theme_mod.of(.night);
- const patch = try renderThemed(std.testing.allocator, "```\n--- a/x\n+++ b/x\n-gone\n+here\n```", th, 40);
- defer std.testing.allocator.free(patch);
- try std.testing.expect(std.mem.indexOf(u8, patch, diff.addBg(false)) != null);
- // Lines that merely START with `-` are a list, not a diff (#diff).
- const list = try renderThemed(std.testing.allocator, "- one\n- two\n- three", th, 40);
- defer std.testing.allocator.free(list);
- try std.testing.expect(std.mem.indexOf(u8, list, diff.delBg(false)) == null);
- // …and a zig fence still gets syntax colors on the code canvas.
- const code = try renderThemed(std.testing.allocator, "```zig\nconst x = 1;\n```", th, 40);
- defer std.testing.allocator.free(code);
- try std.testing.expect(std.mem.indexOf(u8, code, syntax.codeBg(false)) != null);
- try std.testing.expect(std.mem.indexOf(u8, code, diff.addBg(false)) == null);
-}
diff --git a/TUI/scrollback_tests.zig b/TUI/scrollback_tests.zig
index 795e76d6..3dd4cd45 100644
--- a/TUI/scrollback_tests.zig
+++ b/TUI/scrollback_tests.zig
@@ -153,7 +153,6 @@ test "a failed call is marked, a refused one is marked differently" {
test "an edit result that is a unified diff renders banded, not quoted (#diff)" {
const diff = @import("diff.zig");
- const theme_mod = @import("theme.zig");
var m: Model = undefined;
m.setup(std.testing.allocator);
defer m.deinit();
@@ -193,7 +192,6 @@ test "end to end: a wrapped diff keeps its band and bleeds onto nothing (#diff)"
// active at a break, so a band left open at EOL is what used to paint the
// equal line (and the prose) under a long deletion.
const diff = @import("diff.zig");
- const theme_mod = @import("theme.zig");
var m: Model = undefined;
m.setup(std.testing.allocator);
defer m.deinit();