diff options
| author | 2025-12-23 11:04:01 -0500 | |
|---|---|---|
| committer | 2025-12-23 11:04:01 -0500 | |
| commit | 9f725580a2b6c93825edeff27f06951f57bcc237 (patch) | |
| tree | 9fe23343f03718ac1e224cdf589390c8e3424bcf /src/DisplayWidth.zig | |
| parent | Fix #74: Check for characters before popping in wrap (diff) | |
| download | zg-9f725580a2b6c93825edeff27f06951f57bcc237.tar.gz zg-9f725580a2b6c93825edeff27f06951f57bcc237.tar.xz zg-9f725580a2b6c93825edeff27f06951f57bcc237.zip | |
Use width 2 when skin tone modifier detected
Fix: #82
Diffstat (limited to 'src/DisplayWidth.zig')
| -rw-r--r-- | src/DisplayWidth.zig | 5 |
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. |