mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-02-01 09:34:35 +00:00
add utf8proc so we can detect unicode char width
This commit is contained in:
51
pkg/utf8proc/build.zig
Normal file
51
pkg/utf8proc/build.zig
Normal file
@@ -0,0 +1,51 @@
|
||||
const std = @import("std");
|
||||
|
||||
/// Directories with our includes.
|
||||
const root = thisDir() ++ "../../../vendor/utf8proc/";
|
||||
const include_path = root;
|
||||
|
||||
pub const include_paths = .{include_path};
|
||||
|
||||
pub const pkg = std.build.Pkg{
|
||||
.name = "utf8proc",
|
||||
.source = .{ .path = thisDir() ++ "/main.zig" },
|
||||
};
|
||||
|
||||
fn thisDir() []const u8 {
|
||||
return std.fs.path.dirname(@src().file) orelse ".";
|
||||
}
|
||||
|
||||
pub fn link(b: *std.build.Builder, step: *std.build.LibExeObjStep) !*std.build.LibExeObjStep {
|
||||
const lib = try buildLib(b, step);
|
||||
step.linkLibrary(lib);
|
||||
step.addIncludePath(include_path);
|
||||
return lib;
|
||||
}
|
||||
|
||||
pub fn buildLib(
|
||||
b: *std.build.Builder,
|
||||
step: *std.build.LibExeObjStep,
|
||||
) !*std.build.LibExeObjStep {
|
||||
const lib = b.addStaticLibrary("utf8proc", null);
|
||||
lib.setTarget(step.target);
|
||||
lib.setBuildMode(step.build_mode);
|
||||
|
||||
// Include
|
||||
lib.addIncludePath(include_path);
|
||||
|
||||
// Link
|
||||
lib.linkLibC();
|
||||
|
||||
// Compile
|
||||
var flags = std.ArrayList([]const u8).init(b.allocator);
|
||||
defer flags.deinit();
|
||||
|
||||
// C files
|
||||
lib.addCSourceFiles(srcs, flags.items);
|
||||
|
||||
return lib;
|
||||
}
|
||||
|
||||
const srcs = &.{
|
||||
root ++ "utf8proc.c",
|
||||
};
|
||||
3
pkg/utf8proc/c.zig
Normal file
3
pkg/utf8proc/c.zig
Normal file
@@ -0,0 +1,3 @@
|
||||
pub usingnamespace @cImport({
|
||||
@cInclude("utf8proc.h");
|
||||
});
|
||||
8
pkg/utf8proc/main.zig
Normal file
8
pkg/utf8proc/main.zig
Normal file
@@ -0,0 +1,8 @@
|
||||
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(u8, c.utf8proc_charwidth(@intCast(i32, codepoint)));
|
||||
}
|
||||
Reference in New Issue
Block a user