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/plain/plain.zig | 2 + src/plain/term.zig | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 src/plain/term.zig (limited to 'src/plain') diff --git a/src/plain/plain.zig b/src/plain/plain.zig index 9c2cbb5a..6dc75f94 100644 --- a/src/plain/plain.zig +++ b/src/plain/plain.zig @@ -5,6 +5,8 @@ //! Event.zig, under their old names) and the terminal (src/term/) both //! import it, and neither imports the other. const std = @import("std"); +/// The terminal as the core sees it: the records it takes and gives. +pub const term = @import("term.zig"); pub const Color = union(enum) { default, index: u8, rgb: [3]u8 }; diff --git a/src/plain/term.zig b/src/plain/term.zig new file mode 100644 index 00000000..2f1323f0 --- /dev/null +++ b/src/plain/term.zig @@ -0,0 +1,110 @@ +//! The terminal as the core sees it (docs/next-terminal.md, Phase 1): the +//! records its draw group takes and gives, plain data. src/Term.zig is the +//! core's side of it. +const std = @import("std"); +const plain = @import("plain.zig"); +const Color = plain.Color; +const CellStyle = plain.CellStyle; + +/// How much of a row the prompt it starts with is. +pub const PromptCut = union(enum) { + /// no prompt: the row as the emulator dumps it + keep, + /// all prompt, nothing typed yet: show nothing of it + blank, + /// this many leading COLUMNS are the prompt; the rest is what was typed + /// at it + cut: usize, +}; + +// ---- its colours on the body ---- + +/// A theme's colours as a terminal's paint takes them. +pub const Ink = struct { + fg: ?[3]u8, + bg: ?[3]u8, + tag_fg: [3]u8, + tag_bg: [3]u8, + /// The theme's own sixteen, when it has them. + palette: ?[16][3]u8, + /// The sixteen the filter keys a program's colours to: `palette`, else + /// made of the theme's roles. + base: [16][3]u8, + + /// A palette index as the theme draws it: its own sixteen, else the + /// index. + pub fn palColor(ink: *const Ink, idx: u8) Color { + if (ink.palette) |pal| if (idx < 16) return .{ .rgb = pal[idx] }; + return .{ .index = idx }; + } +}; + +/// The theme's 256 colours as the filter maps onto them, kept while the +/// theme is the same (`Pardes.tty_filter_palette`). +pub const FilterPalette = struct { + key: ?Key = null, + colors: [256][3]u8 = undefined, + + pub const Key = struct { bg: [3]u8, fg: [3]u8, base: [16][3]u8 }; +}; + +/// A program's colours mapped to the theme, once a frame: what a +Pager's +/// spans are drawn through (`spanColor`), as a terminal's cells are. +pub const Filter = struct { + target: *const [256][3]u8, + /// The theme's page and ink, and the page a program's colours are + /// drawn on (its OSC 11, keyed to the theme, else the theme's). + theme_bg: [3]u8, + theme_fg: [3]u8, + default_bg: [3]u8, + /// What a foreground too near the page's background becomes instead. + fallback_fg: [3]u8, + default_bg_luminance: f64, + fg_for_palette: [256]Color, + bg_for_palette: [256]Color, + /// The two answers for a cell that names no colour of its own. + fg_default: Color, + bg_default: Color, + cache_rgb: [256][3]u8 = undefined, + cache_key: [256]u8 = undefined, + cache_valid: [256]bool = @splat(false), +}; + +/// One cell of a terminal's view as its paint gives it: its style (its +/// colours the theme's already), the bytes it spells in the view's text, +/// and whether it is half of a wide one. +pub const Painted = struct { + style: CellStyle, + bytes: u16, + wide: enum(u2) { narrow, wide, spacer_tail, spacer_head }, +}; + +/// One row of a terminal's view as its paint gives it. +pub const PaintedRow = struct { + /// The shell marked it a prompt's: how much of it the prompt is. + prompt: ?PromptCut, + /// It holds kitty placeholder cells. + placeholder: bool, + /// Its cells given, from its first: the grid's past them are none. + len: u16, +}; + +/// Where a terminal's kitty images go, as the body lays out its rows: +/// `rows_of[v]` is the body row its view's row `v` shows on, null for one +/// not shown. +pub const ImagesAt = struct { + pane: u8, + serial: u32, + tx: u16, + body_y: u16, + cols: u16, + rows_of: []const ?u16, + /// The pane shows its terminal's rows as they are (tty mode): a prompt + /// row is the grid's then, and its images show. + tty_mode: bool, + /// The core's clock (animations step on it), and a cell's size in + /// pixels. + now_ms: u64, + cell_w: u32, + cell_h: u32, +}; -- cgit v1.3