summaryrefslogtreecommitdiff
path: root/src/ansi.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/ansi.zig')
-rw-r--r--src/ansi.zig36
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) {