summaryrefslogtreecommitdiff
path: root/src/TerminalImages.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-22 09:50:43 -0300
committerGabriel Schneider <[email protected]>2026-10-22 10:03:24 -0300
commita8b457a306a4442975210bcac3f04b56513c61c3 (patch)
tree6e2026ecb15da2fb919a0202f5d8b38e3b36a595 /src/TerminalImages.zig
parenta8a1499bdffffc5b6919e24ec957e92fabaf003b (diff)
parent7e9d2c4169245072265b483ffaa6aa05f23f08d3 (diff)
downloadpardes-a8b457a306a4442975210bcac3f04b56513c61c3.tar.gz
pardes-a8b457a306a4442975210bcac3f04b56513c61c3.zip
Merge: Def/Refs, the diff viewer, Helix n/N, Callstack, Zig 0.17, Window mode and the terminal cwd fix onto 0.24
The docs keep both sides: 0.24's Ctrl-i fallbacks and typed ls with this line's Window mode, raw Esc and Helix n/N wording. The CHANGELOG's unreleased entries go above 0.24, Def/Refs and the context rows among them. cheatsheet-a4.pdf rendered again; .scratch/ ignored. 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] },