summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Sam Atman2025-12-23 11:04:01 -0500
committerGravatar Sam Atman2025-12-23 11:04:01 -0500
commit9f725580a2b6c93825edeff27f06951f57bcc237 (patch)
tree9fe23343f03718ac1e224cdf589390c8e3424bcf
parentFix #74: Check for characters before popping in wrap (diff)
downloadzg-9f725580a2b6c93825edeff27f06951f57bcc237.tar.gz
zg-9f725580a2b6c93825edeff27f06951f57bcc237.tar.xz
zg-9f725580a2b6c93825edeff27f06951f57bcc237.zip
Use width 2 when skin tone modifier detected
Fix: #82
-rw-r--r--README.md2
-rw-r--r--build.zig.zon2
-rw-r--r--src/DisplayWidth.zig5
3 files changed, 7 insertions, 2 deletions
diff --git a/README.md b/README.md
index c2db6e2..6ba456f 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ You first need to add zg as a dependency in your `build.zig.zon` file. In your
19Zig project's root directory, run: 19Zig project's root directory, run:
20 20
21```plain 21```plain
22zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.2.tar.gz 22zig fetch --save https://codeberg.org/atman/zg/archive/v0.15.3.tar.gz
23``` 23```
24 24
25Then instantiate the dependency in your `build.zig`: 25Then 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.