summaryrefslogtreecommitdiff
path: root/src/term/terminal.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/term/terminal.zig')
-rw-r--r--src/term/terminal.zig71
1 files changed, 36 insertions, 35 deletions
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());