diff options
Diffstat (limited to 'src/terminal.zig')
| -rw-r--r-- | src/terminal.zig | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/src/terminal.zig b/src/terminal.zig index 6f9e2071..a285d1f8 100644 --- a/src/terminal.zig +++ b/src/terminal.zig @@ -3142,7 +3142,7 @@ pub fn drawImages(p: *Pardes, s: *Surface, pane: *Pane, id: usize, tx: u16, tw: } // Nothing to draw, no placeholder to blank and nothing cached to let // go: the common case costs the rows' flags. - if (!any_placeholder and screen.kitty_images.placements.count() == 0 and state.images.converted.count() == 0 and state.images.glyphs.count() == 0) return; + if (!any_placeholder and screen.kitty_images.placements.count() == 0 and state.images.converted.count() == 0) return; state.images.draw(p, s, &state.vt, @intCast(id), pane.serial, tx, body_y, @min(tw, pane.cols), rows_of[0..vp_rows]); } @@ -3210,8 +3210,8 @@ inline fn kittyTransmit(comptime extra: []const u8) []const u8 { }; } -fn imagePlaces(s: *const Surface) []const pardes.ImagePlace { - return s.images.items; +fn imagePlaces(s: *const Surface) []const pardes.Placement { + return s.placements.items; } test "a terminal's kitty graphics image is drawn where its program placed it, and a delete takes it away" { @@ -3232,25 +3232,20 @@ test "a terminal's kitty graphics image is drawn where its program placed it, an try std.testing.expectEqual(@as(usize, 1), places.len); const place = places[0]; const r = p.rects[0]; - try std.testing.expect(place.native.exact); - try std.testing.expectEqual(@as(u32, 7), place.native.page); - try std.testing.expectEqual(pane.serial, place.serial); - try std.testing.expectEqual(r.x + config.GUTTER + 4, place.x); - try std.testing.expectEqual(p.bodyTop(pane, r) + 2, place.y); - try std.testing.expectEqual(@as(u16, 2), place.w); - try std.testing.expectEqual(@as(u16, 1), place.h); - try std.testing.expectEqual(@as(usize, 4), place.iw); - try std.testing.expectEqual(@as(usize, 2), place.ih); - try std.testing.expectEqualSlices(u8, &.{ 255, 0, 0, 255 }, place.rgba[0..4]); - const g = place.native.geometry.?; - try std.testing.expectEqual(pardes.image.PixelRect{ .x = 0, .y = 0, .w = 4, .h = 2 }, g.src); - try std.testing.expectEqual(pardes.image.PixelRect{ .x = 0, .y = 0, .w = 20, .h = 20 }, g.dst); + 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(@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.?); // Scrolled up by the shell's output, it goes up with the text. p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b[24;1H\n\n" } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); - try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].y); + try std.testing.expectEqual(p.bodyTop(pane, r), imagePlaces(s)[0].dst.y); p.update(.{ .output = .{ .pane = 0, .bytes = "\n" } }); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); @@ -3362,15 +3357,13 @@ test "a virtual kitty placement shows through its placeholder cells, which draw const r = p.rects[0]; const tx = r.x + config.GUTTER; const y = p.bodyTop(pane, r) + 1; - try std.testing.expectEqual(tx + 2, places[0].x); - try std.testing.expectEqual(y, places[0].y); - try std.testing.expectEqual(@as(u16, 2), places[0].w); + try std.testing.expectEqual(pardes.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()); } -test "without pixels, or by the Petscii builtin, a terminal's image is glyph art in its cells" { +test "a terminal's image is a placement whatever the frontend draws, and the Petscii builtin asks for it as glyph art" { if (comptime !images_enabled) return error.SkipZigTest; const gpa = std.testing.allocator; const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .shells = 1 }); @@ -3384,40 +3377,27 @@ test "without pixels, or by the Petscii builtin, a terminal's image is glyph art const r = p.rects[0]; const tx = r.x + config.GUTTER; const y = p.bodyTop(pane, r); - const commodore = pardes.image.GlyphArt.commodore; - const painted = struct { - fn check(cell: *const pardes.Cell) bool { - const bg = switch (cell.style.bg) { - .rgb => |rgb| rgb, - else => return false, - }; - for (commodore) |c| if (std.mem.eql(u8, &c, &bg)) return true; - return false; - } - }.check; - // A shell that draws no pixels (a tty under no kitty graphics): forced. + // A frontend that draws no pixels (a tty under no kitty graphics) is + // handed the picture all the same, and the cells under it are its. p.frontend.native_images = false; var s = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len); - try std.testing.expect(painted(s.at(tx, y)) and painted(s.at(tx + 1, y))); - try std.testing.expect(!painted(s.at(tx + 2, y))); - // The tag says what is drawn, glyph art, as an image pane's does. + try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len); + try std.testing.expect(!imagePlaces(s)[0].art.glyph); + try std.testing.expectEqualStrings(" ", s.at(tx, y).grapheme()); + try std.testing.expectEqualStrings(" ", s.at(tx + 1, y).grapheme()); + // The tag says what that frontend draws, glyph art, as an image pane's does. try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null); - // Pixels where they can be drawn; the builtin flips the pane to glyphs - // and back. + // The builtin flips the pane to glyph art and back. p.frontend.native_images = true; - _ = frame.reset(.retain_capacity); - s = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len); try std.testing.expect(p.executeBuiltinLine(0, "Petscii")); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 0), imagePlaces(s).len); - try std.testing.expect(painted(s.at(tx, y))); + try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len); + try std.testing.expect(imagePlaces(s)[0].art.glyph); try std.testing.expect(std.mem.indexOf(u8, try tagline.tagPrefix(p, pane), " petscii:on") != null); - // Dumped and restored, it is still glyph art. + // Dumped and restored, it still asks for glyph art. try pardes.dump.dumpState(p); const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon"); defer restored.deinit(); @@ -3425,7 +3405,7 @@ test "without pixels, or by the Petscii builtin, a terminal's image is glyph art try std.testing.expect(p.executeBuiltinLine(0, "Petscii")); _ = frame.reset(.retain_capacity); s = try p.render(frame.allocator()); - try std.testing.expectEqual(@as(usize, 1), imagePlaces(s).len); + try std.testing.expect(!imagePlaces(s)[0].art.glyph); } test "TermImages is real by default, and petscii makes new terminals draw glyph art" { |
