History

fix: Collect all stdout messages in line renderer as well (#215)

Otherwise the threaded line renderer will interfere with genuine program output.

Sebastian Thiel committed 4 years ago

Commit 57ca0451 parent e4514a81 file · +6 −4Browse files

Unified · Split

src/shared.rs+6−4
@@ -85,7 +85,7 @@ pub mod pretty { · 84 unmodified lines
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 { · 11 unmodified lines
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 { · 6 unmodified lines
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() {