diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 23:10:21 +0530 |
|---|---|---|
| committer | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 23:10:21 +0530 |
| commit | 38d4f46a5afa8426ea62e25e8f1c825b4a49bf7f (patch) | |
| tree | 3d37a0ee2994b049e20676f21d108b40f507b1a8 /src/pomo | |
| parent | 3d773f046f4d37b52801895f79b581dbd26ff84b (diff) | |
| download | pomoru-38d4f46a5afa8426ea62e25e8f1c825b4a49bf7f.tar.xz pomoru-38d4f46a5afa8426ea62e25e8f1c825b4a49bf7f.zip | |
improve session switching & introduce task editing options
Diffstat (limited to 'src/pomo')
| -rw-r--r-- | src/pomo/state.rs | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/src/pomo/state.rs b/src/pomo/state.rs index f4a7a5e..64ceca7 100644 --- a/src/pomo/state.rs +++ b/src/pomo/state.rs @@ -9,6 +9,12 @@ pub enum SessionMode { LongBreak, } +pub enum InputMode { + Normal, + Insert, + Edit, +} + impl SessionMode { pub fn get_color(&self) -> Color { match self { @@ -26,10 +32,16 @@ pub struct Task { pub struct Pomo { pub mode: SessionMode, + pub work_time: Duration, + pub short_break_time: Duration, + pub long_break_time: Duration, pub time_remaining: Duration, pub is_running: bool, + pub break_count: u32, pub tasks: Vec<Task>, pub task_state: ListState, + pub input_mode: InputMode, + pub input_buffer: String, pub should_quit: bool, pub show_help: bool } @@ -48,31 +60,46 @@ impl Pomo { Self { mode: SessionMode::Work, - time_remaining: Duration::from_secs(25 * 60), + work_time: work, + short_break_time: Duration::from_secs(5 * 60), + long_break_time: Duration::from_secs(15 * 60), + time_remaining: work, is_running: false, - tasks: dummy_tasks, + break_count: 0, + tasks: Vec::new(), task_state: ListState::default(), + input_mode: InputMode::Normal, + input_buffer: String::new(), should_quit: false, - show_help: false + show_help: false, } } pub fn tick(&mut self) { if self.is_running && self.time_remaining.as_secs() > 0 { - self.time_remaining -= std::time::Duration::from_secs(1); + self.time_remaining -= Duration::from_secs(1); } else if self.is_running && self.time_remaining.as_secs() == 0 { self.is_running = false; - // Simple rotation: Work -> ShortBreak -> Work - match self.mode { - SessionMode::Work => { + self.transition_next_session(); + } + } + + fn transition_next_session(&mut self) { + match self.mode { + SessionMode::Work => { + self.break_count += 1; + if self.break_count % 4 == 0 { + self.mode = SessionMode::LongBreak; + self.time_remaining = self.long_break_time; + } else { self.mode = SessionMode::ShortBreak; - self.time_remaining = std::time::Duration::from_secs(5 * 60); - } - _ => { - self.mode = SessionMode::Work; - self.time_remaining = std::time::Duration::from_secs(25 * 60); + self.time_remaining = self.short_break_time; } } + _ => { + self.mode = SessionMode::Work; + self.time_remaining = self.work_time; + } } } |