summaryrefslogtreecommitdiff
path: root/src/DisplayWidth.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/DisplayWidth.zig')
-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.