Otherwise the threaded line renderer will interfere with genuine program output.
Unified · Split
| @@ -85,7 +85,7 @@ pub mod pretty { · 84 unmodified lines | ||
| 85 | 85 | enum Event<T> { |
| 86 | 86 | UiDone, |
| 87 | 87 | ComputationFailed, |
| 88 | − ComputationDone(Result<T>), | |
| 88 | + ComputationDone(Result<T>, Vec<u8>), | |
| 89 | 89 | } |
| 90 | 90 | use crate::shared::{self, STANDARD_RANGE}; |
| 91 | 91 | let (tx, rx) = std::sync::mpsc::sync_channel::<Event<T>>(1); |
| @@ -103,11 +103,12 @@ pub mod pretty { · 11 unmodified lines | ||
| 103 | 103 | // LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever. |
| 104 | 104 | // `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash. |
| 105 | 105 | let join_handle = std::thread::spawn(move || { |
| 106 | + let mut out = Vec::<u8>::new(); | |
| 106 | 107 | 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()) | |
| 108 | 109 | })); |
| 109 | 110 | match res { |
| 110 | − Ok(res) => tx.send(Event::ComputationDone(res)).ok(), | |
| 111 | + Ok(res) => tx.send(Event::ComputationDone(res, out)).ok(), | |
| 111 | 112 | Err(err) => { |
| 112 | 113 | tx.send(Event::ComputationFailed).ok(); |
| 113 | 114 | std::panic::resume_unwind(err) |
| @@ -120,9 +121,10 @@ pub mod pretty { · 6 unmodified lines | ||
| 120 | 121 | drop(join_handle); |
| 121 | 122 | Err(anyhow::anyhow!("Operation cancelled by user")) |
| 122 | 123 | } |
| 123 | − Event::ComputationDone(res) => { | |
| 124 | + Event::ComputationDone(res, out) => { | |
| 124 | 125 | ui_handle.shutdown_and_wait(); |
| 125 | 126 | join_handle.join().ok(); |
| 127 | + std::io::Write::write_all(&mut stdout(), &out)?; | |
| 126 | 128 | res |
| 127 | 129 | } |
| 128 | 130 | Event::ComputationFailed => match join_handle.join() { |