From 61a64093e4c083b004d1f95c8c4d2f10cac5132e Mon Sep 17 00:00:00 2001 From: Amanda Liem Date: Tue, 25 Nov 2025 20:00:43 +0000 Subject: [PATCH] fix: show cursor on program exit Signed-off-by: Amanda Liem --- src/main.rs | 14 +++++++++++++- src/tui/mod.rs | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 3cc1452..2f7db99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,8 +46,21 @@ struct Args { path: String, } +/// Guard that ensures term settings are restored upon program exit +struct CleanupGuard; + +impl Drop for CleanupGuard { + fn drop(&mut self) { + tui::cleanup(); + } +} + #[tokio::main] async fn main() -> Result<()> { + // Create cleanup guard - will automatically reset term settings + // on program exit, even on panic and error + let _cleanup = CleanupGuard; + // Parse arguments let args = Args::parse(); @@ -93,7 +106,6 @@ async fn main() -> Result<()> { _ = terminal_events(&mut events, status.clone()) => {} } - ratatui::restore(); Ok(()) } diff --git a/src/tui/mod.rs b/src/tui/mod.rs index f723f11..f2120a8 100644 --- a/src/tui/mod.rs +++ b/src/tui/mod.rs @@ -6,6 +6,13 @@ pub use throbbing::Throbbing; use std::sync::{LazyLock, Mutex}; +use crossterm::{cursor, execute}; use ratatui::DefaultTerminal; pub static TERMINAL: LazyLock> = LazyLock::new(|| ratatui::init().into()); + +/// Cleanup function to restore terminal state +pub fn cleanup() { + ratatui::restore(); + let _ = execute!(std::io::stdout(), cursor::Show); +}