Stream the report to the terminal as the writer generates it #5
1 changed files with 5 additions and 4 deletions
|
|
@ -178,7 +178,6 @@ async fn write_report(
|
||||||
drop(spinner);
|
drop(spinner);
|
||||||
|
|
||||||
let mut report = String::new();
|
let mut report = String::new();
|
||||||
let stdout = std::io::stdout();
|
|
||||||
|
|
||||||
while let Some(chunk) = response_stream.next().await {
|
while let Some(chunk) = response_stream.next().await {
|
||||||
match chunk? {
|
match chunk? {
|
||||||
|
|
@ -187,9 +186,11 @@ async fn write_report(
|
||||||
..
|
..
|
||||||
})) => {
|
})) => {
|
||||||
report.push_str(&text);
|
report.push_str(&text);
|
||||||
let mut handle = stdout.lock();
|
// Terminal stdout is line-buffered, so a flush is needed here —
|
||||||
write!(handle, "{text}")?;
|
// otherwise a chunk without a trailing newline sits in the
|
||||||
handle.flush()?;
|
// buffer instead of appearing as it streams in.
|
||||||
|
print!("{text}");
|
||||||
|
std::io::stdout().flush()?;
|
||||||
}
|
}
|
||||||
_ => continue,
|
_ => continue,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue