use split_inclusive instead

This commit is contained in:
Marcel Märtens 2021-05-11 11:34:16 +02:00
parent 863e11d5e3
commit a65ef892ca

View File

@ -36,20 +36,15 @@ impl<'a> Write for TuiLog<'a> {
for out in line.ansi_parse() { for out in line.ansi_parse() {
match out { match out {
Output::TextBlock(mut text) => { Output::TextBlock(text) => {
// search for newlines (.lines() or .split doesn't work, as this block does not // search for newlines
// need to contain one) for t in text.split_inclusive('\n') {
while let Some(newline) = text.find('\n') { span.content.to_mut().push_str(&t);
span.content.to_mut().push_str(&text[..newline]); if t.ends_with('\n') && span.content.len() != 0 {
if span.content.len() != 0 { spans.push(std::mem::replace(&mut span, Span::raw("")));
spans.push(span); lines.push(std::mem::take(&mut spans));
lines.push(spans);
spans = Vec::new();
span = Span::raw("");
} }
text = &text[newline + 1..];
} }
span.content.to_mut().push_str(text);
}, },
Output::Escape(seq) => { Output::Escape(seq) => {
if span.content.len() != 0 { if span.content.len() != 0 {