mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 21:49:08 +00:00
save game
This commit is contained in:
parent
d930d332d0
commit
42746ffdc3
@ -13,8 +13,5 @@ readme = "readme.md"
|
|||||||
categories = ["command-line-interface"]
|
categories = ["command-line-interface"]
|
||||||
keywords = ["ascii", "table"]
|
keywords = ["ascii", "table"]
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
regex = "1"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
colorful = "0.2"
|
colorful = "0.2"
|
||||||
|
19
src/lib.rs
19
src/lib.rs
@ -233,7 +233,24 @@ impl AsciiTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn count_characters(&self, cell: &str) -> usize {
|
fn count_characters(&self, cell: &str) -> usize {
|
||||||
cell.chars().count()
|
let mut count = 0;
|
||||||
|
let mut block = false;
|
||||||
|
let mut iter = cell.chars().peekable();
|
||||||
|
while let Some(ch) = iter.next() {
|
||||||
|
if block {
|
||||||
|
if ch != '\u{1b}' && ch != '[' && ch != ';' && ch != 'm' && !('0'..'9').contains(&ch) {
|
||||||
|
block = false;
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ch == '\u{1b}' && Some(&'[') == iter.peek() {
|
||||||
|
block = true;
|
||||||
|
} else {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
count
|
||||||
}
|
}
|
||||||
|
|
||||||
fn truncate_widths(&self, mut widths: Vec<usize>) -> Vec<usize> {
|
fn truncate_widths(&self, mut widths: Vec<usize>) -> Vec<usize> {
|
||||||
|
Loading…
Reference in New Issue
Block a user