summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:06:49 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit98f84f99e79cccc2344aff2efe10823540d0c7b7 (patch)
tree0e11fcb0a2252858dc8c7b442a9c78152af5a585
parentf749eb712d990a9b03f1db372d5311e77bd32edd (diff)
downloadpardes-98f84f99e79cccc2344aff2efe10823540d0c7b7.tar.gz
pardes-98f84f99e79cccc2344aff2efe10823540d0c7b7.zip
plain: the records the core and the terminal both name, a leaf module (docs/next-terminal.md, Phase 1, its first step): src/plain/plain.zig takes Color, FontRole, CellStyle, Cell, RectPx, RectCell, Raster and Placement from surface.zig and Key from Event.zig, moved as they are, and imports std alone; surface.zig and Event.zig re-export them under their old names, so no caller changes; src/term/'s files name them through `plain` (pager.zig and TerminalImages.zig no longer reach surface.zig); build.zig's wireCore gives every core module the `plain` import; locations.Row stays (it names look.Spot and walk's digest: not free); core-test 985 of 985, lib-test
-rw-r--r--build.zig5
-rw-r--r--src/Event.zig31
-rw-r--r--src/plain/plain.zig158
-rw-r--r--src/surface.zig126
-rw-r--r--src/term/TerminalImages.zig9
-rw-r--r--src/term/pager.zig3
-rw-r--r--src/term/terminal.zig71
7 files changed, 218 insertions, 185 deletions
diff --git a/build.zig b/build.zig
index 903b7ea8..f59d1928 100644
--- a/build.zig
+++ b/build.zig
@@ -836,7 +836,10 @@ pub fn build(b: *std.Build) void {
image_mod.addCSourceFile(.{ .file = b.path("addons/image/stb.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
const image_addon = b.addLibrary(.{ .name = "image", .linkage = .dynamic, .root_module = image_mod });
for (builtin_mods) |m| m.addImport("image_addon", image_mod);
+ // The records the core and the terminal both name (src/plain/plain.zig).
+ const plain_mod = b.createModule(.{ .root_source_file = b.path("src/plain/plain.zig"), .target = target, .optimize = optimize });
for (core_mods) |m| wireCore(m, .{
+ .plain = plain_mod,
.kind = kind_mod,
.themes = themes_mod,
.tree_sitter = ts_mod,
@@ -2188,6 +2191,7 @@ fn library(b: *std.Build) void {
}
fn wireCore(m: *std.Build.Module, d: struct {
+ plain: ?*std.Build.Module = null,
kind: ?*std.Build.Module = null,
themes: ?*std.Build.Module = null,
tree_sitter: ?*std.Build.Module = null,
@@ -2202,6 +2206,7 @@ fn wireCore(m: *std.Build.Module, d: struct {
wuffs: ?*std.Build.Module = null,
xitdb: ?*std.Build.Module = null,
}) void {
+ if (d.plain) |x| m.addImport("plain", x);
if (d.kind) |x| m.addImport("pardes_addon", x);
if (d.themes) |x| m.addImport("generated_themes", x);
if (d.tree_sitter) |x| m.addImport("tree-sitter", x);
diff --git a/src/Event.zig b/src/Event.zig
index aa93f412..faea73cc 100644
--- a/src/Event.zig
+++ b/src/Event.zig
@@ -49,36 +49,7 @@ pub const Mouse = struct {
amount: f32 = 0,
};
-pub const Key = struct {
- cp: u21, // codepoint or one of the specials below
- text: []const u8 = "",
- ctrl: bool = false,
- alt: bool = false,
- shift: bool = false,
-
- pub const enter: u21 = 0x0D;
- pub const escape: u21 = 0x1B;
- pub const tab: u21 = 0x09;
- pub const backspace: u21 = 0x7F;
- // private-use plane for non-text keys, matching no real codepoint
- pub const up: u21 = 0xF0001;
- pub const down: u21 = 0xF0002;
- pub const left: u21 = 0xF0003;
- pub const right: u21 = 0xF0004;
- pub const home: u21 = 0xF0005;
- pub const end: u21 = 0xF0006;
- pub const page_up: u21 = 0xF0007;
- pub const page_down: u21 = 0xF0008;
- pub const delete: u21 = 0xF0009;
- pub const insert: u21 = 0xF000A;
- pub const print_screen: u21 = 0xF000B;
- pub const scroll_lock: u21 = 0xF000C;
- pub const pause: u21 = 0xF000D;
- pub const menu: u21 = 0xF000E;
- /// F1 to F25, in order: Fn is `f1 + n - 1`.
- pub const f1: u21 = 0xF0011;
- pub const f25: u21 = f1 + 24;
-};
+pub const Key = @import("plain").Key;
pub fn hit(key: Key, binding: []const config.Chord) bool {
for (binding) |c| {
diff --git a/src/plain/plain.zig b/src/plain/plain.zig
new file mode 100644
index 00000000..9c2cbb5a
--- /dev/null
+++ b/src/plain/plain.zig
@@ -0,0 +1,158 @@
+//! The plain records the core and the terminal both name
+//! (docs/next-terminal.md, Phase 1): a frame's cells, their styles and
+//! colours, the pictures over them and a key read. Data that needs
+//! nothing else, in a module of its own: the core (surface.zig and
+//! Event.zig, under their old names) and the terminal (src/term/) both
+//! import it, and neither imports the other.
+const std = @import("std");
+
+pub const Color = union(enum) { default, index: u8, rgb: [3]u8 };
+
+pub const FontRole = enum(u8) { body, tagline };
+
+pub const CellStyle = struct {
+ fg: Color = .default,
+ bg: Color = .default,
+ bold: bool = false,
+ dim: bool = false,
+ italic: bool = false,
+ blink: bool = false,
+ reverse: bool = false,
+ invisible: bool = false,
+ strikethrough: bool = false,
+ ul: enum(u3) { off, single, double, curly, dotted, dashed } = .off,
+ font_role: FontRole = .body,
+};
+
+pub const Cell = struct {
+ text: [7]u8 = @splat(' '),
+ len: u8 = 1,
+ style: CellStyle = .{},
+ default: bool = true,
+
+ pub fn grapheme(c: *const Cell) []const u8 {
+ return c.text[0..c.len];
+ }
+
+ pub fn visuallyEqual(a: *const Cell, b: *const Cell) bool {
+ if (a.default or b.default) return a.default and b.default;
+ return a.len == b.len and
+ std.mem.eql(u8, a.grapheme(), b.grapheme()) and
+ std.meta.eql(a.style, b.style);
+ }
+
+ pub fn printableAscii(c: *const Cell) ?u8 {
+ if (c.default) return ' ';
+ if (c.len != 1) return null;
+ const byte = c.text[0];
+ return if (byte >= ' ' and byte <= '~') byte else null;
+ }
+};
+
+/// A rectangle in pixels.
+pub const RectPx = struct {
+ x: u32 = 0,
+ y: u32 = 0,
+ w: u32 = 0,
+ h: u32 = 0,
+};
+
+/// A rectangle in the frame's cells.
+pub const RectCell = struct { x: u16 = 0, y: u16 = 0, w: u16 = 0, h: u16 = 0 };
+
+/// The pixels a placement shows: RGBA, straight alpha, `stride` bytes a
+/// row. They are the pane's, and stay put until its next frame.
+pub const Raster = struct {
+ ptr: [*]const u8,
+ w: u32,
+ h: u32,
+ stride: u32,
+
+ pub fn of(rgba: []const u8, w: usize, h: usize) Raster {
+ return .{ .ptr = rgba.ptr, .w = @intCast(w), .h = @intCast(h), .stride = @intCast(w * 4) };
+ }
+
+ pub fn bytes(r: Raster) []const u8 {
+ return r.ptr[0 .. @as(usize, r.stride) * r.h];
+ }
+};
+
+/// A picture over the frame's cells, which a frontend realises: the window
+/// as a texture kept by `key`, the tty as a kitty image, or either as glyph
+/// art in `dst`'s cells (Art.zig, the frontends' own) where it cannot show
+/// pixels or the pane asks for art. The frame lists them a pane at a time,
+/// lowest first.
+pub const Placement = struct {
+ pane: u8,
+ raster: Raster,
+ /// The part of `raster` shown.
+ src: RectPx,
+ /// The cells it lies over, which clip it.
+ dst: RectCell,
+ /// Where it goes in `dst`, in pixels from `dst`'s top left corner;
+ /// null: the frontend fits `src` there, no larger than it is, at the
+ /// top left (as glyph art, centred).
+ at: ?RectPx = null,
+ /// The pixels' identity (`keyOf`): one key is one picture, so a
+ /// frontend keeps what it uploaded under it.
+ key: u64,
+ /// A terminal program's kitty `z=`: below 0 it is under the text,
+ /// which a tty passes on to the terminal outside.
+ z: i32 = 0,
+ /// Rows of `raster` that alone differ from the picture under the key
+ /// `from`: a frontend still holding that one updates those rows.
+ dirty: ?Dirty = null,
+ art: Art = .{},
+
+ pub const Dirty = struct { from: u64, y: u32, h: u32 };
+
+ /// How the pane wants it drawn as glyph art: the Petscii, Palette and
+ /// Ascii words on an image pane, Petscii and TermImages on a terminal.
+ pub const Art = struct {
+ /// Glyph art even where pixels could be shown (Petscii on).
+ glyph: bool = false,
+ palette: Palette = .commodore,
+ /// Letters and signs among the glyphs, not only blocks and lines.
+ ascii: bool = true,
+
+ pub const Palette = enum { commodore, terminal };
+ };
+
+ /// A pane's picture `page` (a PDF's page, a terminal's image id; 0 for
+ /// an image) as of `revision`.
+ pub fn keyOf(serial: u32, page: u32, revision: u32) u64 {
+ return std.hash.Wyhash.hash(0, std.mem.asBytes(&[3]u32{ serial, page, revision }));
+ }
+};
+
+/// A key a frontend read (Event.zig).
+pub const Key = struct {
+ cp: u21, // codepoint or one of the specials below
+ text: []const u8 = "",
+ ctrl: bool = false,
+ alt: bool = false,
+ shift: bool = false,
+
+ pub const enter: u21 = 0x0D;
+ pub const escape: u21 = 0x1B;
+ pub const tab: u21 = 0x09;
+ pub const backspace: u21 = 0x7F;
+ // private-use plane for non-text keys, matching no real codepoint
+ pub const up: u21 = 0xF0001;
+ pub const down: u21 = 0xF0002;
+ pub const left: u21 = 0xF0003;
+ pub const right: u21 = 0xF0004;
+ pub const home: u21 = 0xF0005;
+ pub const end: u21 = 0xF0006;
+ pub const page_up: u21 = 0xF0007;
+ pub const page_down: u21 = 0xF0008;
+ pub const delete: u21 = 0xF0009;
+ pub const insert: u21 = 0xF000A;
+ pub const print_screen: u21 = 0xF000B;
+ pub const scroll_lock: u21 = 0xF000C;
+ pub const pause: u21 = 0xF000D;
+ pub const menu: u21 = 0xF000E;
+ /// F1 to F25, in order: Fn is `f1 + n - 1`.
+ pub const f1: u21 = 0xF0011;
+ pub const f25: u21 = f1 + 24;
+};
diff --git a/src/surface.zig b/src/surface.zig
index b832222f..73789dce 100644
--- a/src/surface.zig
+++ b/src/surface.zig
@@ -2,6 +2,7 @@
//! the image placements laid over them, and the Surface that holds a frame.
const pardes = @import("pardes.zig");
const std = @import("std");
+const plain = @import("plain");
const layout = @import("layout.zig");
const uucode = @import("uucode");
const vaxis = @import("vaxis");
@@ -11,56 +12,16 @@ const MAX_PANES = pardes.MAX_PANES;
const Layer = @import("Layer.zig");
const MAX_TAG_LAYERS = pardes.MAX_TAG_LAYERS;
-pub const Color = union(enum) { default, index: u8, rgb: [3]u8 };
-
-pub const FontRole = enum(u8) { body, tagline };
-
-pub const CellStyle = struct {
- fg: Color = .default,
- bg: Color = .default,
- bold: bool = false,
- dim: bool = false,
- italic: bool = false,
- blink: bool = false,
- reverse: bool = false,
- invisible: bool = false,
- strikethrough: bool = false,
- ul: enum(u3) { off, single, double, curly, dotted, dashed } = .off,
- font_role: FontRole = .body,
-};
-
-pub const Cell = struct {
- text: [7]u8 = @splat(' '),
- len: u8 = 1,
- style: CellStyle = .{},
- default: bool = true,
-
- pub fn grapheme(c: *const Cell) []const u8 {
- return c.text[0..c.len];
- }
-
- pub fn visuallyEqual(a: *const Cell, b: *const Cell) bool {
- if (a.default or b.default) return a.default and b.default;
- return a.len == b.len and
- std.mem.eql(u8, a.grapheme(), b.grapheme()) and
- std.meta.eql(a.style, b.style);
- }
-
- pub fn printableAscii(c: *const Cell) ?u8 {
- if (c.default) return ' ';
- if (c.len != 1) return null;
- const byte = c.text[0];
- return if (byte >= ' ' and byte <= '~') byte else null;
- }
-};
-
-/// A rectangle in pixels.
-pub const RectPx = struct {
- x: u32 = 0,
- y: u32 = 0,
- w: u32 = 0,
- h: u32 = 0,
-};
+// The plain records (src/plain/plain.zig) both the core and the terminal
+// name, under the names the core has always called them.
+pub const Color = plain.Color;
+pub const FontRole = plain.FontRole;
+pub const CellStyle = plain.CellStyle;
+pub const Cell = plain.Cell;
+pub const RectPx = plain.RectPx;
+pub const RectCell = plain.RectCell;
+pub const Raster = plain.Raster;
+pub const Placement = plain.Placement;
pub const PixelPoint = struct { x: u32, y: u32 };
@@ -113,73 +74,8 @@ pub fn containGeometry(iw: usize, ih: usize, max_w: u32, max_h: u32) ?NativeGeom
return .{ .src = .{ .w = src_w, .h = src_h }, .dst = dst };
}
-/// A rectangle in the frame's cells.
-pub const RectCell = struct { x: u16 = 0, y: u16 = 0, w: u16 = 0, h: u16 = 0 };
-/// The pixels a placement shows: RGBA, straight alpha, `stride` bytes a
-/// row. They are the pane's, and stay put until its next frame.
-pub const Raster = struct {
- ptr: [*]const u8,
- w: u32,
- h: u32,
- stride: u32,
- pub fn of(rgba: []const u8, w: usize, h: usize) Raster {
- return .{ .ptr = rgba.ptr, .w = @intCast(w), .h = @intCast(h), .stride = @intCast(w * 4) };
- }
-
- pub fn bytes(r: Raster) []const u8 {
- return r.ptr[0 .. @as(usize, r.stride) * r.h];
- }
-};
-
-/// A picture over the frame's cells, which a frontend realises: the window
-/// as a texture kept by `key`, the tty as a kitty image, or either as glyph
-/// art in `dst`'s cells (Art.zig, the frontends' own) where it cannot show
-/// pixels or the pane asks for art. The frame lists them a pane at a time,
-/// lowest first.
-pub const Placement = struct {
- pane: u8,
- raster: Raster,
- /// The part of `raster` shown.
- src: RectPx,
- /// The cells it lies over, which clip it.
- dst: RectCell,
- /// Where it goes in `dst`, in pixels from `dst`'s top left corner;
- /// null: the frontend fits `src` there, no larger than it is, at the
- /// top left (as glyph art, centred).
- at: ?RectPx = null,
- /// The pixels' identity (`keyOf`): one key is one picture, so a
- /// frontend keeps what it uploaded under it.
- key: u64,
- /// A terminal program's kitty `z=`: below 0 it is under the text,
- /// which a tty passes on to the terminal outside.
- z: i32 = 0,
- /// Rows of `raster` that alone differ from the picture under the key
- /// `from`: a frontend still holding that one updates those rows.
- dirty: ?Dirty = null,
- art: Art = .{},
-
- pub const Dirty = struct { from: u64, y: u32, h: u32 };
-
- /// How the pane wants it drawn as glyph art: the Petscii, Palette and
- /// Ascii words on an image pane, Petscii and TermImages on a terminal.
- pub const Art = struct {
- /// Glyph art even where pixels could be shown (Petscii on).
- glyph: bool = false,
- palette: Palette = .commodore,
- /// Letters and signs among the glyphs, not only blocks and lines.
- ascii: bool = true,
-
- pub const Palette = enum { commodore, terminal };
- };
-
- /// A pane's picture `page` (a PDF's page, a terminal's image id; 0 for
- /// an image) as of `revision`.
- pub fn keyOf(serial: u32, page: u32, revision: u32) u64 {
- return std.hash.Wyhash.hash(0, std.mem.asBytes(&[3]u32{ serial, page, revision }));
- }
-};
/// One part of the frame and where it is, placed once by `draw.place`
/// before anything is painted: every painter and every shell reads the
diff --git a/src/term/TerminalImages.zig b/src/term/TerminalImages.zig
index 6894945c..ab7aca25 100644
--- a/src/term/TerminalImages.zig
+++ b/src/term/TerminalImages.zig
@@ -8,6 +8,7 @@
//! moves with the text it was put on, and a virtual one (`U=1`) shown
//! through the U+10EEEE placeholder cells the program prints.
const std = @import("std");
+const plain = @import("plain");
const ghostty_vt = @import("ghostty-vt");
const pardes = @import("../pardes.zig");
const zstbi = @import("zstbi");
@@ -15,7 +16,7 @@ const wuffs = @import("wuffs");
const TerminalImages = @This();
const gfx = ghostty_vt.kitty.graphics;
-const PixelRect = @import("../surface.zig").RectPx;
+const PixelRect = plain.RectPx;
/// The bytes ghostty-vt may hold for one screen's images (it evicts the
/// oldest past this): a 4K picture in RGBA, with room for a second.
@@ -190,8 +191,8 @@ pub fn draw(
// 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(pardes.Placement, s.placements.items[first..], {}, struct {
- fn lessThan(_: void, a: pardes.Placement, b: pardes.Placement) bool {
+ defer std.sort.insertion(plain.Placement, s.placements.items[first..], {}, struct {
+ fn lessThan(_: void, a: plain.Placement, b: plain.Placement) bool {
return a.z < b.z;
}
}.lessThan);
@@ -314,7 +315,7 @@ const Ctx = struct {
.w = @intCast(x1 - x0),
.h = @intCast(y1 - y0),
},
- .key = pardes.Placement.keyOf(ctx.serial, img.id, @truncate(img.generation)),
+ .key = plain.Placement.keyOf(ctx.serial, img.id, @truncate(img.generation)),
.z = z,
.art = .{ .glyph = ctx.ti.petscii },
});
diff --git a/src/term/pager.zig b/src/term/pager.zig
index dca57024..c4dbf721 100644
--- a/src/term/pager.zig
+++ b/src/term/pager.zig
@@ -5,8 +5,9 @@
//! motion, OSC titles and hyperlinks, modes). The spans are display state
//! of the pane only: no 9P file reads them (File.recolorSyntax draws them).
const std = @import("std");
+const plain = @import("plain");
const pardes = @import("../pardes.zig");
-const CellStyle = @import("../surface.zig").CellStyle;
+const CellStyle = plain.CellStyle;
const ghostty_vt = @import("ghostty-vt");
/// Bytes `start..end` of the text, drawn in `style`. A palette colour stays
diff --git a/src/term/terminal.zig b/src/term/terminal.zig
index 85ac859d..d11d1074 100644
--- a/src/term/terminal.zig
+++ b/src/term/terminal.zig
@@ -2,6 +2,7 @@
//! typed over shell rows, and the Filter that recolours output to the theme.
const panes = @import("../panes.zig");
const std = @import("std");
+const plain = @import("plain");
const pardes = @import("../pardes.zig");
const config = @import("../config.zig");
const Pardes = pardes.Pardes;
@@ -9,7 +10,7 @@ const Surface = pardes.Surface;
const modal = @import("../modal.zig");
const tracy = @import("../tracy.zig");
const tagline = @import("../tagline.zig");
-const Key = pardes.Key;
+const Key = plain.Key;
const Pane = panes.Pane;
const Term = @import("../Term.zig");
const BodyWalk = @import("../body_layer.zig").BodyWalk;
@@ -1397,7 +1398,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16
// Consume every cell that contributed to this grapheme. A cluster
// ghostty split across several cells is still ONE printed glyph.
var covered: usize = 0;
- var style: ?pardes.CellStyle = null;
+ var style: ?plain.CellStyle = null;
while (covered < want) {
const ci = cellAt(pages, row_pin, gc) orelse break;
if (style == null and ci.cell.wide != .spacer_tail and ci.cell.wide != .spacer_head)
@@ -1422,7 +1423,7 @@ pub fn recolorAnsi(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16
sc += span;
at = stop;
}
- var tail: ?pardes.CellStyle = null;
+ var tail: ?plain.CellStyle = null;
if (anchor.whole() or anchor.suffix > 0) {
while (sc < tw) {
const ci = cellAt(pages, row_pin, gc) orelse break;
@@ -1459,13 +1460,13 @@ fn cellAt(pages: *const ghostty_vt.PageList, row: ghostty_vt.Pin, x: u16) ?ghost
// A cell's underline styles are SGR's, in SGR's order (`off` its `none`): a
// cast takes one to the other (cellStyle, and pager.zig's attribute).
comptime {
- for (@typeInfo(@FieldType(pardes.CellStyle, "ul")).@"enum".field_names, 0..) |name, i|
+ for (@typeInfo(@FieldType(plain.CellStyle, "ul")).@"enum".field_names, 0..) |name, i|
if (@backingInt(@field(ghostty_vt.sgr.Attribute.Underline, if (std.mem.eql(u8, name, "off")) "none" else name)) != i) @compileError("a cell's underline styles are not SGR's");
}
-fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColors, scnm: bool) pardes.CellStyle {
+fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColors, scnm: bool) plain.CellStyle {
const style = ci.style();
- var cs: pardes.CellStyle = .{
+ var cs: plain.CellStyle = .{
.fg = if (filtered) |colors| colors.fg(style) else ghostColor(p, style.fg_color, scnm),
.bg = if (filtered) |colors| colors.bg(style, ci.cell) else ghostColor(p, style.bg_color, !scnm),
.bold = style.flags.bold,
@@ -1488,7 +1489,7 @@ fn cellStyle(p: *Pardes, ci: ghostty_vt.PageList.Cell, filtered: ?*FilteredColor
return cs;
}
-fn asPardesColor(rgb: GColor.RGB) pardes.Color {
+fn asPardesColor(rgb: GColor.RGB) plain.Color {
return .{ .rgb = .{ rgb.r, rgb.g, rgb.b } };
}
@@ -1505,11 +1506,11 @@ pub const FilteredColors = struct {
/// What a foreground too near `default_bg` becomes instead.
fallback_fg: GColor.RGB,
default_bg_luminance: f64,
- fg_for_palette: [256]pardes.Color = undefined,
- bg_for_palette: [256]pardes.Color = undefined,
+ fg_for_palette: [256]plain.Color = undefined,
+ bg_for_palette: [256]plain.Color = undefined,
/// The two answers for a cell that names no colour of its own.
- fg_default: pardes.Color = undefined,
- bg_default: pardes.Color = undefined,
+ fg_default: plain.Color = undefined,
+ bg_default: plain.Color = undefined,
cache_rgb: [256]GColor.RGB = undefined,
cache_key: [256]u8 = undefined,
cache_valid: [256]bool = @splat(false),
@@ -1558,7 +1559,7 @@ pub const FilteredColors = struct {
return self;
}
- fn fg(self: *FilteredColors, style: ghostty_vt.Style) pardes.Color {
+ fn fg(self: *FilteredColors, style: ghostty_vt.Style) plain.Color {
return switch (style.fg_color) {
.none => self.fg_default,
.palette => |idx| self.fg_for_palette[idx],
@@ -1570,7 +1571,7 @@ pub const FilteredColors = struct {
};
}
- fn bg(self: *FilteredColors, style: ghostty_vt.Style, cell: *const ghostty_vt.Cell) pardes.Color {
+ fn bg(self: *FilteredColors, style: ghostty_vt.Style, cell: *const ghostty_vt.Cell) plain.Color {
switch (cell.content_tag) {
.bg_color_palette => return self.bg_for_palette[cell.content.color_palette.data],
.bg_color_rgb => {},
@@ -1585,7 +1586,7 @@ pub const FilteredColors = struct {
}
/// A +Pager span's colour (Term.page), as `fg` and `bg` map a cell's.
- pub fn spanColor(self: *FilteredColors, color: pardes.Color, is_bg: bool) pardes.Color {
+ pub fn spanColor(self: *FilteredColors, color: plain.Color, is_bg: bool) plain.Color {
return switch (color) {
.default => color,
.index => |idx| if (is_bg) self.bg_for_palette[idx] else self.fg_for_palette[idx],
@@ -1668,12 +1669,12 @@ fn colorDistance(a: GColor.RGB, b: GColor.RGB) u32 {
return @intCast(dr * dr + dg * dg + db * db);
}
-pub fn palColor(p: *Pardes, idx: u8) pardes.Color {
+pub fn palColor(p: *Pardes, idx: u8) plain.Color {
if (p.theme().palette) |pal| if (idx < 16) return .{ .rgb = pal[idx] };
return .{ .index = idx };
}
-fn ghostColor(p: *Pardes, color: ghostty_vt.Style.Color, is_bg: bool) pardes.Color {
+fn ghostColor(p: *Pardes, color: ghostty_vt.Style.Color, is_bg: bool) plain.Color {
return switch (color) {
.none => blk: {
const t = if (is_bg) p.theme().bg else p.theme().fg;
@@ -1775,7 +1776,7 @@ inline fn kittyTransmit(comptime extra: []const u8) []const u8 {
};
}
-fn imagePlaces(s: *const Surface) []const pardes.Placement {
+fn imagePlaces(s: *const Surface) []const plain.Placement {
return s.placements.items;
}
@@ -2059,9 +2060,9 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
const body_y = p.bodyTop(pane, r);
const raw = try p.render(frame.allocator());
- try testing.expectEqual(pardes.Color{ .index = 1 }, raw.at(tx, body_y).style.fg);
- try testing.expectEqual(pardes.Color{ .index = 196 }, raw.at(tx + 1, body_y).style.fg);
- try testing.expectEqual(pardes.Color{ .rgb = .{ 255, 0, 0 } }, raw.at(tx + 2, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .index = 1 }, raw.at(tx, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .index = 196 }, raw.at(tx + 1, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .rgb = .{ 255, 0, 0 } }, raw.at(tx + 2, body_y).style.fg);
pane.tty_filter = true;
_ = frame.reset(.retain_capacity);
@@ -2138,7 +2139,7 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
try testing.expectEqual(asPardesColor(expected[196]), reversed_blank.bg);
const reversed_explicit = reversed.at(tx, body_y).style;
try testing.expectEqual(asPardesColor(expected[196]), reversed_explicit.bg);
- try testing.expectEqual(pardes.Color{ .rgb = p.theme().bg.? }, reversed_explicit.fg);
+ try testing.expectEqual(plain.Color{ .rgb = p.theme().bg.? }, reversed_explicit.fg);
try testing.expect(!std.meta.eql(reversed_explicit.fg, reversed_explicit.bg));
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5l" } });
@@ -2158,11 +2159,11 @@ test "terminal Filter keys indexed truecolor OSC and background-only cells throu
p.custom_theme = custom;
_ = frame.reset(.retain_capacity);
const custom_first = try p.render(frame.allocator());
- try testing.expectEqual(pardes.Color{ .rgb = .{ 1, 2, 3 } }, custom_first.at(tx, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .rgb = .{ 1, 2, 3 } }, custom_first.at(tx, body_y).style.fg);
if (p.custom_theme) |*theme| theme.kw = .{ 4, 5, 6 };
_ = frame.reset(.retain_capacity);
const custom_second = try p.render(frame.allocator());
- try testing.expectEqual(pardes.Color{ .rgb = .{ 4, 5, 6 } }, custom_second.at(tx, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .rgb = .{ 4, 5, 6 } }, custom_second.at(tx, body_y).style.fg);
}
test "terminal Filter keeps extended keys dark-to-light on a light theme" {
@@ -2199,14 +2200,14 @@ test "terminal Filter preserves exact palette-null light theme default roles" {
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
const ordinary = try p.render(frame.allocator());
- try testing.expectEqual(pardes.Color{ .rgb = light.fg.? }, ordinary.at(tx, body_y).style.fg);
- try testing.expectEqual(pardes.Color{ .rgb = light.bg.? }, ordinary.at(tx, body_y).style.bg);
+ try testing.expectEqual(plain.Color{ .rgb = light.fg.? }, ordinary.at(tx, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, ordinary.at(tx, body_y).style.bg);
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[?5h" } });
_ = frame.reset(.retain_capacity);
const reversed = try p.render(frame.allocator());
- try testing.expectEqual(pardes.Color{ .rgb = light.bg.? }, reversed.at(tx, body_y).style.fg);
- try testing.expectEqual(pardes.Color{ .rgb = light.fg.? }, reversed.at(tx, body_y).style.bg);
+ try testing.expectEqual(plain.Color{ .rgb = light.bg.? }, reversed.at(tx, body_y).style.fg);
+ try testing.expectEqual(plain.Color{ .rgb = light.fg.? }, reversed.at(tx, body_y).style.bg);
}
test "terminal Filter maps the default roles before it maps anything else" {
@@ -2349,8 +2350,8 @@ test "tty ansi colors follow the prompt hug into normal mode" {
const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const body_y = p.bodyTop(pane, r);
- const red: pardes.Color = .{ .rgb = p.theme().palette.?[1] };
- const blue: pardes.Color = .{ .rgb = p.theme().palette.?[4] };
+ const red: plain.Color = .{ .rgb = p.theme().palette.?[1] };
+ const blue: plain.Color = .{ .rgb = p.theme().palette.?[4] };
// tty mode projects the emulator's ansi colours cell for cell.
pane.body.mode = .tty;
@@ -2390,7 +2391,7 @@ test "a prompt row hidden end to end paints nothing at all" {
const s = try p.render(frame.allocator());
try testing.expectEqualStrings(" ", s.at(tx, body_y).grapheme());
- try testing.expect(!std.meta.eql(pardes.Color{ .rgb = p.theme().palette.?[1] }, s.at(tx, body_y).style.bg));
+ try testing.expect(!std.meta.eql(plain.Color{ .rgb = p.theme().palette.?[1] }, s.at(tx, body_y).style.bg));
}
test "a program that asked for focus reports hears CSI I and CSI O as its pane takes and gives up the keyboard, and as the window does" {
@@ -2450,13 +2451,13 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an
const place = places[0];
const r = p.view().rects[0];
const img = pane.terminal.?.vt.screens.active.kitty_images.imageById(7).?;
- try std.testing.expectEqual(pardes.Placement.keyOf(pane.serial, 7, @truncate(img.generation)), place.key);
- try std.testing.expectEqual(pardes.RectCell{ .x = r.x + config.GUTTER + 4, .y = p.bodyTop(pane, r) + 2, .w = 2, .h = 1 }, place.dst);
+ try std.testing.expectEqual(plain.Placement.keyOf(pane.serial, 7, @truncate(img.generation)), place.key);
+ try std.testing.expectEqual(plain.RectCell{ .x = r.x + config.GUTTER + 4, .y = p.bodyTop(pane, r) + 2, .w = 2, .h = 1 }, place.dst);
try std.testing.expectEqual(@as(u32, 4), place.raster.w);
try std.testing.expectEqual(@as(u32, 2), place.raster.h);
try std.testing.expectEqualSlices(u8, &.{ 255, 0, 0, 255 }, place.raster.bytes()[0..4]);
- try std.testing.expectEqual(pardes.RectPx{ .x = 0, .y = 0, .w = 4, .h = 2 }, place.src);
- try std.testing.expectEqual(pardes.RectPx{ .x = 0, .y = 0, .w = 20, .h = 20 }, place.at.?);
+ try std.testing.expectEqual(plain.RectPx{ .x = 0, .y = 0, .w = 4, .h = 2 }, place.src);
+ try std.testing.expectEqual(plain.RectPx{ .x = 0, .y = 0, .w = 20, .h = 20 }, place.at.?);
// Scrolled up by the shell's output, it goes up with the text.
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[24;1H\n\n" } });
@@ -2567,7 +2568,7 @@ test "a virtual kitty placement shows through its placeholder cells, which draw
const r = p.view().rects[0];
const tx = r.x + config.GUTTER;
const y = p.bodyTop(pane, r) + 1;
- try std.testing.expectEqual(pardes.RectCell{ .x = tx + 2, .y = y, .w = 2, .h = 1 }, places[0].dst);
+ try std.testing.expectEqual(plain.RectCell{ .x = tx + 2, .y = y, .w = 2, .h = 1 }, places[0].dst);
try std.testing.expectEqualStrings(" ", s.at(tx + 2, y).grapheme());
try std.testing.expectEqualStrings(" ", s.at(tx + 3, y).grapheme());
try std.testing.expectEqualStrings("X", s.at(tx + 4, y).grapheme());