mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'tui/newline_in_trace' into 'master'
enable TUI to actually handle newline character. See merge request veloren/veloren!2282
This commit is contained in:
commit
276dd2f26c
@ -32,11 +32,19 @@ impl<'a> Write for TuiLog<'a> {
|
|||||||
|
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
let mut span = Span::raw("");
|
let mut span = Span::raw("");
|
||||||
|
let mut lines = Vec::new();
|
||||||
|
|
||||||
for out in line.ansi_parse() {
|
for out in line.ansi_parse() {
|
||||||
match out {
|
match out {
|
||||||
Output::TextBlock(text) => {
|
Output::TextBlock(text) => {
|
||||||
span.content = format!("{}{}", span.content.to_owned(), text).into()
|
// search for newlines
|
||||||
|
for t in text.split_inclusive('\n') {
|
||||||
|
span.content.to_mut().push_str(&t);
|
||||||
|
if t.ends_with('\n') && span.content.len() != 0 {
|
||||||
|
spans.push(std::mem::replace(&mut span, Span::raw("")));
|
||||||
|
lines.push(std::mem::take(&mut spans));
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Output::Escape(seq) => {
|
Output::Escape(seq) => {
|
||||||
if span.content.len() != 0 {
|
if span.content.len() != 0 {
|
||||||
@ -79,8 +87,12 @@ impl<'a> Write for TuiLog<'a> {
|
|||||||
if span.content.len() != 0 {
|
if span.content.len() != 0 {
|
||||||
spans.push(span);
|
spans.push(span);
|
||||||
}
|
}
|
||||||
|
if !spans.is_empty() {
|
||||||
|
lines.push(spans);
|
||||||
|
}
|
||||||
|
|
||||||
self.inner.lock().unwrap().lines.push(Spans(spans));
|
let mut lines = lines.into_iter().map(Spans).collect::<Vec<_>>();
|
||||||
|
self.inner.lock().unwrap().lines.append(&mut lines);
|
||||||
|
|
||||||
Ok(buf.len())
|
Ok(buf.len())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user