mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #837 from mitchellh/utf8proc-kill
replace utf8proc with ziglyph
This commit is contained in:
13
build.zig
13
build.zig
@ -667,10 +667,6 @@ fn addDeps(
|
|||||||
.target = step.target,
|
.target = step.target,
|
||||||
.optimize = step.optimize,
|
.optimize = step.optimize,
|
||||||
});
|
});
|
||||||
const utf8proc_dep = b.dependency("utf8proc", .{
|
|
||||||
.target = step.target,
|
|
||||||
.optimize = step.optimize,
|
|
||||||
});
|
|
||||||
const harfbuzz_dep = b.dependency("harfbuzz", .{
|
const harfbuzz_dep = b.dependency("harfbuzz", .{
|
||||||
.target = step.target,
|
.target = step.target,
|
||||||
.optimize = step.optimize,
|
.optimize = step.optimize,
|
||||||
@ -687,12 +683,8 @@ fn addDeps(
|
|||||||
// We link this package but its a no-op since Tracy
|
// We link this package but its a no-op since Tracy
|
||||||
// never actually WORKS with wasm.
|
// never actually WORKS with wasm.
|
||||||
step.addModule("tracy", tracy_dep.module("tracy"));
|
step.addModule("tracy", tracy_dep.module("tracy"));
|
||||||
step.addModule("utf8proc", utf8proc_dep.module("utf8proc"));
|
|
||||||
step.addModule("zig-js", js_dep.module("zig-js"));
|
step.addModule("zig-js", js_dep.module("zig-js"));
|
||||||
|
|
||||||
// utf8proc
|
|
||||||
step.linkLibrary(utf8proc_dep.artifact("utf8proc"));
|
|
||||||
|
|
||||||
return static_libs;
|
return static_libs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -729,7 +721,6 @@ fn addDeps(
|
|||||||
step.addModule("harfbuzz", harfbuzz_dep.module("harfbuzz"));
|
step.addModule("harfbuzz", harfbuzz_dep.module("harfbuzz"));
|
||||||
step.addModule("xev", libxev_dep.module("xev"));
|
step.addModule("xev", libxev_dep.module("xev"));
|
||||||
step.addModule("pixman", pixman_dep.module("pixman"));
|
step.addModule("pixman", pixman_dep.module("pixman"));
|
||||||
step.addModule("utf8proc", utf8proc_dep.module("utf8proc"));
|
|
||||||
step.addModule("ziglyph", ziglyph_dep.module("ziglyph"));
|
step.addModule("ziglyph", ziglyph_dep.module("ziglyph"));
|
||||||
|
|
||||||
// Mac Stuff
|
// Mac Stuff
|
||||||
@ -752,10 +743,6 @@ fn addDeps(
|
|||||||
try static_libs.append(tracy_dep.artifact("tracy").getEmittedBin());
|
try static_libs.append(tracy_dep.artifact("tracy").getEmittedBin());
|
||||||
}
|
}
|
||||||
|
|
||||||
// utf8proc
|
|
||||||
step.linkLibrary(utf8proc_dep.artifact("utf8proc"));
|
|
||||||
try static_libs.append(utf8proc_dep.artifact("utf8proc").getEmittedBin());
|
|
||||||
|
|
||||||
// Dynamic link
|
// Dynamic link
|
||||||
if (!static) {
|
if (!static) {
|
||||||
step.addIncludePath(freetype_dep.path(""));
|
step.addIncludePath(freetype_dep.path(""));
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
.hash = "1220319b42fbc0116f3f198343256018e9f1da9483cef259201afe4ebab0ce0d8f6a",
|
.hash = "1220319b42fbc0116f3f198343256018e9f1da9483cef259201afe4ebab0ce0d8f6a",
|
||||||
},
|
},
|
||||||
.ziglyph = .{
|
.ziglyph = .{
|
||||||
.url = "https://codeberg.org/dude_the_builder/ziglyph/archive/v0.11.1.tar.gz",
|
.url = "https://codeberg.org/dude_the_builder/ziglyph/archive/v0.11.2.tar.gz",
|
||||||
.hash = "1220dee955839b7f267c1bb21e0ee60888c08f408c30f0722b243cabcc8cce8b7508",
|
.hash = "1220c45655c6f107ca129a558ace8fb3c57afcd7290694c8c4a2d74df40f8c9a8937",
|
||||||
},
|
},
|
||||||
|
|
||||||
// C libs
|
// C libs
|
||||||
@ -34,7 +34,6 @@
|
|||||||
.macos = .{ .path = "./pkg/macos" },
|
.macos = .{ .path = "./pkg/macos" },
|
||||||
.pixman = .{ .path = "./pkg/pixman" },
|
.pixman = .{ .path = "./pkg/pixman" },
|
||||||
.tracy = .{ .path = "./pkg/tracy" },
|
.tracy = .{ .path = "./pkg/tracy" },
|
||||||
.utf8proc = .{ .path = "./pkg/utf8proc" },
|
|
||||||
.zlib = .{ .path = "./pkg/zlib" },
|
.zlib = .{ .path = "./pkg/zlib" },
|
||||||
|
|
||||||
// System headers
|
// System headers
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
|
|
||||||
pub fn build(b: *std.Build) !void {
|
|
||||||
const target = b.standardTargetOptions(.{});
|
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
|
||||||
|
|
||||||
_ = b.addModule("utf8proc", .{ .source_file = .{ .path = "main.zig" } });
|
|
||||||
|
|
||||||
const upstream = b.dependency("utf8proc", .{});
|
|
||||||
const lib = b.addStaticLibrary(.{
|
|
||||||
.name = "utf8proc",
|
|
||||||
.target = target,
|
|
||||||
.optimize = optimize,
|
|
||||||
});
|
|
||||||
lib.linkLibC();
|
|
||||||
lib.addIncludePath(upstream.path(""));
|
|
||||||
lib.installHeadersDirectoryOptions(.{
|
|
||||||
.source_dir = upstream.path(""),
|
|
||||||
.install_dir = .header,
|
|
||||||
.install_subdir = "",
|
|
||||||
.include_extensions = &.{".h"},
|
|
||||||
});
|
|
||||||
|
|
||||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
|
||||||
try flags.append("-DUTF8PROC_EXPORTS");
|
|
||||||
defer flags.deinit();
|
|
||||||
for (srcs) |src| {
|
|
||||||
lib.addCSourceFile(.{
|
|
||||||
.file = upstream.path(src),
|
|
||||||
.flags = flags.items,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
b.installArtifact(lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
const srcs: []const []const u8 = &.{
|
|
||||||
"utf8proc.c",
|
|
||||||
};
|
|
@ -1,10 +0,0 @@
|
|||||||
.{
|
|
||||||
.name = "utf8proc",
|
|
||||||
.version = "2.8.0",
|
|
||||||
.dependencies = .{
|
|
||||||
.utf8proc = .{
|
|
||||||
.url = "https://github.com/JuliaStrings/utf8proc/archive/refs/tags/v2.8.0.tar.gz",
|
|
||||||
.hash = "1220056ce228a8c58f1fa66ab778f5c8965e62f720c1d30603c7d534cb7d8a605ad7",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
pub usingnamespace @cImport({
|
|
||||||
@cInclude("utf8proc.h");
|
|
||||||
});
|
|
@ -1,20 +0,0 @@
|
|||||||
pub const c = @import("c.zig");
|
|
||||||
|
|
||||||
/// Given a codepoint, return a character width analogous to `wcwidth(codepoint)`,
|
|
||||||
/// except that a width of 0 is returned for non-printable codepoints
|
|
||||||
/// instead of -1 as in `wcwidth`.
|
|
||||||
pub fn charwidth(codepoint: u21) u8 {
|
|
||||||
return @intCast(c.utf8proc_charwidth(@intCast(codepoint)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Given a pair of consecutive codepoints, return whether a grapheme break is
|
|
||||||
/// permitted between them (as defined by the extended grapheme clusters in UAX#29).
|
|
||||||
pub fn graphemeBreakStateful(cp1: u21, cp2: u21, state: *i32) bool {
|
|
||||||
return c.utf8proc_grapheme_break_stateful(
|
|
||||||
@intCast(cp1),
|
|
||||||
@intCast(cp2),
|
|
||||||
state,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
test {}
|
|
@ -1,7 +1,7 @@
|
|||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const utf8proc = @import("utf8proc");
|
const ziglyph = @import("ziglyph");
|
||||||
const font = @import("../main.zig");
|
const font = @import("../main.zig");
|
||||||
const terminal = @import("../../terminal/main.zig");
|
const terminal = @import("../../terminal/main.zig");
|
||||||
|
|
||||||
@ -113,7 +113,7 @@ pub const Shaper = struct {
|
|||||||
// font ligatures. However, we do support grapheme clustering.
|
// font ligatures. However, we do support grapheme clustering.
|
||||||
// This means we can render things like skin tone emoji but
|
// This means we can render things like skin tone emoji but
|
||||||
// we can't render things like single glyph "=>".
|
// we can't render things like single glyph "=>".
|
||||||
var break_state: i32 = 0;
|
var break_state: u3 = 0;
|
||||||
var cp1: u21 = @intCast(codepoints[0]);
|
var cp1: u21 = @intCast(codepoints[0]);
|
||||||
|
|
||||||
var start: usize = 0;
|
var start: usize = 0;
|
||||||
@ -128,7 +128,7 @@ pub const Shaper = struct {
|
|||||||
const cp2: u21 = @intCast(codepoints[i]);
|
const cp2: u21 = @intCast(codepoints[i]);
|
||||||
defer cp1 = cp2;
|
defer cp1 = cp2;
|
||||||
|
|
||||||
break :blk utf8proc.graphemeBreakStateful(
|
break :blk ziglyph.graphemeBreak(
|
||||||
cp1,
|
cp1,
|
||||||
cp2,
|
cp2,
|
||||||
&break_state,
|
&break_state,
|
||||||
|
@ -54,7 +54,7 @@ const builtin = @import("builtin");
|
|||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
|
|
||||||
const utf8proc = @import("utf8proc");
|
const ziglyph = @import("ziglyph");
|
||||||
const trace = @import("tracy").trace;
|
const trace = @import("tracy").trace;
|
||||||
const ansi = @import("ansi.zig");
|
const ansi = @import("ansi.zig");
|
||||||
const modes = @import("modes.zig");
|
const modes = @import("modes.zig");
|
||||||
@ -2795,12 +2795,12 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
// If we have a previous cell, we check if we're part of a grapheme.
|
// If we have a previous cell, we check if we're part of a grapheme.
|
||||||
if (grapheme.cell) |prev_cell| {
|
if (grapheme.cell) |prev_cell| {
|
||||||
const grapheme_break = brk: {
|
const grapheme_break = brk: {
|
||||||
var state: i32 = 0;
|
var state: u3 = 0;
|
||||||
var cp1 = @as(u21, @intCast(prev_cell.char));
|
var cp1 = @as(u21, @intCast(prev_cell.char));
|
||||||
if (prev_cell.attrs.grapheme) {
|
if (prev_cell.attrs.grapheme) {
|
||||||
var it = row.codepointIterator(grapheme.x);
|
var it = row.codepointIterator(grapheme.x);
|
||||||
while (it.next()) |cp2| {
|
while (it.next()) |cp2| {
|
||||||
assert(!utf8proc.graphemeBreakStateful(
|
assert(!ziglyph.graphemeBreak(
|
||||||
cp1,
|
cp1,
|
||||||
cp2,
|
cp2,
|
||||||
&state,
|
&state,
|
||||||
@ -2810,7 +2810,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break :brk utf8proc.graphemeBreakStateful(cp1, c, &state);
|
break :brk ziglyph.graphemeBreak(cp1, c, &state);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!grapheme_break) {
|
if (!grapheme_break) {
|
||||||
@ -2820,7 +2820,7 @@ pub fn testWriteString(self: *Screen, text: []const u8) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const width = utf8proc.charwidth(c);
|
const width: usize = @intCast(@max(0, ziglyph.display_width.codePointWidth(c, .half)));
|
||||||
//log.warn("c={x} width={}", .{ c, width });
|
//log.warn("c={x} width={}", .{ c, width });
|
||||||
|
|
||||||
// Zero-width are attached as grapheme data.
|
// Zero-width are attached as grapheme data.
|
||||||
|
@ -6,7 +6,7 @@ const Terminal = @This();
|
|||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const utf8proc = @import("utf8proc");
|
const ziglyph = @import("ziglyph");
|
||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
@ -682,12 +682,12 @@ pub fn print(self: *Terminal, c: u21) !void {
|
|||||||
if (prev.cell.char == 0) break :grapheme;
|
if (prev.cell.char == 0) break :grapheme;
|
||||||
|
|
||||||
const grapheme_break = brk: {
|
const grapheme_break = brk: {
|
||||||
var state: i32 = 0;
|
var state: u3 = 0;
|
||||||
var cp1 = @as(u21, @intCast(prev.cell.char));
|
var cp1: u21 = @intCast(prev.cell.char);
|
||||||
if (prev.cell.attrs.grapheme) {
|
if (prev.cell.attrs.grapheme) {
|
||||||
var it = row.codepointIterator(prev.x);
|
var it = row.codepointIterator(prev.x);
|
||||||
while (it.next()) |cp2| {
|
while (it.next()) |cp2| {
|
||||||
assert(!utf8proc.graphemeBreakStateful(
|
assert(!ziglyph.graphemeBreak(
|
||||||
cp1,
|
cp1,
|
||||||
cp2,
|
cp2,
|
||||||
&state,
|
&state,
|
||||||
@ -697,7 +697,7 @@ pub fn print(self: *Terminal, c: u21) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break :brk utf8proc.graphemeBreakStateful(cp1, c, &state);
|
break :brk ziglyph.graphemeBreak(cp1, c, &state);
|
||||||
};
|
};
|
||||||
|
|
||||||
// If we can NOT break, this means that "c" is part of a grapheme
|
// If we can NOT break, this means that "c" is part of a grapheme
|
||||||
@ -764,7 +764,7 @@ pub fn print(self: *Terminal, c: u21) !void {
|
|||||||
|
|
||||||
// Determine the width of this character so we can handle
|
// Determine the width of this character so we can handle
|
||||||
// non-single-width characters properly.
|
// non-single-width characters properly.
|
||||||
const width = utf8proc.charwidth(c);
|
const width: usize = @intCast(@max(0, ziglyph.display_width.codePointWidth(c, .half)));
|
||||||
assert(width <= 2);
|
assert(width <= 2);
|
||||||
// log.debug("c={x} width={}", .{ c, width });
|
// log.debug("c={x} width={}", .{ c, width });
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user