diff --git a/src/main.rs b/src/main.rs index 13c787d..022a0b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,15 @@ async fn main() -> AppResult<()> { tui.init()?; + // Run the app, but always restore the terminal afterwards so a failure + // does not leave the user's terminal in raw mode. Prioritize the run + // error so a failing exit() does not mask the real cause. + let result = run(&mut tui, config).await; + let exit_result = tui.exit(); + result.and(exit_result) +} + +async fn run(tui: &mut Tui>, config: Arc) -> AppResult<()> { let mut app = App::new(config.clone(), tui.events.sender.clone()).await?; while app.running { @@ -145,6 +154,5 @@ async fn main() -> AppResult<()> { } } - tui.exit()?; Ok(()) }