diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 11:25:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 73b7602b7948fe4b459f4344f091910297d4a107 (patch) | |
| tree | 8d30675d77d62534482d8aee2e154cd1c95ddee1 /src/ansi.zig | |
| parent | c8cfa9433ddbd210143b99b374406266e94a06c0 (diff) | |
| download | pardes-73b7602b7948fe4b459f4344f091910297d4a107.tar.gz pardes-73b7602b7948fe4b459f4344f091910297d4a107.zip | |
Term: paint only the view's rows the body shows (docs/next-terminal.md, Phase 1 as built): Term.paint takes the first row, and ansi.recolor walks the body once first for the rows its grid lines and an edit copy's lines stand over, so a pane shorter than its terminal (perf's render gesture: a 3-row shell strip beside the file, its terminal still 118x37 until the next update resizes it to 118x2) no longer paints 37 rows of cells (4,366 Painted, 20 bytes each, 87 KB a frame) to show 2, as Phase 0's walk never did; render on medium, best of ten, back to back against the tree before: tui Debug 126/124/127 -> 81/82/81 us, gui Debug 128/129/124 -> 82/83/82, tui ReleaseFast 110/107/112 -> 75/74/74 (the old baselines: 81, 81, 73), 0.72M instructions:u a frame fewer, every other gesture unchanged; perf --terminal-mib 8 and 32 (instructions:u, 3 runs each): 3,928.7M -> 3,928.5M and 13,219.2M -> 13,217.9M; the perf baselines recorded anew in the three shapes (Zig 0.17.1, harness aed36aceb98afadd), so unit-test's perf check passes again; tui core-test 811/950 (139 skipped), shell-test 993/996, term-test 15/15, pane-test 180/181, kitty-test 45/45, behaviour-test 269/273 (the four addon ABI tests the base fails), process-test 2 of 144 failed (lspcomplete and lspcompletemoved, the base's), replicas pass (checked/wrong 0), image-harness and kitty-harness pass, unit-test 1528/1536 (the four addon tests); gui core-test 811/950, image-harness and kitty-harness pass, unit-test 1587/1595 (the four addon tests)HEADmain
Diffstat (limited to 'src/ansi.zig')
| -rw-r--r-- | src/ansi.zig | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/ansi.zig b/src/ansi.zig index ad74dabb..224a5e69 100644 --- a/src/ansi.zig +++ b/src/ansi.zig @@ -56,17 +56,39 @@ pub fn recolor(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw const body_y = p.bodyTop(pane, r); const g = Term.grid(state); const cols = g.cols; + const vp_rows: i32 = @intCast(g.len); + // The view's rows the body shows, an edit copy's among them: only they + // are painted (a pane shorter than its terminal, as one is until the + // terminal is resized to it, shows few of its rows). + var lo: i32 = vp_rows; + var hi: i32 = 0; + { + var shown: BodyWalk = .init(pane); + var n: u16 = 0; + while (shown.next()) |row| : (n += 1) { + if (n >= body_h) break; + // A copy's line stands over one of the rows the copy covers. + const from: i32, const to: i32 = switch (row) { + .grid => |v| .{ v, v + 1 }, + .edit => .{ pane.ovl.?.row - shown.goff, pane.ovl.?.row + pane.ovl.?.rows - shown.goff }, + }; + lo = @min(lo, from); + hi = @max(hi, to); + } + } + lo = @max(lo, 0); + hi = @min(hi, vp_rows); + if (lo >= hi) return; const arena = p.scratch.allocator(); - const cells = arena.alloc(Term.Painted, g.len * @as(usize, cols)) catch return; - const rows = arena.alloc(Term.PaintedRow, g.len) catch return; + const cells = arena.alloc(Term.Painted, @as(usize, @intCast(hi - lo)) * cols) catch return; + const rows = arena.alloc(Term.PaintedRow, @intCast(hi - lo)) catch return; { const tz_paint = tracy.zone(@src(), "termPaint"); defer tz_paint.end(); const ink = inkOf(p.theme()); - Term.paint(state, &ink, &p.tty_filter_palette, pane.tty_filter, cols, cells, rows); + Term.paint(state, &ink, &p.tty_filter_palette, pane.tty_filter, @intCast(lo), cols, cells, rows); } const filtered = pane.tty_filter; - const vp_rows: i32 = @intCast(g.len); // Which buffer lines the user has not actually changed, so a row swallowed // by a growing buffer keeps the colour it still stands over. var anchors: ?EditAnchors = null; @@ -87,9 +109,9 @@ pub fn recolor(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw .grid => |v| .{ .row = v }, }; const vi = anchor.row; - if (vi < 0 or vi >= vp_rows) continue; - const prow = rows[@intCast(vi)]; - const grid_row = cells[@as(usize, @intCast(vi)) * cols ..][0..prow.len]; + if (vi < lo or vi >= hi) continue; + const prow = rows[@intCast(vi - lo)]; + const grid_row = cells[@as(usize, @intCast(vi - lo)) * cols ..][0..prow.len]; const cut: u16 = if (pane.body.mode == .tty) 0 else cut: { const prompt = prow.prompt orelse break :cut 0; break :cut switch (prompt) { |
