summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Art.zig32
-rw-r--r--src/CHANGELOG.md4
-rw-r--r--src/colors.zig30
-rw-r--r--src/gui/gui.zig10
-rw-r--r--src/terminal.zig4
5 files changed, 41 insertions, 39 deletions
diff --git a/src/Art.zig b/src/Art.zig
index 6cc33e2e..2e2941c6 100644
--- a/src/Art.zig
+++ b/src/Art.zig
@@ -6,7 +6,7 @@
//! the same on every client. One of these a frontend keeps the art of the
//! pictures it shows, while it shows them.
const std = @import("std");
-const ghostty_vt = @import("ghostty-vt");
+const colors = @import("colors.zig");
const pardes = @import("pardes.zig");
const Art = @This();
@@ -76,7 +76,7 @@ fn gridOf(art: *Art, gpa: std.mem.Allocator, place: Placement, cell_h: u32) ?Gri
}
const colours = switch (place.art.palette) {
.commodore => commodore,
- .terminal => terminal_palette,
+ .terminal => colors.xterm[0..16].*,
};
const grid = (if (place.at == null)
fitted(gpa, place.raster, place.src, place.dst.w, place.dst.h, colours, place.art.ascii)
@@ -466,34 +466,6 @@ fn renderRect(gpa: std.mem.Allocator, raster: Raster, src: RectPx, cols: usize,
return .{ .cells = cells, .cols = cols, .rows = rows };
}
-pub const terminal_palette = [16][3]u8{
- .{ 0x1D, 0x1F, 0x21 }, // black
- .{ 0xCC, 0x66, 0x66 }, // red
- .{ 0xB5, 0xBD, 0x68 }, // green
- .{ 0xF0, 0xC6, 0x74 }, // yellow
- .{ 0x81, 0xA2, 0xBE }, // blue
- .{ 0xB2, 0x94, 0xBB }, // magenta
- .{ 0x8A, 0xBE, 0xB7 }, // cyan
- .{ 0xC5, 0xC8, 0xC6 }, // white
- .{ 0x66, 0x66, 0x66 }, // bright black
- .{ 0xD5, 0x4E, 0x53 }, // bright red
- .{ 0xB9, 0xCA, 0x4A }, // bright green
- .{ 0xE7, 0xC5, 0x47 }, // bright yellow
- .{ 0x7A, 0xA6, 0xDA }, // bright blue
- .{ 0xC3, 0x97, 0xD8 }, // bright magenta
- .{ 0x70, 0xC0, 0xB1 }, // bright cyan
- .{ 0xEA, 0xEA, 0xEA }, // bright white
-};
-
-comptime {
- for (terminal_palette, 0..) |rgb, i| {
- const c = ghostty_vt.color.default[i];
- if (rgb[0] != c.r or rgb[1] != c.g or rgb[2] != c.b) @compileError(
- "terminal palette differs from the emulator",
- );
- }
-}
-
test "sextant codepoints: blocks + endpoints" {
try std.testing.expectEqual(@as(u21, ' '), sextantCp(0));
try std.testing.expectEqual(@as(u21, 0x2588), sextantCp(63));
diff --git a/src/CHANGELOG.md b/src/CHANGELOG.md
index d0b07885..4226e986 100644
--- a/src/CHANGELOG.md
+++ b/src/CHANGELOG.md
@@ -5,7 +5,9 @@
- The core measures a grapheme's cells over uucode itself
(`File.utf8Width`, libvaxis's `gwidth` to the cell on every scalar
value), so libvaxis is the tui's and the gui's alone, not the core
- module's.
+ module's. The 256-colour palette Petscii art and the window draw a
+ palette colour with is pardes's own (`colors.xterm`), ghostty-vt's
+ default to the entry.
- Commit patches open as `+Diff-<short-hash>` and reuse only their own
commit's pane, so another paged patch no longer replaces one already open.
diff --git a/src/colors.zig b/src/colors.zig
index e679f4a5..1713ba24 100644
--- a/src/colors.zig
+++ b/src/colors.zig
@@ -12,6 +12,36 @@ const MAX_PANES = pardes.MAX_PANES;
const BOX_H = pardes.BOX_H;
const Pardes = pardes.Pardes;
+/// The 256-colour palette a terminal starts from (ghostty-vt's default):
+/// sixteen named colours, a 6x6x6 cube at xterm's levels (0, then 95 to
+/// 255 by 40) and a ramp of 24 greys from 8 by 10.
+pub const xterm: [256][3]u8 = blk: {
+ var p: [256][3]u8 = undefined;
+ p[0..16].* = .{
+ .{ 0x1D, 0x1F, 0x21 }, // black
+ .{ 0xCC, 0x66, 0x66 }, // red
+ .{ 0xB5, 0xBD, 0x68 }, // green
+ .{ 0xF0, 0xC6, 0x74 }, // yellow
+ .{ 0x81, 0xA2, 0xBE }, // blue
+ .{ 0xB2, 0x94, 0xBB }, // magenta
+ .{ 0x8A, 0xBE, 0xB7 }, // cyan
+ .{ 0xC5, 0xC8, 0xC6 }, // white
+ .{ 0x66, 0x66, 0x66 }, // bright black
+ .{ 0xD5, 0x4E, 0x53 }, // bright red
+ .{ 0xB9, 0xCA, 0x4A }, // bright green
+ .{ 0xE7, 0xC5, 0x47 }, // bright yellow
+ .{ 0x7A, 0xA6, 0xDA }, // bright blue
+ .{ 0xC3, 0x97, 0xD8 }, // bright magenta
+ .{ 0x70, 0xC0, 0xB1 }, // bright cyan
+ .{ 0xEA, 0xEA, 0xEA }, // bright white
+ };
+ for (0..216) |i| {
+ for (0..3, [3]usize{ i / 36, i / 6 % 6, i % 6 }) |c, v| p[16 + i][c] = if (v == 0) 0 else 55 + 40 * v;
+ }
+ for (0..24) |i| p[232 + i] = @splat(8 + 10 * i);
+ break :blk p;
+};
+
/// sRGB channel to linear light.
pub const to_linear: [256]f32 = blk: {
@setEvalBranchQuota(100_000);
diff --git a/src/gui/gui.zig b/src/gui/gui.zig
index 51ec6bbf..202f4aa8 100644
--- a/src/gui/gui.zig
+++ b/src/gui/gui.zig
@@ -7,7 +7,6 @@ const posix = std.posix;
/// libc: pipes and fcntl for the window's wakes, and a test harness's capture files written from the render thread.
const libc = std.c;
const vaxis = @import("vaxis"); // test modes only: the stdin escape-seq parser
-const ghostty_vt = @import("ghostty-vt"); // 256-color palette for .index cells
const pardes = @import("../pardes.zig");
const vaxis_input = @import("../vaxis_input.zig");
const dump = @import("../dump.zig");
@@ -4762,12 +4761,12 @@ fn resolveCell(g: *Gui, line: []const pardes.Cell, at: usize, cursor: ?usize, ro
const st = cell.style;
fg = switch (st.fg) {
.default => fg_default,
- .index => |i| palColor(i),
+ .index => |i| pardes.colors.xterm[i],
.rgb => |rgb| rgb,
};
switch (st.bg) {
.default => {},
- .index => |i| bg = palColor(i),
+ .index => |i| bg = pardes.colors.xterm[i],
.rgb => |rgb| bg = rgb,
}
if (st.reverse) reverse = !reverse;
@@ -5139,11 +5138,6 @@ fn cellCodepoint(cell: *const pardes.Cell) u32 {
return if (cell.default or grapheme.len == 0) ' ' else firstCp(grapheme);
}
-fn palColor(idx: u8) [3]u8 {
- const p = ghostty_vt.color.default[idx];
- return .{ p.r, p.g, p.b };
-}
-
fn firstCp(s: []const u8) u32 {
if (s.len == 0) return ' ';
const n = std.unicode.utf8ByteSequenceLength(s[0]) catch return ' ';
diff --git a/src/terminal.zig b/src/terminal.zig
index 68b3adde..46790de1 100644
--- a/src/terminal.zig
+++ b/src/terminal.zig
@@ -3420,3 +3420,7 @@ test "a program asking the cell size in pixels (CSI 16 t) is told the shell's" {
p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[16t" } });
try std.testing.expectEqualStrings("0:\x1b[6;20;10t\n", try ptyWritesByPane(p, &out));
}
+
+test "colors.xterm is the palette the emulator starts from, all 256" {
+ for (pardes.colors.xterm, ghostty_vt.color.default) |ours, its| try std.testing.expectEqual(ours, [3]u8{ its.r, its.g, its.b });
+}