summaryrefslogtreecommitdiff
path: root/src/term
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 /src/term
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
Diffstat (limited to 'src/term')
-rw-r--r--src/term/TerminalImages.zig9
-rw-r--r--src/term/pager.zig3
-rw-r--r--src/term/terminal.zig71
3 files changed, 43 insertions, 40 deletions
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());