simplify: use print! + flush for streamed chunks, not an explicit stdout lock

print! already locks stdout per call, so the manual lock()/write!() was
extra ceremony over what the flush actually needed. Matches rig's own
cli_chatbot streaming example more closely.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Austin Schaefer 2026-08-17 12:19:08 +02:00
parent 55f4f7eeb3
commit 469b7cf8c6

View file

@ -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,
} }