diff options
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/cell.rs | 8 | ||||
-rw-r--r-- | tests/text.rs | 4 |
3 files changed, 11 insertions, 2 deletions
@@ -12,5 +12,6 @@ keywords = ["terminal", "vt100"] license = "MIT" [dependencies] +unicode-normalization = "0.1" unicode-width = "0.1" vte = "0.3" diff --git a/src/cell.rs b/src/cell.rs index 3d2a9fa..370feb0 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -1,3 +1,5 @@ +use unicode_normalization::UnicodeNormalization as _; + #[derive(Clone, Debug, Default)] pub struct Cell { contents: String, @@ -16,6 +18,12 @@ impl Cell { pub(crate) fn append(&mut self, c: char) { self.contents.push(c); + // some fonts have combined characters but can't render combining + // characters correctly, so try to prefer precombined characters when + // possible + if !unicode_normalization::is_nfc(&self.contents) { + self.contents = self.contents.nfc().collect(); + } } pub(crate) fn reset(&mut self) { diff --git a/tests/text.rs b/tests/text.rs index 4ece65b..a328d52 100644 --- a/tests/text.rs +++ b/tests/text.rs @@ -94,9 +94,9 @@ fn combining() { screen.process("\u{0301}".as_bytes()); assert_eq!(screen.cell(0, 0).unwrap().contents(), "á"); screen.process(b"\x1b[20;20Habcdefg"); - assert_eq!(screen.window_contents(19, 19, 19, 26), "abcdefg"); + assert_eq!(screen.window_contents(19, 19, 19, 26), "abcdefg\n"); screen.process("\x1b[20;25H\u{0301}".as_bytes()); - assert_eq!(screen.window_contents(19, 19, 19, 26), "abcdéfg"); + assert_eq!(screen.window_contents(19, 19, 19, 26), "abcdéfg\n"); screen.process(b"\x1b[10;78Haaa"); assert_eq!(screen.cell(9, 79).unwrap().contents(), "a"); screen.process("\r\n\u{0301}".as_bytes()); |