unicode-display_width 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +2 -1
- data/lib/unicode/display_width/constants.rb +1 -1
- data/lib/unicode/display_width.rb +22 -43
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1886b39340f01645fd4e64d032ab1611e471e60c4dbd46e3d8867125ef45232d
|
4
|
+
data.tar.gz: dc452df48efa0f7f9cd862b0390f611df83e4dcd82c640f4faa151b05022596f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85dfef303836ba1c13271144ad24f89dbc40591d9056ee187c9ee5b7b6ff1f19d8d9ebd4e21108f78a61d2e3d3c6ce44f560005e3216cf3f8fa595466c50dfc7
|
7
|
+
data.tar.gz: eae08ff81ed83a3965820aaf09ce10fd028428adf6653807d3fb87b0c96b9ae7be757d38ffa90a8a27b39a8454e4b2694109a8aaddcc75d21d0e449ce8f7f628
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -114,10 +114,11 @@ The `emoji:` option can be used to configure which type of Emoji should be consi
|
|
114
114
|
`:all_no_vs16` | EAW (1 or 2) | 2 for all ZWJ/modifier/keycap sequences, even if they are not well-formed Emoji sequences | WezTerm
|
115
115
|
`:possible`| 2 | 2 for all possible/well-formed Emoji sequences | ?
|
116
116
|
`:rgi` | 2 | 2 for all [RGI Emoji](https://www.unicode.org/reports/tr51/#def_rgi_set) sequences | ?
|
117
|
-
`:rgi_at` | EAW (1 or 2) | 1 or 2: Like `:rgi`, but Emoji sequences starting with a default-text Emoji have
|
117
|
+
`:rgi_at` | EAW (1 or 2) | 1 or 2: Like `:rgi`, but Emoji sequences starting with a default-text Emoji have EAW | Apple Terminal
|
118
118
|
`:vs16` | 2 | 2 * number of partial Emoji (sequences never considered to represent a combined Emoji) | kitty?
|
119
119
|
`false` or `:none` | EAW (1 or 2) | No Emoji adjustments | gnome-terminal, many older terminals
|
120
120
|
|
121
|
+
- *EAW:* East Asian Width
|
121
122
|
- *RGI Emoji:* Emoji Recommended for General Interchange
|
122
123
|
- *ZWJ:* Zero-width Joiner: Codepoint `U+200D`,used in many Emoji sequences
|
123
124
|
|
@@ -30,9 +30,17 @@ module Unicode
|
|
30
30
|
rgi_at: :REGEX_INCLUDE_MQE_UQE,
|
31
31
|
possible: :REGEX_WELL_FORMED,
|
32
32
|
}
|
33
|
-
REGEX_EMOJI_BASIC_OR_KEYCAP = Regexp.union(Unicode::Emoji::REGEX_BASIC, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
|
34
|
-
REGEX_EMOJI_ALL_SEQUENCES = Regexp.union(/.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?(\u{200D}.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?)+/, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
|
35
33
|
REGEX_EMOJI_NOT_POSSIBLE = /\A[#*0-9]\z/
|
34
|
+
REGEX_EMOJI_VS16 = Regexp.union(
|
35
|
+
Regexp.compile(
|
36
|
+
Unicode::Emoji::REGEX_TEXT_PRESENTATION.source +
|
37
|
+
"(?<![#*0-9])" +
|
38
|
+
"\u{FE0F}"
|
39
|
+
),
|
40
|
+
Unicode::Emoji::REGEX_EMOJI_KEYCAP
|
41
|
+
)
|
42
|
+
REGEX_EMOJI_ALL_SEQUENCES = Regexp.union(/.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?(\u{200D}.[\u{1F3FB}-\u{1F3FF}\u{FE0F}]?)+/, Unicode::Emoji::REGEX_EMOJI_KEYCAP)
|
43
|
+
REGEX_EMOJI_ALL_SEQUENCES_AND_VS16 = Regexp.union(REGEX_EMOJI_ALL_SEQUENCES, REGEX_EMOJI_VS16)
|
36
44
|
|
37
45
|
# Returns monospace display width of string
|
38
46
|
def self.of(string, ambiguous = nil, overwrite = nil, old_options = {}, **options)
|
@@ -177,45 +185,23 @@ module Unicode
|
|
177
185
|
mode == :rgi_at,
|
178
186
|
ambiguous,
|
179
187
|
)
|
188
|
+
|
180
189
|
elsif mode == :all_no_vs16
|
181
|
-
|
190
|
+
no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES){ res += 2; "" }
|
191
|
+
[res, no_emoji_string]
|
192
|
+
|
182
193
|
elsif mode == :vs16
|
183
|
-
|
194
|
+
no_emoji_string = string.gsub(REGEX_EMOJI_VS16){ res += 2; "" }
|
195
|
+
[res, no_emoji_string]
|
196
|
+
|
184
197
|
elsif mode == :all
|
185
|
-
|
186
|
-
|
187
|
-
|
198
|
+
no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES_AND_VS16){ res += 2; "" }
|
199
|
+
[res, no_emoji_string]
|
200
|
+
|
188
201
|
else
|
189
202
|
[0, string]
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
# Ensure all explicit VS16 sequences have width 2
|
194
|
-
def self.emoji_width_basic(string)
|
195
|
-
res = 0
|
196
203
|
|
197
|
-
|
198
|
-
if basic_emoji.size >= 2 # VS16 present
|
199
|
-
res += 2
|
200
|
-
""
|
201
|
-
else
|
202
|
-
basic_emoji
|
203
|
-
end
|
204
|
-
}
|
205
|
-
|
206
|
-
[res, no_emoji_string]
|
207
|
-
end
|
208
|
-
|
209
|
-
# Use simplistic ZWJ/modifier/kecap sequence matching
|
210
|
-
def self.emoji_width_all(string)
|
211
|
-
res = 0
|
212
|
-
|
213
|
-
no_emoji_string = string.gsub(REGEX_EMOJI_ALL_SEQUENCES){
|
214
|
-
res += 2
|
215
|
-
""
|
216
|
-
}
|
217
|
-
|
218
|
-
[res, no_emoji_string]
|
204
|
+
end
|
219
205
|
end
|
220
206
|
|
221
207
|
# Match possible Emoji first, then refine
|
@@ -241,14 +227,7 @@ module Unicode
|
|
241
227
|
else
|
242
228
|
if !strict_eaw
|
243
229
|
# Ensure all explicit VS16 sequences have width 2
|
244
|
-
emoji_candidate.gsub!(
|
245
|
-
if basic_emoji.size == 2 # VS16 present
|
246
|
-
res += 2
|
247
|
-
""
|
248
|
-
else
|
249
|
-
basic_emoji
|
250
|
-
end
|
251
|
-
}
|
230
|
+
emoji_candidate.gsub!(REGEX_EMOJI_VS16){ res += 2; "" }
|
252
231
|
end
|
253
232
|
|
254
233
|
emoji_candidate
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicode-display_width
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode-emoji
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.0.4
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.0.4
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|