diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 22:12:25 +0530 |
|---|---|---|
| committer | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 22:12:25 +0530 |
| commit | 921e2220bdea2eb6c0e03c0bac8abe431f9698a1 (patch) | |
| tree | 4143ead206ed7c4fd0f1859ca7ba7155a842f070 /src/main.rs | |
| parent | 2a40c1bc7a1869f921c3428546f81f3f1cb26e07 (diff) | |
| download | pomoru-921e2220bdea2eb6c0e03c0bac8abe431f9698a1.tar.xz pomoru-921e2220bdea2eb6c0e03c0bac8abe431f9698a1.zip | |
add panic handler & implement tokio tick
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 1f11a9e..bd5deb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,26 @@ mod pomo; use pomo::state::Pomo; +use std::panic; +use crossterm::terminal::{disable_raw_mode, LeaveAlternateScreen}; +use crossterm::execute; -fn main() -> Result<(), Box<dyn std::error::Error>> { +fn setup_panic_hook() { + let original_hook = panic::take_hook(); + panic::set_hook(Box::new(move |panic_info| { + // Restore terminal state before exiting + let _ = disable_raw_mode(); + let mut stdout = std::io::stdout(); + let _ = execute!(stdout, LeaveAlternateScreen); + + // Call the original hook to print the error + original_hook(panic_info); + })); +} + +#[tokio::main] +async fn main() -> Result<(), Box<dyn std::error::Error>> { + setup_panic_hook(); let mut app = Pomo::new(); - app.run()?; + app.run().await?; Ok(()) } |