save game

This commit is contained in:
Gerrit Viljoen 2020-05-17 12:08:36 +02:00
parent c06a4aa793
commit cc8b6b5223

View File

@ -364,7 +364,34 @@ impl SmartString {
// } // }
// } // }
// count // 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 { fn char_len(&self) -> usize {