diff options
| author | 2025-12-24 01:37:15 +0100 | |
|---|---|---|
| committer | 2025-12-24 01:37:15 +0100 | |
| commit | d9f596626e8ec05a9f3e47f7bc83aedd5bd2f989 (patch) | |
| tree | 9fe23343f03718ac1e224cdf589390c8e3424bcf | |
| parent | Fix #74: Check for characters before popping in wrap (diff) | |
| parent | Use width 2 when skin tone modifier detected (diff) | |
| download | zg-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
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | build.zig.zon | 2 | ||||
| -rw-r--r-- | src/DisplayWidth.zig | 5 |
3 files changed, 7 insertions, 2 deletions
| @@ -19,7 +19,7 @@ You first need to add zg as a dependency in your `build.zig.zon` file. In your | |||
| 19 | Zig project's root directory, run: | 19 | Zig project's root directory, run: |
| 20 | 20 | ||
| 21 | ```plain | 21 | ```plain |
| 22 | zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.2.tar.gz | 22 | zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.3.tar.gz |
| 23 | ``` | 23 | ``` |
| 24 | 24 | ||
| 25 | Then instantiate the dependency in your `build.zig`: | 25 | 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 @@ | |||
| 1 | .{ | 1 | .{ |
| 2 | .name = .zg, | 2 | .name = .zg, |
| 3 | .version = "0.15.2", | 3 | .version = "0.15.3", |
| 4 | .minimum_zig_version = "0.15.2", | 4 | .minimum_zig_version = "0.15.2", |
| 5 | .fingerprint = 0x47df7778dc946aa0, | 5 | .fingerprint = 0x47df7778dc946aa0, |
| 6 | 6 | ||
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. |