mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
Measure text width using Unicode segmentation
This commit is contained in:
parent
37f6f7e8fb
commit
73cc36ce71
@ -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"
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user