aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 22:12:25 +0530
committerSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 22:12:25 +0530
commit921e2220bdea2eb6c0e03c0bac8abe431f9698a1 (patch)
tree4143ead206ed7c4fd0f1859ca7ba7155a842f070 /src/main.rs
parent2a40c1bc7a1869f921c3428546f81f3f1cb26e07 (diff)
downloadpomoru-921e2220bdea2eb6c0e03c0bac8abe431f9698a1.tar.xz
pomoru-921e2220bdea2eb6c0e03c0bac8abe431f9698a1.zip
add panic handler & implement tokio tick
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs22
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(())
}