From 2d485d6b3408ed8ef2629b6be14189a312d8c60c Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sun, 28 Mar 2021 14:40:09 +0200 Subject: [PATCH] Actually unicode_width is more suitable --- Cargo.toml | 2 +- src/lib.rs | 4 ++-- src/test.rs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9256a47..8d1c199 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,4 @@ keywords = ["ascii", "table"] colorful = "0.2" [dependencies] -unicode-segmentation = "1.7.1" +unicode-width = "0.1.8" diff --git a/src/lib.rs b/src/lib.rs index 93276d6..f4c3f04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ mod test; use std::collections::BTreeMap; use std::fmt::Display; -use unicode_segmentation::UnicodeSegmentation; +use unicode_width::UnicodeWidthStr; const SE: &str = "┌"; const NW: &str = "┘"; @@ -398,7 +398,7 @@ impl SmartString { fn char_len(&self) -> usize { self.fragments.iter() .filter(|(visible, _)| *visible) - .map(|(_, string)| UnicodeSegmentation::graphemes(string.as_str(), true).count()) + .map(|(_, string)| UnicodeWidthStr::width(string.as_str())) .sum() } diff --git a/src/test.rs b/src/test.rs index 971a222..550b9bb 100644 --- a/src/test.rs +++ b/src/test.rs @@ -335,14 +335,14 @@ fn show_one_character_for_header2() { #[test] fn cube_with_partial_content() { let config = cube_config(); - let input: Vec<&[i32]> = vec![&[1, 2, 3], &[4, 5], &[7]]; - let expected = "┌───┬───┬───┐\n\ - │ a │ b │ c │\n\ - ├───┼───┼───┤\n\ - │ 1 │ 2 │ 3 │\n\ - │ 4 │ 5 │ │\n\ - │ 7 │ │ │\n\ - └───┴───┴───┘\n"; + let input: Vec<&[&str]> = vec![&["1", "2", "😞"], &["4", "5"], &["7"]]; + let expected = "┌───┬───┬────┐\n\ + │ a │ b │ c │\n\ + ├───┼───┼────┤\n\ + │ 1 │ 2 │ 😞 │\n\ + │ 4 │ 5 │ │\n\ + │ 7 │ │ │\n\ + └───┴───┴────┘\n"; assert_eq!(expected, config.format(input)); }