mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 13:39:06 +00:00
actually, use both
This commit is contained in:
parent
2d485d6b34
commit
2f57befcd2
@ -17,4 +17,5 @@ keywords = ["ascii", "table"]
|
|||||||
colorful = "0.2"
|
colorful = "0.2"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
unicode-segmentation = "1.7.1"
|
||||||
unicode-width = "0.1.8"
|
unicode-width = "0.1.8"
|
||||||
|
@ -58,6 +58,7 @@ mod test;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
use unicode_width::UnicodeWidthStr;
|
use unicode_width::UnicodeWidthStr;
|
||||||
|
|
||||||
const SE: &str = "┌";
|
const SE: &str = "┌";
|
||||||
@ -398,7 +399,8 @@ impl SmartString {
|
|||||||
fn char_len(&self) -> usize {
|
fn char_len(&self) -> usize {
|
||||||
self.fragments.iter()
|
self.fragments.iter()
|
||||||
.filter(|(visible, _)| *visible)
|
.filter(|(visible, _)| *visible)
|
||||||
.map(|(_, string)| UnicodeWidthStr::width(string.as_str()))
|
.map(|(_, string)| UnicodeSegmentation::graphemes(string.as_str(), true)
|
||||||
|
.map(|x| if UnicodeWidthStr::width(x) > 1 { 2 } else { 1 }).sum::<usize>())
|
||||||
.sum()
|
.sum()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,12 +335,12 @@ fn show_one_character_for_header2() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cube_with_partial_content() {
|
fn cube_with_partial_content() {
|
||||||
let config = cube_config();
|
let config = cube_config();
|
||||||
let input: Vec<&[&str]> = vec![&["1", "2", "😞"], &["4", "5"], &["7"]];
|
let input: Vec<&[&str]> = vec![&["1", "2", "😞"], &["4", "5", "👩🔬"], &["7"]];
|
||||||
let expected = "┌───┬───┬────┐\n\
|
let expected = "┌───┬───┬────┐\n\
|
||||||
│ a │ b │ c │\n\
|
│ a │ b │ c │\n\
|
||||||
├───┼───┼────┤\n\
|
├───┼───┼────┤\n\
|
||||||
│ 1 │ 2 │ 😞 │\n\
|
│ 1 │ 2 │ 😞 │\n\
|
||||||
│ 4 │ 5 │ │\n\
|
│ 4 │ 5 │ 👩🔬 │\n\
|
||||||
│ 7 │ │ │\n\
|
│ 7 │ │ │\n\
|
||||||
└───┴───┴────┘\n";
|
└───┴───┴────┘\n";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user