Skip to content

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

Python

Merge branch 'perf/tui-scroll-paint' into ui/tui-scrollbar-osc52

Rach Pradhanc3ce63a81f8a
diff --cc TUI/render.zig
index 375cfe71,dbc8b598..ac512940
--- a/TUI/render.zig
+++ b/TUI/render.zig
@@@ -8,7 -8,8 +8,9 @@@ const anchor = @import("anchor.zig")
const app = @import("app.zig");
const chrome = @import("chrome.zig");
const engine = @import("engine.zig");
+const layout_cache = @import("layout_cache.zig");
+ const scrollback = @import("scrollback.zig");
+ const scrollpaint = @import("scrollpaint.zig");
const selection = @import("selection.zig");
const theme_mod = @import("theme.zig");
const welcome = @import("welcome.zig");
@@@ -176,16 -185,26 +194,36 @@@ pub fn render(self: *Model, gpa: std.me
return gpa.dupe(u8, try selection.paint(self, a, out.items, width));
}
+/// `count` mid rows starting at `from`, taken from the layout cache when the
+/// mid IS the transcript and from the composed overlay/welcome lines otherwise.
+/// The cached path never materialises the rows outside the viewport, which is
+/// the whole point: a wheel tick copies a screenful, not a transcript.
+fn midSlice(a: std.mem.Allocator, cache: ?*layout_cache.Cache, lines: [][]const u8, from: usize, count: usize) ![]const []const u8 {
+ if (cache) |c| return layout_cache.window(c, a, from, count);
+ const end = @min(lines.len, from + count);
+ return lines[@min(from, end)..end];
+}
+
+ /// The delta the scrollable band moved by between the last frame and this one,
+ /// when that is the ONLY thing that happened to it — the painter's scroll fast
+ /// path. Null is always safe: it just means the ordinary row diff.
+ fn scrollHint(self: *const Model, prev: app.Band) ?scrollpaint.Hint {
+ const cur = self.band;
+ if (!cur.live or !prev.live) return null;
+ // Geometry moved, so screen row N is not the same slot it was: a resize, an
+ // image card appearing, the sticky header engaging, an overlay opening.
+ if (cur.top != prev.top or cur.len != prev.len) return null;
+ if (cur.off == prev.off) return null;
+ // The drag-selection band is anchored to SCREEN rows (#529), so its
+ // inverse video does not travel with the content a hardware scroll moves.
+ // The wheel drops the band for exactly this reason; keyboard scrolling
+ // keeps it, and that case has to keep repainting.
+ if (self.sel.active or self.sel.pressed) return null;
+ const d = @as(isize, @intCast(cur.off)) - @as(isize, @intCast(prev.off));
+ if (@abs(d) >= cur.len) return null;
+ return .{ .top = cur.top, .len = cur.len, .delta = d };
+ }
+
fn countLines(s: []const u8) usize {
if (s.len == 0) return 0;
return std.mem.count(u8, s, "\n") + 1;