From 6869d7b87756ef8e5a9b589d1bbae692376b0107 Mon Sep 17 00:00:00 2001 From: Dalton Caron Date: Sat, 27 Jun 2026 15:06:37 -0700 Subject: [PATCH 1/2] Gracefully exit terminal on error --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 13c787d..ae2d4d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,6 +35,14 @@ 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. + let result = run(&mut tui, config).await; + tui.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 +153,5 @@ async fn main() -> AppResult<()> { } } - tui.exit()?; Ok(()) } From fd25eef5013c136d50afaac1bb56ef7d0fe41bf5 Mon Sep 17 00:00:00 2001 From: Dalton Caron Date: Sat, 27 Jun 2026 15:22:19 -0700 Subject: [PATCH 2/2] Prioritize run error over exit error on shutdown --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ae2d4d9..022a0b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,10 +36,11 @@ 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. + // 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; - tui.exit()?; - result + let exit_result = tui.exit(); + result.and(exit_result) } async fn run(tui: &mut Tui>, config: Arc) -> AppResult<()> {