aboutsummaryrefslogtreecommitdiff
path: root/src/pomo/mod.rs
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 21:02:45 +0530
committerSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 21:02:45 +0530
commitbb66e0f10c86f3b2e5a3a8c20d910c4df8d05ac7 (patch)
treea5907978eec8d26184ed4817cb844da111d944e1 /src/pomo/mod.rs
parent8f4d471f3b3a6d25b0ba3d3c2b9abbdce7d20312 (diff)
downloadpomoru-bb66e0f10c86f3b2e5a3a8c20d910c4df8d05ac7.tar.xz
pomoru-bb66e0f10c86f3b2e5a3a8c20d910c4df8d05ac7.zip
idiomatic rust
Diffstat (limited to 'src/pomo/mod.rs')
-rw-r--r--src/pomo/mod.rs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs
new file mode 100644
index 0000000..7759877
--- /dev/null
+++ b/src/pomo/mod.rs
@@ -0,0 +1,41 @@
+pub mod state;
+pub mod ui;
+
+use crate::pomo::state::Pomo;
+use crossterm::{
+ event::{self, Event, KeyCode},
+ execute,
+ terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
+};
+use ratatui::prelude::*;
+use std::io;
+use std::time::Duration;
+
+impl Pomo {
+ pub fn run(&mut self) -> io::Result<()> {
+ enable_raw_mode()?;
+ let mut stdout = io::stdout();
+ execute!(stdout, EnterAlternateScreen)?;
+ let backend = CrosstermBackend::new(stdout);
+ let mut terminal = Terminal::new(backend)?;
+
+ while !self.should_quit {
+ terminal.draw(|f| ui::render(f, self))?;
+
+ if event::poll(Duration::from_millis(250))? {
+ if let Event::Key(key) = event::read()? {
+ match key.code {
+ KeyCode::Char('q') => self.should_quit = true,
+ KeyCode::Char(' ') => self.toggle_timer(),
+ _ => {}
+ }
+ }
+ }
+ self.tick();
+ }
+
+ disable_raw_mode()?;
+ execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
+ Ok(())
+ }
+}