summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar atman2025-12-24 01:37:15 +0100
committerGravatar atman2025-12-24 01:37:15 +0100
commitd9f596626e8ec05a9f3e47f7bc83aedd5bd2f989 (patch)
tree9fe23343f03718ac1e224cdf589390c8e3424bcf /src
parentFix #74: Check for characters before popping in wrap (diff)
parentUse width 2 when skin tone modifier detected (diff)
downloadzg-d9f596626e8ec05a9f3e47f7bc83aedd5bd2f989.tar.gz
zg-d9f596626e8ec05a9f3e47f7bc83aedd5bd2f989.tar.xz
zg-d9f596626e8ec05a9f3e47f7bc83aedd5bd2f989.zip
Merge pull request 'Use width 2 when skin tone modifier detected' (#96) from wide-diverse-emoji into masterHEADv0.15.4master
Reviewed-on: https://codeberg.org/atman/zg/pulls/96
Diffstat (limited to 'src')
-rw-r--r--src/DisplayWidth.zig5
1 files changed, 5 insertions, 0 deletions
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 {
126 // emoji text sequence. 126 // emoji text sequence.
127 if (ncp.code == 0xFE0E) w = 1; 127 if (ncp.code == 0xFE0E) w = 1;
128 if (ncp.code == 0xFE0F) w = 2; 128 if (ncp.code == 0xFE0F) w = 2;
129 // Skin tones
130 if (0x1F3FB <= ncp.code and ncp.code <= 0x1F3FF) w = 2;
129 } 131 }
130 132
131 // Only adding width of first non-zero-width code point. 133 // Only adding width of first non-zero-width code point.
@@ -201,6 +203,9 @@ test "strWidth" {
201 try testing.expectEqual(@as(usize, 9), dw.strWidth("Ẓ̌á̲l͔̝̞̄̑͌g̖̘̘̔̔͢͞͝o̪̔T̢̙̫̈̍͞e̬͈͕͌̏͑x̺̍ṭ̓̓ͅ")); 203 try testing.expectEqual(@as(usize, 9), dw.strWidth("Ẓ̌á̲l͔̝̞̄̑͌g̖̘̘̔̔͢͞͝o̪̔T̢̙̫̈̍͞e̬͈͕͌̏͑x̺̍ṭ̓̓ͅ"));
202 try testing.expectEqual(@as(usize, 17), dw.strWidth("슬라바 우크라이나")); 204 try testing.expectEqual(@as(usize, 17), dw.strWidth("슬라바 우크라이나"));
203 try testing.expectEqual(@as(usize, 1), dw.strWidth("\u{378}")); 205 try testing.expectEqual(@as(usize, 1), dw.strWidth("\u{378}"));
206
207 // https://codeberg.org/atman/zg/issues/82
208 try testing.expectEqual(@as(usize, 12), dw.strWidth("✍️✍🏻✍🏼✍🏽✍🏾✍🏿"));
204} 209}
205 210
206/// centers `str` in a new string of width `total_width` (in display cells) using `pad` as padding. 211/// centers `str` in a new string of width `total_width` (in display cells) using `pad` as padding.