Measure text width using Unicode segmentation

This commit is contained in:
Arne Keller 2021-03-28 14:29:33 +02:00
parent 37f6f7e8fb
commit 73cc36ce71
2 changed files with 7 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "ascii_table"
version = "3.0.2"
version = "4.0.0-alpha"
authors = ["Gerrit Viljoen <red.striker@protonmail.com>"]
license = "MIT"
edition = "2018"
@ -15,3 +15,6 @@ keywords = ["ascii", "table"]
[dev-dependencies]
colorful = "0.2"
[dependencies]
unicode-segmentation = "1.7.1"

View File

@ -58,6 +58,8 @@ mod test;
use std::collections::BTreeMap;
use std::fmt::Display;
use unicode_segmentation::UnicodeSegmentation;
const SE: &str = "";
const NW: &str = "";
const SW: &str = "";
@ -396,7 +398,7 @@ impl SmartString {
fn char_len(&self) -> usize {
self.fragments.iter()
.filter(|(visible, _)| *visible)
.map(|(_, string)| string.chars().count())
.map(|(_, string)| UnicodeSegmentation::graphemes(string.as_str(), true).count())
.sum()
}