mirror of
https://gitlab.com/arnekeller/ascii-table.git
synced 2024-12-04 13:39:06 +00:00
save game
This commit is contained in:
parent
c06a4aa793
commit
cc8b6b5223
29
src/lib.rs
29
src/lib.rs
@ -364,7 +364,34 @@ impl SmartString {
|
||||
// }
|
||||
// }
|
||||
// count
|
||||
Self { fragments: vec![(true, string.to_string())] }
|
||||
let string = string.to_string();
|
||||
let mut fragments = Vec::new();
|
||||
let mut visible = true;
|
||||
let mut buf = String::new();
|
||||
let mut iter = string.chars().peekable();
|
||||
|
||||
while let Some(ch) = iter.next() {
|
||||
if visible {
|
||||
if ch == '\u{1b}' && Some(&'[') == iter.peek() {
|
||||
fragments.push((visible, buf));
|
||||
visible = !visible;
|
||||
buf = String::new();
|
||||
}
|
||||
buf.push(ch);
|
||||
} else {
|
||||
if ch != '\u{1b}' && ch != '[' && ch != ';' && ch != 'm' && !('0'..'9').contains(&ch) {
|
||||
fragments.push((visible, buf));
|
||||
visible = !visible;
|
||||
buf = String::new();
|
||||
}
|
||||
buf.push(ch);
|
||||
}
|
||||
}
|
||||
if !buf.is_empty() {
|
||||
fragments.push((visible, buf));
|
||||
}
|
||||
|
||||
Self { fragments }
|
||||
}
|
||||
|
||||
fn char_len(&self) -> usize {
|
||||
|
Loading…
Reference in New Issue
Block a user