mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
output panics for simpler diagnosis
This commit is contained in:
parent
35f4555b2d
commit
5936757538
1 changed files with 16 additions and 4 deletions
20
src/main.rs
20
src/main.rs
|
|
@ -54,11 +54,9 @@ fn main() -> Result<()> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
enable_raw_mode()?;
|
||||
io::stdout().execute(EnterAlternateScreen)?;
|
||||
setup_terminal()?;
|
||||
defer! {
|
||||
io::stdout().execute(LeaveAlternateScreen).unwrap();
|
||||
disable_raw_mode().unwrap();
|
||||
shutdown_terminal().expect("shutdown failed");
|
||||
}
|
||||
|
||||
set_panic_handlers();
|
||||
|
|
@ -118,6 +116,18 @@ fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn setup_terminal() -> Result<()> {
|
||||
enable_raw_mode()?;
|
||||
io::stdout().execute(EnterAlternateScreen)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn shutdown_terminal() -> Result<()> {
|
||||
io::stdout().execute(LeaveAlternateScreen)?;
|
||||
disable_raw_mode()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw<B: Backend>(
|
||||
terminal: &mut Terminal<B>,
|
||||
app: &mut App,
|
||||
|
|
@ -202,6 +212,8 @@ fn set_panic_handlers() {
|
|||
panic::set_hook(Box::new(|e| {
|
||||
let backtrace = Backtrace::new();
|
||||
error!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
|
||||
shutdown_terminal().expect("shutdown failed inside panic");
|
||||
eprintln!("panic: {:?}\ntrace:\n{:?}", e, backtrace);
|
||||
}));
|
||||
|
||||
// global threadpool
|
||||
|
|
|
|||
Loading…
Reference in a new issue