aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/font/shaper/harfbuzz.zig
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-09-10 21:51:57 +0300
committerGitHub <noreply@github.com>2026-09-10 21:51:57 +0300
commit425c86179791cd32e2d4ce0ae7f269940b4b0663 (patch)
treee52c4383a6d69216cbe2a32638bf90841d7e2189 /vendor/libghostty-vt/src/font/shaper/harfbuzz.zig
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/font/shaper/harfbuzz.zig')
-rw-r--r--vendor/libghostty-vt/src/font/shaper/harfbuzz.zig128
1 files changed, 96 insertions, 32 deletions
diff --git a/vendor/libghostty-vt/src/font/shaper/harfbuzz.zig b/vendor/libghostty-vt/src/font/shaper/harfbuzz.zig
index 996aabff..11f9fd23 100644
--- a/vendor/libghostty-vt/src/font/shaper/harfbuzz.zig
+++ b/vendor/libghostty-vt/src/font/shaper/harfbuzz.zig
@@ -15,6 +15,7 @@ const Library = font.Library;
const SharedGrid = font.SharedGrid;
const Style = font.Style;
const Presentation = font.Presentation;
+const global = @import("../../global.zig");
const log = std.log.scoped(.font_shaper);
@@ -36,7 +37,7 @@ pub const Shaper = struct {
/// The codepoints added to the buffer before shaping. We need to keep
/// these separately because after shaping, HarfBuzz replaces codepoints
/// with glyph indices in the buffer.
- codepoints: std.ArrayListUnmanaged(Codepoint) = .{},
+ codepoints: std.ArrayList(Codepoint) = .empty,
const Codepoint = struct {
cluster: u32,
@@ -87,7 +88,7 @@ pub const Shaper = struct {
return Shaper{
.alloc = alloc,
.hb_buf = try harfbuzz.Buffer.create(),
- .cell_buf = .{},
+ .cell_buf = .empty,
.hb_feats = hb_feats,
};
}
@@ -134,8 +135,8 @@ pub const Shaper = struct {
// We have to lock the grid to get the face and unfortunately
// freetype faces (typically used with harfbuzz) are not thread
// safe so this has to be an exclusive lock.
- run.grid.lock.lock();
- defer run.grid.lock.unlock();
+ run.grid.lock.lockUncancelable(global.io());
+ defer run.grid.lock.unlock(global.io());
const face = try run.grid.resolver.collection.getFace(run.font_index);
const i = if (!face.quirks_disable_default_font_features) 0 else i: {
@@ -437,13 +438,14 @@ pub const Shaper = struct {
test "run iterator" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -467,7 +469,7 @@ test "run iterator" {
// Spaces should be part of a run
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -490,7 +492,7 @@ test "run iterator" {
{
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -521,13 +523,14 @@ test "run iterator" {
test "run iterator: empty cells with background set" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -576,6 +579,7 @@ test "run iterator: empty cells with background set" {
test "shape" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
@@ -587,7 +591,7 @@ test "shape" {
buf_idx += try std.unicode.utf8Encode(0x1F3FD, buf[buf_idx..]); // Medium skin tone
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -616,12 +620,13 @@ test "shape" {
test "shape inconsolata ligs" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -650,7 +655,7 @@ test "shape inconsolata ligs" {
}
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -682,12 +687,13 @@ test "shape inconsolata ligs" {
test "shape monaspace ligs" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaperWithFont(alloc, .monaspace_neon);
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -723,11 +729,12 @@ test "shape monaspace ligs" {
test "shape arabic forced LTR" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaperWithFont(alloc, .arabic);
defer testdata.deinit();
- var t = try terminal.Terminal.init(alloc, .{ .cols = 120, .rows = 30 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 120, .rows = 30 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -763,12 +770,13 @@ test "shape arabic forced LTR" {
test "shape emoji width" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -800,12 +808,14 @@ test "shape emoji width" {
test "shape emoji width long" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Make a screen and add a long emoji sequence to it.
var t = try terminal.Terminal.init(
+ io,
alloc,
.{ .cols = 30, .rows = 3 },
);
@@ -816,7 +826,7 @@ test "shape emoji width long" {
const cell = &row.cells.ptr(page.memory)[0];
cell.* = .{
.content_tag = .codepoint,
- .content = .{ .codepoint = 0x1F9D4 }, // Person with beard
+ .content = .{ .codepoint = @bitCast(@as(u24, 0x1F9D4)) }, // Person with beard
};
var graphemes = [_]u21{
0x1F3FB, // Light skin tone (Fitz 1-2)
@@ -852,9 +862,45 @@ test "shape emoji width long" {
try testing.expectEqual(@as(usize, 1), count);
}
+test "shaper selects font for entire grapheme" {
+ const testing = std.testing;
+ const alloc = testing.allocator;
+ const io = testing.io;
+
+ var testdata = try testShaper(alloc);
+ defer testdata.deinit();
+
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 5, .rows = 3 });
+ defer t.deinit(alloc);
+
+ var s = t.vtStream();
+ defer s.deinit();
+ s.nextSlice("#\u{20E3}"); // Combining enclosing keycap
+
+ const primary = (try testdata.grid.getIndex(alloc, '#', .regular, null)).?;
+ try testing.expect(testdata.grid.hasCodepoint(primary, '#', null));
+ try testing.expect(!testdata.grid.hasCodepoint(primary, 0x20E3, null));
+
+ const additional = (try testdata.grid.getIndex(alloc, 0x20E3, .regular, null)).?;
+ try testing.expect(testdata.grid.hasCodepoint(additional, '#', null));
+ try testing.expect(testdata.grid.hasCodepoint(additional, 0x20E3, null));
+
+ var state: terminal.RenderState = .empty;
+ defer state.deinit(alloc);
+ try state.update(alloc, &t);
+
+ var it = testdata.shaper.runIterator(.{
+ .grid = testdata.grid,
+ .cells = state.row_data.get(0).cells.slice(),
+ });
+ const run = (try it.next(alloc)).?;
+ try testing.expectEqual(additional, run.font_index);
+}
+
test "shape variation selector VS15" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
@@ -865,7 +911,7 @@ test "shape variation selector VS15" {
buf_idx += try std.unicode.utf8Encode(0xFE0E, buf[buf_idx..]); // ZWJ to force text
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -896,6 +942,7 @@ test "shape variation selector VS15" {
test "shape variation selector VS16" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
@@ -906,7 +953,7 @@ test "shape variation selector VS16" {
buf_idx += try std.unicode.utf8Encode(0xFE0F, buf[buf_idx..]); // ZWJ to force color
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -937,12 +984,14 @@ test "shape variation selector VS16" {
test "shape with empty cells in between" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Make a screen with some data
var t = try terminal.Terminal.init(
+ io,
alloc,
.{ .cols = 30, .rows = 3 },
);
@@ -977,6 +1026,7 @@ test "shape with empty cells in between" {
test "shape Combining characters" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
@@ -990,6 +1040,7 @@ test "shape Combining characters" {
// Make a screen with some data
var t = try terminal.Terminal.init(
+ io,
alloc,
.{ .cols = 30, .rows = 3 },
);
@@ -1029,6 +1080,7 @@ test "shape Combining characters" {
test "shape Devanagari string" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
// We need a font that supports devanagari for this to work, if we can't
// find Arial Unicode MS, which is a system font on macOS, we just skip
@@ -1040,7 +1092,7 @@ test "shape Devanagari string" {
defer testdata.deinit();
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Disable grapheme clustering
@@ -1087,6 +1139,7 @@ test "shape Tai Tham vowels (position differs from advance)" {
// // behavior.
// const testing = std.testing;
// const alloc = testing.allocator;
+ // const io = testing.io;
// // We need a font that supports Tai Tham for this to work, if we can't find
// // Noto Sans Tai Tham, which is a system font on macOS, we just skip the
@@ -1103,7 +1156,7 @@ test "shape Tai Tham vowels (position differs from advance)" {
// buf_idx += try std.unicode.utf8Encode(0x1a70, buf[buf_idx..]); // ᩰ
// // Make a screen with some data
- // var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ // var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
// defer t.deinit(alloc);
// // Enable grapheme clustering
@@ -1147,6 +1200,7 @@ test "shape Tai Tham vowels (position differs from advance)" {
test "shape Tibetan characters" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
// We need a font that has multiple glyphs for this codepoint to reproduce
// the old broken behavior, and Noto Serif Tibetan is one of them. It's not
@@ -1162,7 +1216,7 @@ test "shape Tibetan characters" {
buf_idx += try std.unicode.utf8Encode(0x0f00, buf[buf_idx..]); // ༀ
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1203,6 +1257,7 @@ test "shape Tai Tham letters (run_offset.y differs from zero)" {
return error.SkipZigTest;
// const testing = std.testing;
// const alloc = testing.allocator;
+ // const io = testing.io;
// // We need a font that supports Tai Tham for this to work, if we can't find
// // Noto Sans Tai Tham, which is a system font on macOS, we just skip the
@@ -1224,7 +1279,7 @@ test "shape Tai Tham letters (run_offset.y differs from zero)" {
// buf_idx += try std.unicode.utf8Encode(0x1a69, buf[buf_idx..]); // U
// // Make a screen with some data
- // var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ // var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
// defer t.deinit(alloc);
// // Enable grapheme clustering
@@ -1266,6 +1321,7 @@ test "shape Javanese ligatures" {
return error.SkipZigTest;
// const testing = std.testing;
// const alloc = testing.allocator;
+ // const io = testing.io;
// // We need a font that supports Javanese for this to work, if we can't find
// // Noto Sans Javanese Regular, which is a system font on macOS, we just
@@ -1287,7 +1343,7 @@ test "shape Javanese ligatures" {
// buf_idx += try std.unicode.utf8Encode(0xa9b8, buf[buf_idx..]); // Vowel sign SUKU
// // Make a screen with some data
- // var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ // var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
// defer t.deinit(alloc);
// // Enable grapheme clustering
@@ -1327,6 +1383,7 @@ test "shape Javanese ligatures" {
test "shape Chakma vowel sign with ligature (vowel sign renders first)" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
// We need a font that supports Chakma for this to work, if we can't find
// Noto Sans Chakma Regular, which is a system font on macOS, we just skip
@@ -1350,7 +1407,7 @@ test "shape Chakma vowel sign with ligature (vowel sign renders first)" {
buf_idx += try std.unicode.utf8Encode(0x1112c, buf[buf_idx..]); // Vowel Sign U
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1398,6 +1455,7 @@ test "shape Bengali ligatures with out of order vowels" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
// We need a font that supports Bengali for this to work, if we can't find
// Arial Unicode MS, which is a system font on macOS, we just skip the
@@ -1425,7 +1483,7 @@ test "shape Bengali ligatures with out of order vowels" {
buf_idx += try std.unicode.utf8Encode(0x09c7, buf[buf_idx..]); // Vowel sign E
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1472,6 +1530,7 @@ test "shape Bengali ligatures with out of order vowels" {
test "shape box glyphs" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
@@ -1482,7 +1541,7 @@ test "shape box glyphs" {
buf_idx += try std.unicode.utf8Encode(0x2501, buf[buf_idx..]); //
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1516,12 +1575,13 @@ test "shape box glyphs" {
test "shape selection boundary" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1621,12 +1681,13 @@ test "shape selection boundary" {
test "shape cursor boundary" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1758,12 +1819,14 @@ test "shape cursor boundary" {
test "shape cursor boundary and colored emoji" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Make a screen with some data
var t = try terminal.Terminal.init(
+ io,
alloc,
.{ .cols = 3, .rows = 10 },
);
@@ -1857,13 +1920,14 @@ test "shape cursor boundary and colored emoji" {
test "shape cell attribute change" {
const testing = std.testing;
const alloc = testing.allocator;
+ const io = testing.io;
var testdata = try testShaper(alloc);
defer testdata.deinit();
// Plain >= should shape into 1 run
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1889,7 +1953,7 @@ test "shape cell attribute change" {
// Bold vs regular should split
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 3, .rows = 10 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1917,7 +1981,7 @@ test "shape cell attribute change" {
// Changing fg color should split
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 3, .rows = 10 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1948,7 +2012,7 @@ test "shape cell attribute change" {
// Changing bg color should not split
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 3, .rows = 10 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1979,7 +2043,7 @@ test "shape cell attribute change" {
// Same bg color should not split
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 3, .rows = 10 });
+ var t = try terminal.Terminal.init(io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();