Skip to content

Commit

Permalink
Use the display width for unicode
Browse files Browse the repository at this point in the history
Currently, TV doesn't format currently some double width unicode chars.
Use the unicode-width crate so that we can get the correct display width
for the unicode string.
  • Loading branch information
38 committed Dec 4, 2023
1 parent 365aac2 commit 0fdfc61
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ serde = { version = "1.0", features = ["derive"] }
structopt = "0.3.21"
toml = "0.5"
unicode-truncate = "0.2.0"
unicode-width = "0.1.11"
3 changes: 2 additions & 1 deletion src/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use itertools::Itertools;
use lazy_static::lazy_static;
use regex::Regex;
use std::str::FromStr;
use unicode_width::UnicodeWidthStr;
use unicode_truncate::UnicodeTruncateStr;

mod sigfig;
Expand Down Expand Up @@ -182,7 +183,7 @@ pub fn format_strings(

string.push_str(&" ".repeat(max_fract - fract));
}
let len = string.chars().count();
let len = UnicodeWidthStr::width(string.as_str());
// the string and its length
(string, len)
})
Expand Down

0 comments on commit 0fdfc61

Please sign in to comment.