termwiz: import widechar_width wcwidth implementation

This commit adopts the use of https://github.com/ridiculousfish/widecharwidth/
to determine the width of a character.

This allows removing a couple of other rust deps that are no longer
needed, but doesn't otherwise change the behavior.

refs: https://github.com/wez/wezterm/issues/1231
This commit is contained in:
Wez Furlong committed 2021-11-24 18:11:59 -07:00
1 parent f0f7110dfe
commit 591e1f593c
5 files changed
+1524 -20

No files matched your search

Generated
-8
View File
@@ -4052,11 +4052,9 @@ dependencies = [
"thiserror",
"ucd-trie",
"unicode-segmentation",
"unicode-width",
"varbincode",
"vtparse",
"winapi 0.3.9",
"xi-unicode",
]
[[package]]
@@ -5125,12 +5123,6 @@ dependencies = [
"nom 7.1.0",
]
[[package]]
name = "xi-unicode"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a"
[[package]]
name = "xkbcommon"
version = "0.5.0"
-2
View File
@@ -33,9 +33,7 @@ sha2 = "0.9"
terminfo = "0.7"
thiserror = "1.0"
unicode-segmentation = "1.8"
unicode-width = "0.1"
ucd-trie = "0.1"
xi-unicode = "0.3"
vtparse = { version="0.5", path="../vtparse" }
[features]
+7 -10
View File
@@ -3,11 +3,11 @@ use crate::color::{ColorAttribute, PaletteIndex};
pub use crate::emoji::Presentation;
pub use crate::escape::osc::Hyperlink;
use crate::image::ImageCell;
use crate::widechar_width::WcWidth;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::mem;
use std::sync::Arc;
use unicode_width::UnicodeWidthStr;
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
@@ -829,11 +829,16 @@ pub fn unicode_column_width(s: &str) -> usize {
/// Returns the number of cells visually occupied by a grapheme.
/// The input string must be a single grapheme.
pub fn grapheme_column_width(s: &str) -> usize {
let width = s
.chars()
.map(|c| WcWidth::from_char(c).width_unicode_9_or_later())
.max()
.unwrap_or(0);
match Presentation::for_grapheme(s) {
(_, Some(Presentation::Emoji)) => 2,
(_, Some(Presentation::Text)) => 1,
(Presentation::Emoji, None) => 2,
(Presentation::Text, None) => UnicodeWidthStr::width(s).min(2),
(Presentation::Text, None) => width.into(),
}
}
@@ -905,10 +910,6 @@ mod test {
eprintln!("foot chars");
for c in foot.chars() {
eprintln!("char: {:?}", c);
use xi_unicode::EmojiExt;
eprintln!("xi emoji: {}", c.is_emoji());
eprintln!("xi emoji_mod: {}", c.is_emoji_modifier());
eprintln!("xi emoji_mod_base: {}", c.is_emoji_modifier_base());
}
assert_eq!(unicode_column_width(foot), 2, "{} should be 2", foot);
@@ -936,10 +937,6 @@ mod test {
eprintln!("deaf_man chars");
for c in deaf_man.chars() {
eprintln!("char: {:?}", c);
use xi_unicode::EmojiExt;
eprintln!("xi emoji: {}", c.is_emoji());
eprintln!("xi emoji_mod: {}", c.is_emoji_modifier());
eprintln!("xi emoji_mod_base: {}", c.is_emoji_modifier_base());
}
assert_eq!(unicode_column_width(deaf_man), 2);
+1
View File
@@ -42,6 +42,7 @@
mod emoji;
mod emoji_presentation;
mod widechar_width;
pub mod caps;
pub mod cell;
File diff suppressed because it is too large. Load diff