aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-11-23 13:17:55 -0500
committerJesse Luehrs <doy@tozt.net>2019-11-23 13:33:41 -0500
commitdf312db3c428e7e8936c5ad6846629236bcb6240 (patch)
treebb8ca39f256cf4605cacd78782f80fdbb0e82ec6
parentcd94e2ccb2272286fd0e2bc8ae67db2fba5276e5 (diff)
downloadvt100-rust-df312db3c428e7e8936c5ad6846629236bcb6240.tar.gz
vt100-rust-df312db3c428e7e8936c5ad6846629236bcb6240.zip
make unicode normalization optional
it's not always necessary or desired, and adds quite a lot to the binary size (for instance, the problem it solves is pretty much non-existent in web browsers, and wasm builds are also very sensitive to code size)
-rw-r--r--CHANGELOG.md9
-rw-r--r--Cargo.toml5
-rw-r--r--src/cell.rs13
-rw-r--r--tests/text.rs1
4 files changed, 26 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71a9d35..b4edf50 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,14 @@
# Changelog
+## Unreleased
+
+### Added
+
+* New (default-on) cargo feature `unicode-normalization` which can be disabled
+ to disable normalizing cell contents to NFC - it's a pretty small edge case,
+ and the data tables required to support it are quite large, which affects
+ size-sensitive targets like wasm
+
## [0.6.3] - 2019-11-20
### Fixed
diff --git a/Cargo.toml b/Cargo.toml
index 7ec13a4..3b79b41 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,10 +12,13 @@ keywords = ["terminal", "vt100"]
categories = ["command-line-interface", "encoding"]
license = "MIT"
+[features]
+default = ["unicode-normalization"]
+
[dependencies]
itoa = "0.4"
enumset = "0.4"
log = "0.4"
-unicode-normalization = "0.1"
+unicode-normalization = { version = "0.1", optional = true }
unicode-width = "0.1"
vte = "0.3"
diff --git a/src/cell.rs b/src/cell.rs
index 05d93be..ecc44b2 100644
--- a/src/cell.rs
+++ b/src/cell.rs
@@ -1,4 +1,3 @@
-use unicode_normalization::UnicodeNormalization as _;
use unicode_width::UnicodeWidthChar as _;
const CODEPOINTS_IN_CELL: usize = 6;
@@ -49,6 +48,18 @@ impl Cell {
self.contents[self.len()] = c;
self.len += 1;
+ self.normalize();
+ }
+
+ #[cfg(not(feature = "unicode-normalization"))]
+ #[inline]
+ fn normalize(&mut self) {}
+
+ #[cfg(feature = "unicode-normalization")]
+ #[inline]
+ fn normalize(&mut self) {
+ use unicode_normalization::UnicodeNormalization as _;
+
// some fonts have combined characters but can't render combining
// characters correctly, so try to prefer precombined characters when
// possible
diff --git a/tests/text.rs b/tests/text.rs
index 81201a1..1ad16ae 100644
--- a/tests/text.rs
+++ b/tests/text.rs
@@ -130,6 +130,7 @@ fn wide() {
);
}
+#[cfg(feature = "unicode-normalization")]
#[test]
fn combining() {
let mut parser = vt100::Parser::default();