Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 57ca045

Browse files
committed
fix: Collect all stdout messages in line renderer as well (#215)
Otherwise the threaded line renderer will interfere with genuine program output.
1 parent e4514a8 commit 57ca045

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/shared.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub mod pretty {
8585
enum Event<T> {
8686
UiDone,
8787
ComputationFailed,
88-
ComputationDone(Result<T>),
88+
ComputationDone(Result<T>, Vec<u8>),
8989
}
9090
use crate::shared::{self, STANDARD_RANGE};
9191
let (tx, rx) = std::sync::mpsc::sync_channel::<Event<T>>(1);
@@ -103,11 +103,12 @@ pub mod pretty {
103103
// LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.
104104
// `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.
105105
let join_handle = std::thread::spawn(move || {
106+
let mut out = Vec::<u8>::new();
106107
let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
107-
run(Some(sub_progress), &mut stdout(), &mut stderr())
108+
run(Some(sub_progress), &mut out, &mut stderr())
108109
}));
109110
match res {
110-
Ok(res) => tx.send(Event::ComputationDone(res)).ok(),
111+
Ok(res) => tx.send(Event::ComputationDone(res, out)).ok(),
111112
Err(err) => {
112113
tx.send(Event::ComputationFailed).ok();
113114
std::panic::resume_unwind(err)
@@ -120,9 +121,10 @@ pub mod pretty {
120121
drop(join_handle);
121122
Err(anyhow::anyhow!("Operation cancelled by user"))
122123
}
123-
Event::ComputationDone(res) => {
124+
Event::ComputationDone(res, out) => {
124125
ui_handle.shutdown_and_wait();
125126
join_handle.join().ok();
127+
std::io::Write::write_all(&mut stdout(), &out)?;
126128
res
127129
}
128130
Event::ComputationFailed => match join_handle.join() {

0 commit comments

Comments
 (0)