summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Term.zig8
-rw-r--r--src/ansi.zig36
-rw-r--r--src/plain/term.zig2
-rw-r--r--src/term/terminal.zig13
4 files changed, 41 insertions, 18 deletions
diff --git a/src/Term.zig b/src/Term.zig
index cf94c6d5..441280ee 100644
--- a/src/Term.zig
+++ b/src/Term.zig
@@ -342,10 +342,10 @@ pub fn spanColor(f: *Filter, color: plain.Color, is_bg: bool) plain.Color {
// images as placements; which of the body's rows they stand under is the
// core's (src/ansi.zig).
-/// Its view's rows as cells in the theme's colours, through the theme's
-/// filter when the pane has it on.
-pub fn paint(s: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, cols: u16, cells: []Painted, rows: []PaintedRow) void {
- the().paint(s.impl, ink, palette, filtered, cols, cells, rows);
+/// Its view's rows from `first`, `rows.len` of them, as cells in the
+/// theme's colours, through the theme's filter when the pane has it on.
+pub fn paint(s: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, first: u16, cols: u16, cells: []Painted, rows: []PaintedRow) void {
+ the().paint(s.impl, ink, palette, filtered, first, cols, cells, rows);
}
/// Its kitty graphics over the body's rows, as placements.
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) {
diff --git a/src/plain/term.zig b/src/plain/term.zig
index dbc4fc87..de969796 100644
--- a/src/plain/term.zig
+++ b/src/plain/term.zig
@@ -398,7 +398,7 @@ pub const Ops = struct {
/// Its view's rows, `rows.len` of them, `cols` cells each, into
/// `cells`: each cell's style in the theme's colours (through the
/// filter when `filtered`), its bytes and width.
- paint: *const fn (s: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, cols: u16, cells: []Painted, rows: []PaintedRow) void,
+ paint: *const fn (s: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, first: u16, cols: u16, cells: []Painted, rows: []PaintedRow) void,
/// Its kitty images over the body's rows, appended to `out`, and their
/// placeholder cells blanked in `frame` (`frame_cols` wide).
images: *const fn (s: *State, gpa: std.mem.Allocator, at: ImagesAt, out: *std.ArrayList(plain.Placement), frame: []plain.Cell, frame_cols: u16) void,
diff --git a/src/term/terminal.zig b/src/term/terminal.zig
index 71a2f3de..0178a848 100644
--- a/src/term/terminal.zig
+++ b/src/term/terminal.zig
@@ -1191,11 +1191,12 @@ pub fn viewport(state: *State, arena: std.mem.Allocator, cut: bool) ![]const []c
}
/// Its view's rows as cells, for the core's paint (Term.paint, the core's
-/// src/ansi.zig): `rows.len` rows of `cols` cells into `cells`, each its
-/// style in the theme's colours (through the filter when `filtered`), the
-/// bytes it spells in the view's text and its width; each row whether a
-/// prompt starts it, and how much of it that is.
-pub fn paint(state: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, cols: u16, cells: []Painted, rows: []PaintedRow) void {
+/// src/ansi.zig): `rows.len` rows from the view's row `first`, `cols`
+/// cells each into `cells`, each its style in the theme's colours (through
+/// the filter when `filtered`), the bytes it spells in the view's text and
+/// its width; each row whether a prompt starts it, and how much of it that
+/// is.
+pub fn paint(state: *State, ink: *const Ink, palette: *FilterPalette, filtered: bool, first: u16, cols: u16, cells: []Painted, rows: []PaintedRow) void {
var filter_storage: Filter = undefined;
const filter: ?*Filter = if (filtered) blk: {
filter_storage = filterOf(ink, palette, &state.vt);
@@ -1207,7 +1208,7 @@ pub fn paint(state: *State, ink: *const Ink, palette: *FilterPalette, filtered:
const pages = &state.vt.screens.active.pages;
for (rows, 0..) |*row, vi| {
row.* = .{ .prompt = null, .placeholder = false, .len = 0 };
- const row_pin = pages.pin(.{ .viewport = .{ .y = @intCast(vi) } }) orelse continue;
+ const row_pin = pages.pin(.{ .viewport = .{ .y = @intCast(first + vi) } }) orelse continue;
const flags = row_pin.rowAndCell().row;
if (flags.semantic_prompt != .none) row.prompt = promptCut(row_pin);
row.placeholder = flags.kitty_virtual_placeholder;