Is there any way to do this? In a terminal graphics library, if an exception occurs, the exception will be flushed away before being displayed, making programming very hard to debug using this library.
impl Drop for Terminal {
fn drop(&mut self) {
self.outbuffer.write_all(&self.driver.get(DevFn::ShowCursor)).unwrap();
self.outbuffer.write_all(&self.driver.get(DevFn::Reset)).unwrap();
self.outbuffer.write_all(&self.driver.get(DevFn::Clear)).unwrap();
self.outbuffer.write_all(&self.driver.get(DevFn::ExitCa)).unwrap();
self.flush().unwrap(); // If an exception occurs, this will reclear the screen and remove the output
self.termctl.reset().unwrap();
SIGWINCH_STATUS.store(false, Ordering::SeqCst);
RUSTTY_STATUS.store(false, Ordering::SeqCst);
}
}
If I were to comment out self.flush().unwrap();
the exception would print, however the terminal would not correctly flush the screen and leave graphics present on the terminal even after the program has ended.
Is it possible to, at the beginning of the program, specify a custom buffer panic will use for writing to? Or possibly write a hacky trick to do this? That way, after the flush we can check to see if anything is inside this buffer, if so we know an exception occurred and can print it out.
Running a program that purposely crashes with an arithmetic overflow, currently the output is only
By commenting out self.flush().unwrap();
however, we're greeted with the actual exception, but a very ugly terminal now. This solution will not work as program that execute correctly still need to be flushed since no error is needed to be displayed