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 --- src/DisplayWidth.zig | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/DisplayWidth.zig') 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