aboutsummaryrefslogtreecommitdiff
path: root/src/pomo
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 21:41:13 +0530
committerSaiyed Shizain <saiyedshizain@gmail.com>2026-01-18 21:41:13 +0530
commit4e22d4150020fa1068dcd3867d026215d5156271 (patch)
treea60321b5c5f64267814f260e0ac93c957b9ae0e9 /src/pomo
parentf885b4a05ddc047085f153bed87bb8048ca35536 (diff)
downloadpomoru-4e22d4150020fa1068dcd3867d026215d5156271.tar.xz
pomoru-4e22d4150020fa1068dcd3867d026215d5156271.zip
update ui timer, update mod and state to fix unused warnings
Diffstat (limited to 'src/pomo')
-rw-r--r--src/pomo/mod.rs17
-rw-r--r--src/pomo/state.rs20
-rw-r--r--src/pomo/ui.rs51
3 files changed, 56 insertions, 32 deletions
diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs
index 7759877..284f28a 100644
--- a/src/pomo/mod.rs
+++ b/src/pomo/mod.rs
@@ -9,7 +9,7 @@ use crossterm::{
};
use ratatui::prelude::*;
use std::io;
-use std::time::Duration;
+use std::time::{Duration, Instant}; // Fixed: Added Instant here
impl Pomo {
pub fn run(&mut self) -> io::Result<()> {
@@ -19,10 +19,17 @@ impl Pomo {
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;
+ let mut last_tick = Instant::now();
+ let tick_rate = Duration::from_millis(250);
+
while !self.should_quit {
terminal.draw(|f| ui::render(f, self))?;
- if event::poll(Duration::from_millis(250))? {
+ let timeout = tick_rate
+ .checked_sub(last_tick.elapsed())
+ .unwrap_or_else(|| Duration::from_secs(0));
+
+ if event::poll(timeout)? {
if let Event::Key(key) = event::read()? {
match key.code {
KeyCode::Char('q') => self.should_quit = true,
@@ -31,7 +38,11 @@ impl Pomo {
}
}
}
- self.tick();
+
+ if last_tick.elapsed() >= Duration::from_secs(1) {
+ self.tick();
+ last_tick = Instant::now();
+ }
}
disable_raw_mode()?;
diff --git a/src/pomo/state.rs b/src/pomo/state.rs
index 111e935..c7a3011 100644
--- a/src/pomo/state.rs
+++ b/src/pomo/state.rs
@@ -1,4 +1,5 @@
use ratatui::widgets::ListState;
+use ratatui::prelude::Color;
use std::time::Duration;
#[derive(PartialEq, Clone, Copy)]
@@ -8,6 +9,16 @@ pub enum SessionMode {
LongBreak,
}
+impl SessionMode {
+ pub fn get_color(&self) -> Color {
+ match self {
+ SessionMode::Work => Color::Cyan,
+ SessionMode::ShortBreak => Color::Green,
+ SessionMode::LongBreak => Color::Magenta,
+ }
+ }
+}
+
pub struct Task {
pub title: String,
pub is_done: bool,
@@ -24,11 +35,16 @@ pub struct Pomo {
impl Pomo {
pub fn new() -> Self {
+ let dummy_tasks = vec![
+ Task { title: "Complete Milestone 1".into(), is_done: true },
+ Task { title: "Refactor UI for Flocus look".into(), is_done: false },
+ ];
+
Self {
mode: SessionMode::Work,
time_remaining: Duration::from_secs(25 * 60),
is_running: false,
- tasks: Vec::new(),
+ tasks: dummy_tasks,
task_state: ListState::default(),
should_quit: false,
}
@@ -39,7 +55,7 @@ impl Pomo {
self.time_remaining -= Duration::from_secs(1);
} else if self.time_remaining.as_secs() == 0 {
self.is_running = false;
- // logic for switching modes will go here
+ // TODO: Add further mode switching logic
}
}
diff --git a/src/pomo/ui.rs b/src/pomo/ui.rs
index 55ba4e3..e1f1f5d 100644
--- a/src/pomo/ui.rs
+++ b/src/pomo/ui.rs
@@ -2,59 +2,57 @@ use ratatui::{
prelude::*,
widgets::*,
};
-use crate::pomo::state::{Pomo, SessionMode};
+use crate::pomo::state::Pomo;
pub fn render(f: &mut Frame, app: &mut Pomo) {
- // 1. Create a centered area.
- // We use 60% of width and 60% of height for that "isolated" feel.
- let area = centered_rect(60, 60, f.size());
+ let area = centered_rect(50, 50, f.area());
+
+ let accent_color = app.mode.get_color();
- // 2. Clear the area with a transparent background
- // Color::Reset ensures we use your terminal's background/transparency
let main_block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
- .border_style(Style::default().fg(Color::Cyan))
+ .border_style(Style::default().fg(accent_color))
.style(Style::default().bg(Color::Reset));
- // 3. Split the centered area into Timer (Top) and Todo (Bottom)
+ let inner_area = main_block.inner(area);
+ f.render_widget(main_block, area);
+
let chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
- Constraint::Percentage(40), // Timer space
- Constraint::Percentage(60), // Todo space
+ Constraint::Length(3),
+ Constraint::Min(1),
])
- .split(main_block.inner(area));
+ .split(inner_area);
- // 4. Render the Timer
+ // Timer
let timer_text = format_duration(app.time_remaining);
- let timer_color = if app.is_running { Color::Green } else { Color::Yellow };
-
let timer_para = Paragraph::new(timer_text)
.alignment(Alignment::Center)
- .style(Style::default().fg(timer_color).add_modifier(Modifier::BOLD));
+ .style(Style::default().fg(Color::White).add_modifier(Modifier::BOLD));
+
+ f.render_widget(timer_para, chunks[0]);
- // 5. Render the Todo List (Placeholder for now)
+ // Priority Tasks
let tasks: Vec<ListItem> = app.tasks
.iter()
.map(|t| {
- let symbol = if t.is_done { "󰄲 " } else { "󰄱 " };
- ListItem::new(format!("{} {}", symbol, t.title))
+ let symbol = if t.is_done { "󰄲" } else { "󰄱" };
+ ListItem::new(Line::from(vec![
+ Span::styled(format!(" {} ", symbol), Style::default().fg(accent_color)),
+ Span::raw(t.title.clone()),
+ ]))
})
.collect();
let list = List::new(tasks)
- .block(Block::default().title(" Priorities ").borders(Borders::TOP))
- .highlight_style(Style::default().add_modifier(Modifier::REVERSED))
- .highlight_symbol(">> ");
+ .highlight_style(Style::default().bg(Color::Indexed(8)).fg(Color::White))
+ .highlight_symbol(" ");
- // Final Renders
- f.render_widget(main_block, area);
- f.render_widget(timer_para, chunks[0]);
f.render_stateful_widget(list, chunks[1], &mut app.task_state);
}
-/// Helper function to center a rectangle
fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
let popup_layout = Layout::default()
.direction(Direction::Vertical)
@@ -75,10 +73,9 @@ fn centered_rect(percent_x: u16, percent_y: u16, r: Rect) -> Rect {
.split(popup_layout[1])[1]
}
-/// Helper to format Duration into MM:SS
fn format_duration(duration: std::time::Duration) -> String {
let secs = duration.as_secs();
let mins = secs / 60;
let secs = secs % 60;
- format!("\n\n{:02}:{:02}", mins, secs)
+ format!("{:02}:{:02}", mins, secs)
}