summaryrefslogtreecommitdiff
path: root/src/TerminalImages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-21 14:35:15 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:15 -0300
commitbc3d18d27f9fc1155db7fac3946c4d38774f9e65 (patch)
tree9178ce95952797f8a78b16c2b805e53368efb35a /src/TerminalImages.zig
parent1ecb9b720840ea8e4753823fa8cddcf5d6a3a4d2 (diff)
downloadpardes-bc3d18d27f9fc1155db7fac3946c4d38774f9e65.tar.gz
pardes-bc3d18d27f9fc1155db7fac3946c4d38774f9e65.zip
Build with Zig 0.17
ghostty, libvaxis and uucode move to ghostty's 0.17 pins, cloud9 to its 0.17 main, SDL to castholm's release-3.4.x (3.4.18), zstbi and tree-sitter to forks with 0.17 build files (see build.zig.zon). A bare zig build copies the binaries into ~/.local/bin (-Dhome-install=false leaves it out): 0.17 keeps the prefix from build scripts. A terminal's edited copy goes when the program clears the screen. tinywin.snap is gone; perf baselines are re-recorded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/TerminalImages.zig')
-rw-r--r--src/TerminalImages.zig82
1 files changed, 76 insertions, 6 deletions
diff --git a/src/TerminalImages.zig b/src/TerminalImages.zig
index bc1b2ea8..4140813f 100644
--- a/src/TerminalImages.zig
+++ b/src/TerminalImages.zig
@@ -38,6 +38,72 @@ const GlyphKey = struct { id: u32, generation: u64, src: PixelRect, cols: u16 };
/// left corner (above or left of it is negative).
const Rect = struct { x: i64, y: i64, w: i64, h: i64 };
+/// The runs of Kitty placeholder cells between two pins, one row's run at a
+/// time, as ghostty's own `kitty.graphics.unicode.placementIterator` gave
+/// them before it moved into its RenderState, which pardes does not keep.
+const PlaceholderRuns = struct {
+ rows: ghostty_vt.PageList.RowIterator,
+ row: ?ghostty_vt.Pin,
+ /// Where the scan of `row` resumes: a run ended by an incompatible
+ /// placeholder starts the next one there.
+ x: usize = 0,
+
+ fn init(top: ghostty_vt.Pin, bottom: ghostty_vt.Pin) PlaceholderRuns {
+ var rows = top.rowIterator(.right_down, bottom);
+ const row = rows.next();
+ return .{ .rows = rows, .row = row };
+ }
+
+ fn next(self: *PlaceholderRuns) ?gfx.unicode.Placement {
+ while (self.row) |row| {
+ if (!row.rowAndCell().row.kitty_virtual_placeholder) {
+ self.advance();
+ continue;
+ }
+ var run: ?gfx.unicode.IncompletePlacement = null;
+ var start: usize = 0;
+ const cells = row.cells(.all);
+ while (self.x < cells.len) : (self.x += 1) {
+ const cell = &cells[self.x];
+ if (cell.codepoint() != gfx.unicode.placeholder) {
+ if (run) |done| return complete(row, start, done);
+ continue;
+ }
+ const style = row.style(cell);
+ const curr: gfx.unicode.IncompletePlacement = .init(&style, row.grapheme(cell) orelse &.{});
+ if (run) |*prev| {
+ if (!prev.append(&curr)) return complete(row, start, prev.*);
+ } else {
+ run = curr.start();
+ start = self.x;
+ }
+ }
+ self.advance();
+ if (run) |done| return complete(row, start, done);
+ }
+ return null;
+ }
+
+ fn advance(self: *PlaceholderRuns) void {
+ self.row = self.rows.next();
+ self.x = 0;
+ }
+
+ fn complete(row: ghostty_vt.Pin, x: usize, run: gfx.unicode.IncompletePlacement) gfx.unicode.Placement {
+ var pin = row;
+ pin.x = @intCast(x);
+ return .{
+ .pin = pin,
+ .image_id = run.imageId(),
+ .placement_id = run.placement_id orelse 0,
+ .col = run.col.?,
+ .row = run.row.?,
+ .width = run.width,
+ .height = 1,
+ };
+ }
+};
+
pub fn deinit(ti: *TerminalImages, gpa: std.mem.Allocator) void {
var conv = ti.converted.valueIterator();
while (conv.next()) |c| gpa.free(c.rgba);
@@ -91,7 +157,7 @@ pub fn draw(
// Virtual placements: shown through the placeholder cells, one run of
// them on a row at a time. The placeholders themselves are not text.
- var runs = gfx.unicode.placementIterator(top, bottom);
+ var runs: PlaceholderRuns = .init(top, bottom);
while (runs.next()) |run| {
const at = pages.pointFromPin(.viewport, run.pin) orelse continue;
const v = at.viewport.y;
@@ -104,7 +170,8 @@ pub fn draw(
cell.len = 1;
}
const img = storage.imageById(run.image_id) orelse continue;
- const rp = run.renderPlacement(storage, &img, cw, ch) catch continue;
+ const target = storage.placeholderTarget(run.image_id, run.placement_id) orelse continue;
+ const rp = run.renderPlacement(&target.placement, &img, cw, ch) catch continue;
if (rp.dest_width == 0 or rp.dest_height == 0 or rp.source_width == 0 or rp.source_height == 0) continue;
ctx.place(img, .{ .x = rp.source_x, .y = rp.source_y, .w = rp.source_width, .h = rp.source_height }, .{
.x = @as(i64, at.viewport.x) * cw + rp.offset_x,
@@ -122,7 +189,8 @@ pub fn draw(
const placed = entry.value_ptr.*;
const pin = switch (placed.location) {
.pin => |pin| pin,
- .virtual => continue,
+ // ponytail: a placement relative to another (P=/Q=, new in ghostty) is not drawn; resolve its chain if a program needs it.
+ .virtual, .relative => continue,
};
const img = storage.images.get(entry.key_ptr.image_id) orelse continue;
const at = pages.pointFromPin(.screen, pin.*) orelse continue;
@@ -221,7 +289,8 @@ const Ctx = struct {
fn pixelsOf(ti: *TerminalImages, gpa: std.mem.Allocator, img: gfx.Image) ?[]const u8 {
const n = @as(usize, img.width) * img.height;
if (n == 0) return null;
- if (img.format == .rgba) return if (img.data.len == n * 4) img.data else null;
+ const data = img.data.bytes() orelse return null;
+ if (img.format == .rgba) return if (data.len == n * 4) data else null;
const gop = ti.converted.getOrPut(gpa, img.id) catch return null;
if (gop.found_existing) {
if (gop.value_ptr.generation == img.generation) {
@@ -247,10 +316,11 @@ fn convert(gpa: std.mem.Allocator, img: gfx.Image, n: usize) ?[]u8 {
.gray => 1,
else => return null,
};
- if (img.data.len != n * depth) return null;
+ const data = img.data.bytes() orelse return null;
+ if (data.len != n * depth) return null;
const out = gpa.alloc(u8, n * 4) catch return null;
for (0..n) |i| {
- const px = img.data[i * depth ..][0..depth];
+ const px = data[i * depth ..][0..depth];
out[i * 4 ..][0..4].* = switch (depth) {
3 => .{ px[0], px[1], px[2], 255 },
2 => .{ px[0], px[0], px[0], px[1] },