From fb2cab5aeefad229246306efc9db3a224347e633 Mon Sep 17 00:00:00 2001 From: Jacob Sandlund Date: Sun, 27 Jul 2025 18:25:05 -0400 Subject: [PATCH] Using uucode in a few places where it's easy. --- build.zig.zon | 4 ++-- src/build/SharedDeps.zig | 8 ++++---- src/font/CodepointResolver.zig | 4 ++-- src/font/shaper/web_canvas.zig | 6 +++--- src/global.zig | 6 ------ src/renderer/cell.zig | 7 +++++-- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/build.zig.zon b/build.zig.zon index addfacb16..6cd2201e0 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -42,8 +42,8 @@ .lazy = true, }, .uucode = .{ - .url = "https://github.com/jacobsandlund/uucode/archive/fdcd8582f050e3054091d3ce3c60bf7a78bc8830.tar.gz", - .hash = "uucode-0.0.0-ZZjBPpnZOgCLQD3BsYbQ4N6dGqR3CRKlOngOBB3YEU_j", + .url = "https://github.com/jacobsandlund/uucode/archive/539c710408cda93d2fa28825d67cb5685d963fc1.tar.gz", + .hash = "uucode-0.0.0-ZZjBPpz5OgBrcQOasHVZYLtDHcLPx9al7RH4QXJZ8XCK", }, .zig_wayland = .{ // codeberg ifreund/zig-wayland diff --git a/src/build/SharedDeps.zig b/src/build/SharedDeps.zig index 543c87df2..8875c98a7 100644 --- a/src/build/SharedDeps.zig +++ b/src/build/SharedDeps.zig @@ -34,10 +34,10 @@ pub fn init(b: *std.Build, cfg: *const Config) !SharedDeps { \\ \\pub const configs = [_]types.TableConfig{ \\ .override(&config.default, .{ - \\ .fields = &.{"case_folding_simple"}, - \\ }), - \\ .override(&config.default, .{ - \\ .fields = &.{"alphabetic","lowercase","uppercase"}, + \\ .fields = &.{ + \\ "general_category", + \\ "has_emoji_presentation", + \\ }, \\ }), \\}; \\ diff --git a/src/font/CodepointResolver.zig b/src/font/CodepointResolver.zig index ba74065ab..ec318abe5 100644 --- a/src/font/CodepointResolver.zig +++ b/src/font/CodepointResolver.zig @@ -13,7 +13,7 @@ const CodepointResolver = @This(); const std = @import("std"); const Allocator = std.mem.Allocator; -const ziglyph = @import("ziglyph"); +const uucode = @import("uucode"); const font = @import("main.zig"); const Atlas = font.Atlas; const CodepointMap = font.CodepointMap; @@ -150,7 +150,7 @@ pub fn getIndex( // we'll do this multiple times if we recurse, but this is a cached function // call higher up (GroupCache) so this should be rare. const p_mode: Collection.PresentationMode = if (p) |v| .{ .explicit = v } else .{ - .default = if (ziglyph.emoji.isEmojiPresentation(@intCast(cp))) + .default = if (uucode.hasEmojiPresentation(@intCast(cp))) .emoji else .text, diff --git a/src/font/shaper/web_canvas.zig b/src/font/shaper/web_canvas.zig index 4ed4b7db6..e0f0e1a00 100644 --- a/src/font/shaper/web_canvas.zig +++ b/src/font/shaper/web_canvas.zig @@ -1,9 +1,9 @@ const std = @import("std"); const assert = std.debug.assert; const Allocator = std.mem.Allocator; -const ziglyph = @import("ziglyph"); const font = @import("../main.zig"); const terminal = @import("../../terminal/main.zig"); +const unicode = @import("../../unicode/main.zig"); const log = std.log.scoped(.font_shaper); @@ -111,7 +111,7 @@ pub const Shaper = struct { // font ligatures. However, we do support grapheme clustering. // This means we can render things like skin tone emoji but // we can't render things like single glyph "=>". - var break_state: u3 = 0; + var break_state: unicode.GraphemeBreakState = .{}; var cp1: u21 = @intCast(codepoints[0]); var start: usize = 0; @@ -126,7 +126,7 @@ pub const Shaper = struct { const cp2: u21 = @intCast(codepoints[i]); defer cp1 = cp2; - break :blk ziglyph.graphemeBreak( + break :blk unicode.graphemeBreak( cp1, cp2, &break_state, diff --git a/src/global.zig b/src/global.zig index 6d0aa655d..e68ec7f74 100644 --- a/src/global.zig +++ b/src/global.zig @@ -10,7 +10,6 @@ const oni = @import("oniguruma"); const crash = @import("crash/main.zig"); const renderer = @import("renderer.zig"); const apprt = @import("apprt.zig"); -const uucode = @import("uucode"); /// We export the xev backend we want to use so that the rest of /// Ghostty can import this once and have access to the proper @@ -55,11 +54,6 @@ pub const GlobalState = struct { // std.log.err("[global init time] start={}us duration={}ns", .{ start_micro, end.since(start) / std.time.ns_per_us }); // } - std.log.err("XXX Uucode testing: {d}, {}\n", .{ - uucode.case_folding_simple(65), - uucode.alphabetic(97), - }); - // Initialize ourself to nothing so we don't have any extra state. // IMPORTANT: this MUST be initialized before any log output because // the log function uses the global state. diff --git a/src/renderer/cell.zig b/src/renderer/cell.zig index b1ce4523c..d72e5965c 100644 --- a/src/renderer/cell.zig +++ b/src/renderer/cell.zig @@ -2,6 +2,7 @@ const std = @import("std"); const Allocator = std.mem.Allocator; const assert = std.debug.assert; const ziglyph = @import("ziglyph"); +const uucode = @import("uucode"); const font = @import("../font/main.zig"); const terminal = @import("../terminal/main.zig"); const renderer = @import("../renderer.zig"); @@ -235,7 +236,8 @@ pub fn constraintWidth(cell_pin: terminal.Pin) u2 { const cell = cell_pin.rowAndCell().cell; const cp = cell.codepoint(); - if (!ziglyph.general_category.isPrivateUse(cp) and + // If not a Co (Private Use) and not a Dingbats, use grid width. + if (uucode.generalCategory(cp) != .Co and !ziglyph.blocks.isDingbats(cp)) { return cell.gridWidth(); @@ -259,7 +261,8 @@ pub fn constraintWidth(cell_pin: terminal.Pin) u2 { // We consider powerline glyphs whitespace. if (isPowerline(prev_cp)) break :prev; - if (ziglyph.general_category.isPrivateUse(prev_cp)) { + // If it's Private Use (Co) use 1 as the width. + if (uucode.generalCategory(prev_cp) == .Co) { return 1; } }