From a3509e4df5efc94b0deee3b06dd72f85b0d96647 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 03:25:13 -0300 Subject: Term: the draw group as plain data (docs/next-terminal.md, Phase 1): the terminal paints its view into a plain cell buffer and the core lays it over the body's rows; Term.paint gives each of its view's rows (Term.PaintedRow: the prompt cut a shell's marks make of it, its kitty placeholders, how many cells it has) and each cell (Term.Painted: its style in the theme's colours, through the filter when the pane has it on, the bytes it spells, its width) for a theme handed in as Term.Ink; src/ansi.zig, new, is the core's half of what was terminal.zig's recolorAnsi, moved: the body walk, the edit copy's anchors (EditAnchors, its rows from Term.editRows) and the grapheme-to-cell alignment, now reading the buffer instead of the emulator's pages, and drawImages' body walk (Term.images takes the rows it maps and appends placements to the frame's list, blanking placeholder cells in its cells, as TerminalImages.draw did through Pardes); the filter stays the terminal's (it wraps ghostty's generate256Color), its record plain (Term.Filter, Term.FilterPalette in src/plain/term.zig, [3]u8 for ghostty's RGB), so a +Pager's spans are drawn through Term.filter and Term.spanColor, and palColor is Ink.palColor; config.tty_filter_min_contrast goes to the filter it bounds; Term.Grid gains the grid's cols; the filter tests reach the plain record's fields through asGhostRgb, asserting what they did; perf --terminal-mib (tail-style line off, ReleaseFast, instructions:u, 3 runs each, ±30k): 8 MiB 4,347.9M -> 3,949.8M (4.51M -> 4.09M a batch), 32 MiB 14,729.1M -> 13,294.4M (3.82M -> 3.45M a batch), the copy costs nothing that shows and the frame got cheaper; core-test 985/985, kitty-test 45/45, pane-test 151/152 (1 skipped), behaviour-test 268/272 (the four addon ABI 3.0 tests the base fails), replicas checked/wrong 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/term/TerminalImages.zig | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'src/term/TerminalImages.zig') diff --git a/src/term/TerminalImages.zig b/src/term/TerminalImages.zig index ab7aca25..3847be4c 100644 --- a/src/term/TerminalImages.zig +++ b/src/term/TerminalImages.zig @@ -161,37 +161,35 @@ fn decodePng(gpa: std.mem.Allocator, bytes: []const u8) ghostty_vt.sys.DecodeErr /// columns the body shows, from `tx`. pub fn draw( ti: *TerminalImages, - p: *pardes.Pardes, - s: *pardes.Surface, + gpa: std.mem.Allocator, vt: *ghostty_vt.Terminal, - pane_id: u8, - serial: u32, - tx: u16, - body_y: u16, - cols: u16, + where: plain.term.ImagesAt, rows_of: []const ?u16, + out: *std.ArrayList(plain.Placement), + frame: []plain.Cell, + frame_cols: u16, ) void { var conv = ti.converted.valueIterator(); while (conv.next()) |c| c.used = false; - defer ti.prune(p.gpa); + defer ti.prune(gpa); const screen = vt.screens.active; const storage = &screen.kitty_images; // Animations step on the core's clock, as this frame shows them; the // shown frame is `renderData()` (a new `generation` each step, which // the caches key on). - const now_ms = p.clock.stepped_ns / std.time.ns_per_ms; + const now_ms = where.now_ms; ti.animation_due_ms = if (storage.animationTick(vt.io(), now_ms)) |delay| now_ms +| delay else null; const pages = &screen.pages; const top = pages.getTopLeft(.viewport); const bottom = pages.getBottomRight(.viewport) orelse return; - const cw: u32 = @max(1, p.view().cell_pixels.w); - const ch: u32 = @max(1, p.view().cell_pixels.h); - const ctx: Ctx = .{ .ti = ti, .p = p, .pane = pane_id, .serial = serial, .tx = tx, .body_y = body_y, .cols = cols, .rows_of = rows_of, .cw = cw, .ch = ch }; + const cw: u32 = @max(1, where.cell_w); + const ch: u32 = @max(1, where.cell_h); + const ctx: Ctx = .{ .ti = ti, .gpa = gpa, .out = out, .pane = where.pane, .serial = where.serial, .tx = where.tx, .body_y = where.body_y, .cols = where.cols, .rows_of = rows_of, .cw = cw, .ch = ch }; // Handed on lowest z first (the storage's order is a hash map's), the // order a shell draws them in; equal z keeps the order they came in. - const first = s.placements.items.len; - defer std.sort.insertion(plain.Placement, s.placements.items[first..], {}, struct { + const first = out.items.len; + defer std.sort.insertion(plain.Placement, out.items[first..], {}, struct { fn lessThan(_: void, a: plain.Placement, b: plain.Placement) bool { return a.z < b.z; } @@ -206,8 +204,8 @@ pub fn draw( if (v >= rows_of.len) continue; const row = rows_of[v] orelse continue; for (@as(usize, at.viewport.x)..@as(usize, at.viewport.x) + run.width) |x| { - if (x >= cols) break; - const cell = s.at(tx + @as(u16, @intCast(x)), body_y + row); + if (x >= where.cols) break; + const cell = &frame[@as(usize, where.body_y + row) * frame_cols + where.tx + x]; cell.text[0] = ' '; cell.len = 1; } @@ -268,7 +266,8 @@ pub fn draw( const Ctx = struct { ti: *TerminalImages, - p: *pardes.Pardes, + gpa: std.mem.Allocator, + out: *std.ArrayList(plain.Placement), pane: u8, serial: u32, tx: u16, @@ -286,7 +285,7 @@ const Ctx = struct { const x0 = @max(dst.x, 0); const x1 = @min(dst.x + dst.w, @as(i64, ctx.cols) * cw); if (x1 <= x0) return; - const rgba = ctx.ti.pixelsOf(ctx.p.gpa, img) orelse return; + const rgba = ctx.ti.pixelsOf(ctx.gpa, img) orelse return; const first_row = @divFloor(@max(dst.y, 0), ch); const last_row = @min(@divFloor(dst.y + dst.h - 1, ch), @as(i64, @intCast(ctx.rows_of.len)) - 1); var v = first_row; @@ -304,7 +303,7 @@ const Ctx = struct { }; const c0: u16 = @intCast(@divFloor(x0, cw)); const c1: u16 = @intCast(@divFloor(x1 + cw - 1, cw)); - _ = ctx.p.appendPlacement(.{ + ctx.out.append(ctx.gpa, .{ .pane = ctx.pane, .raster = .of(rgba, img.width, img.height), .src = piece, @@ -318,7 +317,7 @@ const Ctx = struct { .key = plain.Placement.keyOf(ctx.serial, img.id, @truncate(img.generation)), .z = z, .art = .{ .glyph = ctx.ti.petscii }, - }); + }) catch {}; } } }; -- cgit v1.3