aboutsummaryrefslogtreecommitdiff
path: root/vendor/libghostty-vt/src/font/shaper
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
parent90e947a6e26e02f10ec7f1694c4eb5b78a86406b (diff)
chore: upgrade libghostty and preserve terminal behavior (#3906)
Diffstat (limited to 'vendor/libghostty-vt/src/font/shaper')
-rw-r--r--vendor/libghostty-vt/src/font/shaper/coretext.zig93
-rw-r--r--vendor/libghostty-vt/src/font/shaper/feature.zig33
-rw-r--r--vendor/libghostty-vt/src/font/shaper/harfbuzz.zig128
-rw-r--r--vendor/libghostty-vt/src/font/shaper/run.zig53
4 files changed, 179 insertions, 128 deletions
diff --git a/vendor/libghostty-vt/src/font/shaper/coretext.zig b/vendor/libghostty-vt/src/font/shaper/coretext.zig
index 8a9374bd..5172744d 100644
--- a/vendor/libghostty-vt/src/font/shaper/coretext.zig
+++ b/vendor/libghostty-vt/src/font/shaper/coretext.zig
@@ -20,6 +20,7 @@ const SharedGrid = font.SharedGrid;
const Style = font.Style;
const Presentation = font.Presentation;
const CFReleaseThread = os.CFReleaseThread;
+const global = @import("../../global.zig");
const log = std.log.scoped(.font_shaper);
@@ -90,7 +91,7 @@ pub const Shaper = struct {
unichars: std.ArrayListUnmanaged(u16),
fn init() RunState {
- return .{ .codepoints = .{}, .unichars = .{} };
+ return .{ .codepoints = .empty, .unichars = .empty };
}
fn deinit(self: *RunState, alloc: Allocator) void {
@@ -213,18 +214,18 @@ pub const Shaper = struct {
CFReleaseThread.threadMain,
.{cf_release_thread},
);
- cf_release_thr.setName("cf_release") catch {};
+ cf_release_thr.setName(global.io(), "cf_release") catch {};
return .{
.alloc = alloc,
- .cell_buf = .{},
+ .cell_buf = .empty,
.run_state = run_state,
.features = features,
.features_no_default = features_no_default,
.typesetter_attr_dict = typesetter_attr_dict,
- .cached_fonts = .{},
+ .cached_fonts = .empty,
.cached_font_grid = 0,
- .cf_release_pool = .{},
+ .cf_release_pool = .empty,
.cf_release_thread = cf_release_thread,
.cf_release_thr = cf_release_thr,
};
@@ -282,7 +283,7 @@ pub const Shaper = struct {
// Send the items. If the send succeeds then we wake up the
// thread to process the items. If the send fails then do a manual
// cleanup.
- if (self.cf_release_thread.mailbox.push(.{ .release = .{
+ if (self.cf_release_thread.mailbox.push(global.io(), .{ .release = .{
.refs = items,
.alloc = self.alloc,
} }, .{ .forever = {} }) != 0) {
@@ -360,7 +361,7 @@ pub const Shaper = struct {
// Make room for the attributed string, CTTypesetter, and CTLine.
try self.cf_release_pool.ensureUnusedCapacity(self.alloc, 4);
- const str = macos.foundation.String.createWithCharactersNoCopy(state.unichars.items);
+ const str = try macos.foundation.String.createWithCharactersNoCopy(state.unichars.items);
self.cf_release_pool.appendAssumeCapacity(str);
// Create an attributed string from our string
@@ -380,7 +381,7 @@ pub const Shaper = struct {
self.cf_release_pool.appendAssumeCapacity(typesetter);
// Create a line from the typesetter
- const line = typesetter.createLine(.{ .location = 0, .length = 0 });
+ const line = try typesetter.createLine(.{ .location = 0, .length = 0 });
self.cf_release_pool.appendAssumeCapacity(line);
// This keeps track of the current x offset (sum of advance.width) and
@@ -606,8 +607,8 @@ pub const Shaper = struct {
//
// Because of this, we only acquire the read lock to grab the
// face and set it up, then release it.
- grid.lock.lockShared();
- defer grid.lock.unlockShared();
+ grid.lock.lockSharedUncancelable(global.io());
+ defer grid.lock.unlockShared(global.io());
const face = try grid.resolver.collection.getFace(index);
const original = face.font;
@@ -842,7 +843,7 @@ test "run iterator" {
defer testdata.deinit();
{
- var t: terminal.Terminal = try .init(alloc, .{
+ var t: terminal.Terminal = try .init(testing.io, alloc, .{
.cols = 5,
.rows = 3,
});
@@ -869,7 +870,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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -892,7 +893,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(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -917,7 +918,7 @@ test "run iterator" {
// Bad ligatures
for (&[_][]const u8{ "fl", "fi", "st" }) |bad| {
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -949,7 +950,7 @@ test "run iterator: empty cells with background set" {
{
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1009,7 +1010,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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1048,7 +1049,7 @@ test "shape nerd fonts" {
buf_idx += try std.unicode.utf8Encode(' ', buf[buf_idx..]); // space
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1081,7 +1082,7 @@ test "shape inconsolata ligs" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1110,7 +1111,7 @@ test "shape inconsolata ligs" {
}
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1147,7 +1148,7 @@ test "shape monaspace ligs" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1185,7 +1186,7 @@ test "shape left-replaced lig in last run" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1223,7 +1224,7 @@ test "shape left-replaced lig in early run" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1258,7 +1259,7 @@ test "shape U+3C9 with JB Mono" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1295,7 +1296,7 @@ test "shape emoji width" {
defer testdata.deinit();
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 5, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 5, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1330,7 +1331,7 @@ test "shape emoji width long" {
defer testdata.deinit();
// Make a screen and add a long emoji sequence to it.
- var t = try terminal.Terminal.init(alloc, .{ .cols = 30, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
var page = t.screens.active.pages.pages.first.?.page();
@@ -1338,7 +1339,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 = .{ .data = 0x1F9D4 } }, // Person with beard
};
var graphemes = [_]u21{
0x1F3FB, // Light skin tone (Fitz 1-2)
@@ -1385,7 +1386,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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1424,7 +1425,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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1458,7 +1459,7 @@ test "shape with empty cells in between" {
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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1502,7 +1503,7 @@ test "shape Combining characters" {
buf_idx += try std.unicode.utf8Encode('a', 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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1552,7 +1553,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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Disable grapheme clustering
@@ -1611,7 +1612,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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1672,7 +1673,7 @@ test "shape Tai Tham letters (position.y differs from advance)" {
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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1732,7 +1733,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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1795,7 +1796,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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1866,7 +1867,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(testing.io, alloc, .{ .cols = 30, .rows = 3 });
defer t.deinit(alloc);
// Enable grapheme clustering
@@ -1924,7 +1925,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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -1962,7 +1963,7 @@ test "shape selection boundary" {
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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2067,7 +2068,7 @@ test "shape cursor boundary" {
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(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2204,7 +2205,7 @@ test "shape cursor boundary and colored emoji" {
defer testdata.deinit();
// Make a screen with some data
- var t = try terminal.Terminal.init(alloc, .{ .cols = 3, .rows = 10 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2301,7 +2302,7 @@ test "shape cell attribute change" {
// Plain >= should shape into 1 run
{
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2327,7 +2328,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(testing.io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2355,7 +2356,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(testing.io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2386,7 +2387,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(testing.io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2417,7 +2418,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(testing.io, alloc, .{ .cols = 3, .rows = 10 });
defer t.deinit(alloc);
var s = t.vtStream();
@@ -2462,7 +2463,7 @@ test "shape high plane sprite font codepoint" {
var testdata = try testShaper(alloc);
defer testdata.deinit();
- var t = try terminal.Terminal.init(alloc, .{ .cols = 10, .rows = 3 });
+ var t = try terminal.Terminal.init(testing.io, alloc, .{ .cols = 10, .rows = 3 });
defer t.deinit(alloc);
var s = t.vtStream();
diff --git a/vendor/libghostty-vt/src/font/shaper/feature.zig b/vendor/libghostty-vt/src/font/shaper/feature.zig
index 5bd73f97..c60eb049 100644
--- a/vendor/libghostty-vt/src/font/shaper/feature.zig
+++ b/vendor/libghostty-vt/src/font/shaper/feature.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const assert = @import("../../quirks.zig").inlineAssert;
const Allocator = std.mem.Allocator;
+const compat_reader = @import("../../lib/compat/reader.zig");
const log = std.log.scoped(.font_shaper);
@@ -18,9 +19,8 @@ pub const Feature = struct {
value: u32,
pub fn fromString(str: []const u8) ?Feature {
- var fbs = std.io.fixedBufferStream(str);
- const reader = fbs.reader();
- return .fromReader(reader);
+ var reader: std.Io.Reader = .fixed(str);
+ return .fromReader(&reader);
}
/// Parse a single font feature setting from a std.io.Reader, with a version
@@ -55,7 +55,7 @@ pub const Feature = struct {
done,
}).start) {
// If we're done then we skip whitespace until we see a ','.
- .done => while (true) switch (reader.readByte() catch ',') {
+ .done => while (true) switch (compat_reader.readByte(reader) catch ',') {
' ', '\t' => continue,
',' => break,
// If we see something other than whitespace or a ','
@@ -66,11 +66,11 @@ pub const Feature = struct {
// If we're fast-forwarding from an error we just wanna
// stop at the first boundary and ignore all other bytes.
.err => {
- reader.skipUntilDelimiterOrEof(',') catch {};
+ compat_reader.readSkipUntilDelimiterOrEof(reader, ',') catch {};
return null;
},
- .start => while (true) switch (reader.readByte() catch ',') {
+ .start => while (true) switch (compat_reader.readByte(reader) catch ',') {
// Ignore leading whitespace.
' ', '\t' => continue,
// Empty feature string.
@@ -97,7 +97,7 @@ pub const Feature = struct {
},
},
- .tag => while (true) switch (reader.readByte() catch ',') {
+ .tag => while (true) switch (compat_reader.readByte(reader) catch ',') {
// If the tag is interrupted by a comma it's invalid.
',' => return null,
// Ignore quote marks. This does technically ignore cases like
@@ -112,7 +112,7 @@ pub const Feature = struct {
},
},
- .space => while (true) switch (reader.readByte() catch ',') {
+ .space => while (true) switch (compat_reader.readByte(reader) catch ',') {
' ', '\t' => continue,
// Ignore quote marks since we might have a
// closing quote from the tag still ahead.
@@ -142,7 +142,7 @@ pub const Feature = struct {
else => continue :state .err,
},
- .int => while (true) switch (reader.readByte() catch ',') {
+ .int => while (true) switch (compat_reader.readByte(reader) catch ',') {
',' => break,
'0'...'9' => |byte| {
// If our value gets too big while
@@ -155,7 +155,7 @@ pub const Feature = struct {
else => continue :state .err,
},
- .bool => while (true) switch (reader.readByte() catch ',') {
+ .bool => while (true) switch (compat_reader.readByte(reader) catch ',') {
',' => return null,
'n', 'N' => {
// "ofn"
@@ -222,7 +222,7 @@ pub const Feature = struct {
/// A list of font feature settings (see `Feature` for more documentation).
pub const FeatureList = struct {
- features: std.ArrayListUnmanaged(Feature) = .{},
+ features: std.ArrayList(Feature) = .empty,
pub fn deinit(self: *FeatureList, alloc: Allocator) void {
self.features.deinit(alloc);
@@ -243,15 +243,14 @@ pub const FeatureList = struct {
alloc: Allocator,
str: []const u8,
) !void {
- var fbs = std.io.fixedBufferStream(str);
- const reader = fbs.reader();
- while (fbs.pos < fbs.buffer.len) {
- const i = fbs.pos;
- if (Feature.fromReader(reader)) |feature| {
+ var reader: std.Io.Reader = .fixed(str);
+ while (reader.seek < reader.end) {
+ const i = reader.seek;
+ if (Feature.fromReader(&reader)) |feature| {
try self.features.append(alloc, feature);
} else log.warn(
"failed to parse font feature setting: \"{s}\"",
- .{fbs.buffer[i..fbs.pos]},
+ .{reader.buffer[i..reader.seek]},
);
}
}
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();
diff --git a/vendor/libghostty-vt/src/font/shaper/run.zig b/vendor/libghostty-vt/src/font/shaper/run.zig
index 45c5d38c..9f33ba32 100644
--- a/vendor/libghostty-vt/src/font/shaper/run.zig
+++ b/vendor/libghostty-vt/src/font/shaper/run.zig
@@ -348,47 +348,34 @@ pub const RunIterator = struct {
// we just return whatever index for the cell codepoint.
if (!cell.hasGrapheme()) return primary;
- // If this is a grapheme, we need to find a font that supports
- // all of the codepoints in the grapheme.
- var candidates: std.ArrayList(font.Collection.Index) = try .initCapacity(
- alloc,
- graphemes.len + 1,
- );
- defer candidates.deinit(alloc);
- candidates.appendAssumeCapacity(primary);
+ // Try the primary font followed by the font selected for each
+ // additional codepoint until one supports the entire grapheme.
+ candidate: for (0..graphemes.len + 1) |i| {
+ const idx = if (i == 0) primary else idx: {
+ const cp = graphemes[i - 1];
- for (graphemes) |cp| {
- // Ignore Emoji ZWJs
- if (cp == 0xFE0E or cp == 0xFE0F or cp == 0x200D) continue;
+ // Ignore Emoji ZWJs
+ if (cp == 0xFE0E or cp == 0xFE0F or cp == 0x200D) continue :candidate;
- // Find a font that supports this codepoint. If none support this
- // then the whole grapheme can't be rendered so we return null.
- //
- // We explicitly do not require the additional grapheme components
- // to support the base presentation, since it is common for emoji
- // fonts to support the base emoji with emoji presentation but not
- // certain ZWJ-combined characters like the male and female signs.
- const idx = try self.opts.grid.getIndex(
- alloc,
- cp,
- style,
- null,
- ) orelse return null;
- candidates.appendAssumeCapacity(idx);
- }
+ // We explicitly do not require the additional grapheme components
+ // to support the base presentation, since it is common for emoji
+ // fonts to support the base emoji with emoji presentation but not
+ // certain ZWJ-combined characters like the male and female signs.
+ break :idx try self.opts.grid.getIndex(
+ alloc,
+ cp,
+ style,
+ null,
+ ) orelse return null;
+ };
- // We need to find a candidate that has ALL of our codepoints
- for (candidates.items) |idx| {
if (!self.opts.grid.hasCodepoint(idx, primary_cp, presentation)) continue;
for (graphemes) |cp| {
// Ignore Emoji ZWJs
if (cp == 0xFE0E or cp == 0xFE0F or cp == 0x200D) continue;
- if (!self.opts.grid.hasCodepoint(idx, cp, null)) break;
- } else {
- // If the while completed, then we have a candidate that
- // supports all of our codepoints.
- return idx;
+ if (!self.opts.grid.hasCodepoint(idx, cp, null)) continue :candidate;
}
+ return idx;
}
return null;