From 9f725580a2b6c93825edeff27f06951f57bcc237 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Tue, 23 Dec 2025 11:04:01 -0500 Subject: Use width 2 when skin tone modifier detected Fix: #82 --- README.md | 2 +- build.zig.zon | 2 +- src/DisplayWidth.zig | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c2db6e2..6ba456f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You first need to add zg as a dependency in your `build.zig.zon` file. In your Zig project's root directory, run: ```plain -zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.2.tar.gz +zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.3.tar.gz ``` Then instantiate the dependency in your `build.zig`: diff --git a/build.zig.zon b/build.zig.zon index c160bd9..0308457 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,6 +1,6 @@ .{ .name = .zg, - .version = "0.15.2", + .version = "0.15.3", .minimum_zig_version = "0.15.2", .fingerprint = 0x47df7778dc946aa0, diff --git a/src/DisplayWidth.zig b/src/DisplayWidth.zig index d15dbae..9919a55 100644 --- a/src/DisplayWidth.zig +++ b/src/DisplayWidth.zig @@ -126,6 +126,8 @@ pub fn strWidth(dw: DisplayWidth, str: []const u8) usize { // emoji text sequence. if (ncp.code == 0xFE0E) w = 1; if (ncp.code == 0xFE0F) w = 2; + // Skin tones + if (0x1F3FB <= ncp.code and ncp.code <= 0x1F3FF) w = 2; } // Only adding width of first non-zero-width code point. @@ -201,6 +203,9 @@ test "strWidth" { try testing.expectEqual(@as(usize, 9), dw.strWidth("Ẓ̌á̲l͔̝̞̄̑͌g̖̘̘̔̔͢͞͝o̪̔T̢̙̫̈̍͞e̬͈͕͌̏͑x̺̍ṭ̓̓ͅ")); try testing.expectEqual(@as(usize, 17), dw.strWidth("슬라바 우크라이나")); try testing.expectEqual(@as(usize, 1), dw.strWidth("\u{378}")); + + // https://codeberg.org/atman/zg/issues/82 + try testing.expectEqual(@as(usize, 12), dw.strWidth("✍️✍🏻✍🏼✍🏽✍🏾✍🏿")); } /// centers `str` in a new string of width `total_width` (in display cells) using `pad` as padding. -- cgit v1.2.3