diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-19 01:23:29 +0530 |
|---|---|---|
| committer | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-19 01:23:29 +0530 |
| commit | 2e1032f34c3180720289d264869655206a3548a8 (patch) | |
| tree | 8a245e121695ef738f47efb8dd30d5ba078e7ec0 /src/pomo | |
| parent | a77a5fccd060c608f3539bcb0eee6fd008e4d1f1 (diff) | |
| download | pomoru-2e1032f34c3180720289d264869655206a3548a8.tar.xz pomoru-2e1032f34c3180720289d264869655206a3548a8.zip | |
add timer editing and smart quitting using q
q now doesn't close the app, instead it closes the current screen opened and only closes the app when on main timer screen
Diffstat (limited to 'src/pomo')
| -rw-r--r-- | src/pomo/mod.rs | 43 | ||||
| -rw-r--r-- | src/pomo/state.rs | 13 | ||||
| -rw-r--r-- | src/pomo/ui.rs | 9 |
3 files changed, 53 insertions, 12 deletions
diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs index 62aef7a..1d38ed2 100644 --- a/src/pomo/mod.rs +++ b/src/pomo/mod.rs @@ -1,7 +1,7 @@ pub mod state; pub mod ui; -use crate::pomo::state::{Pomo, AppScreen, InputMode, Task}; +use crate::pomo::state::{Pomo, AppScreen, InputMode, Task, SessionMode}; use crossterm::{ event::{self, Event, KeyCode}, execute, @@ -48,7 +48,27 @@ impl Pomo { fn handle_key(&mut self, key: event::KeyEvent) { match self.input_mode { InputMode::Normal => match (self.screen, key.code) { - (_, KeyCode::Char('q')) => self.should_quit = true, + (AppScreen::Tasks, KeyCode::Char('q')) => self.screen = AppScreen::Timer, + (AppScreen::Timer, KeyCode::Char('q')) => self.should_quit = true, + + (AppScreen::Timer, KeyCode::Tab) => { + if !self.is_running { + self.mode = match self.mode { + SessionMode::Work => SessionMode::ShortBreak, + SessionMode::ShortBreak => SessionMode::LongBreak, + SessionMode::LongBreak => SessionMode::Work, + }; + self.reset_timer_to_mode(); + } + } + + (AppScreen::Timer, KeyCode::Char('e')) => { + if !self.is_running { + self.input_mode = InputMode::TimerEdit; + self.input_buffer = (self.time_remaining.as_secs() / 60).to_string(); + } + } + (AppScreen::Timer, KeyCode::Char('t')) => self.screen = AppScreen::Tasks, (AppScreen::Timer, KeyCode::Char(' ')) => self.is_running = !self.is_running, (AppScreen::Timer, KeyCode::Char('r')) => self.time_remaining = self.work_time, @@ -70,8 +90,25 @@ impl Pomo { KeyCode::Enter => { if !self.input_buffer.is_empty() { match self.input_mode { + InputMode::TimerEdit => { + if let Ok(mins) = self.input_buffer.parse::<u64>() { + let new_dur = Duration::from_secs(mins * 60); + match self.mode { + SessionMode::Work => self.work_time = new_dur, + SessionMode::ShortBreak => self.short_break_time = new_dur, + SessionMode::LongBreak => self.long_break_time = new_dur, + } + self.time_remaining = new_dur; + self.total_duration = new_dur; + } + } + InputMode::Insert => self.tasks.push(Task { title: self.input_buffer.clone(), is_done: false }), - InputMode::Edit => if let Some(i) = self.task_state.selected() { self.tasks[i].title = self.input_buffer.clone(); } + + InputMode::Edit => if let Some(i) = self.task_state.selected() { + self.tasks[i].title = self.input_buffer.clone(); + } + _ => {} } } diff --git a/src/pomo/state.rs b/src/pomo/state.rs index fe74473..305a300 100644 --- a/src/pomo/state.rs +++ b/src/pomo/state.rs @@ -8,7 +8,7 @@ pub enum SessionMode { Work, ShortBreak, LongBreak } pub enum AppScreen { Timer, Tasks } #[derive(PartialEq, Clone, Copy)] -pub enum InputMode { Normal, Insert, Edit } +pub enum InputMode { Normal, Insert, Edit, TimerEdit } pub struct Task { pub title: String, @@ -84,9 +84,12 @@ impl Pomo { } } - pub fn get_progress(&self) -> f64 { - if self.total_duration.as_secs() == 0 { return 0.0; } - let elapsed = self.total_duration.as_secs_f64() - self.time_remaining.as_secs_f64(); - (elapsed / self.total_duration.as_secs_f64()).clamp(0.0, 1.0) + pub fn reset_timer_to_mode(&mut self) { + self.time_remaining = match self.mode { + SessionMode::Work => self.work_time, + SessionMode::ShortBreak => self.short_break_time, + SessionMode::LongBreak => self.long_break_time, + }; + self.total_duration = self.time_remaining; } } diff --git a/src/pomo/ui.rs b/src/pomo/ui.rs index 642c3b7..327f031 100644 --- a/src/pomo/ui.rs +++ b/src/pomo/ui.rs @@ -25,7 +25,7 @@ pub fn render(f: &mut Frame, app: &mut Pomo) { AppScreen::Tasks => render_task_screen(f, app), } - if let InputMode::Insert | InputMode::Edit = app.input_mode { + if let InputMode::Insert | InputMode::Edit | InputMode::TimerEdit = app.input_mode { render_input_modal(f, app); } } @@ -65,7 +65,7 @@ fn render_timer_screen(f: &mut Frame, app: &Pomo, area: Rect) { render_session_dots(f, app, chunks[4]); - let footer = "↑ +1 min • space pause • r reset • s skip • t tasks"; + let footer = "tab session • e edit time • space pause • r reset • q quit"; f.render_widget( Paragraph::new(footer).alignment(Alignment::Center).style(Style::default().fg(MOCHA_OVERLAY0)), chunks[6] @@ -158,8 +158,9 @@ pub fn render_input_modal(f: &mut Frame, app: &Pomo) { f.render_widget(Clear, area); let title = match app.input_mode { - InputMode::Insert => " New Task ", - InputMode::Edit => " Edit Task ", + InputMode::Insert => " New Task ", + InputMode::Edit => " Edit Task ", + InputMode::TimerEdit => " Set Minutes ", _ => " Input " }; |