From 7c6ae90300527f7e54ad06eb4ab8ba605524ec60 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 25 Jul 2024 14:09:58 -0700 Subject: [PATCH] terminal/kitty: implement high bit image id parsing --- src/terminal/kitty/graphics_unicode.zig | 28 ++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/terminal/kitty/graphics_unicode.zig b/src/terminal/kitty/graphics_unicode.zig index e67790425..e04b20bd5 100644 --- a/src/terminal/kitty/graphics_unicode.zig +++ b/src/terminal/kitty/graphics_unicode.zig @@ -98,7 +98,8 @@ pub const PlacementIterator = struct { if (cps.len > 1) { p.col = getIndex(cps[1]) orelse @panic("TODO: invalid"); if (cps.len > 2) { - @panic("TODO: higher 8 bits of image ID"); + const high = getIndex(cps[2]) orelse @panic("TODO: invalid"); + p.image_id += high << 24; } } } else @panic("TODO: continuations"); @@ -546,6 +547,31 @@ test "unicode placement: specifying image id as palette" { try testing.expect(it.next() == null); } +test "unicode placement: specifying image id with high bits" { + const alloc = testing.allocator; + var t = try terminal.Terminal.init(alloc, .{ .rows = 5, .cols = 5 }); + defer t.deinit(alloc); + t.modes.set(.grapheme_cluster, true); + + // Single cell + try t.setAttribute(.{ .@"256_fg" = 42 }); + try t.printString("\u{10EEEE}\u{0305}\u{0305}\u{030E}"); + + // Get our top left pin + const pin = t.screen.pages.getTopLeft(.viewport); + + // Should have exactly one placement + var it = placementIterator(pin, null); + { + const p = it.next().?; + try testing.expectEqual(33554474, p.image_id); + try testing.expectEqual(0, p.placement_id); + try testing.expectEqual(0, p.row); + try testing.expectEqual(0, p.col); + } + try testing.expect(it.next() == null); +} + test "unicode placement: specifying placement id as palette" { const alloc = testing.allocator; var t = try terminal.Terminal.init(alloc, .{ .rows = 5, .cols = 5 });