Compare commits

..

6 Commits

Author SHA1 Message Date
01dd14fa62 Merge branch 'development' into staging 2025-09-11 17:41:38 -04:00
1a94332ef8 Moving Workflow
Moving all work over to staging to accomodate workflow going forward.

Reviewed-on: #4
2025-09-11 17:39:20 -04:00
a5d57b58e3 Merge pull request 'Static UI' (#3) from wesley/add-widgets into development
Reviewed-on: #3
2025-09-11 17:21:16 -04:00
8ec710988b Static UI
Got a basic static UI layout setup. Just needs to be plugged up with
actual logic to animate. Maybe new frames to follow.
2025-09-11 17:18:48 -04:00
13a728abf7 Merge pull request 'Non Blocking Events' (#2) from wesley/non-blocking-events into development
Reviewed-on: #2
2025-09-09 23:04:45 -04:00
59608ce5f2 Non Blocking Events
Changed how we process events by polling first to see if there are
events to process. This keeps the app real-time and not hanging waiting
for keypress.
2025-09-09 23:01:31 -04:00
2 changed files with 38 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
use crossterm::event::{self, Event};
use std::error::Error;
use crossterm::event::{self, Event, KeyCode};
use std::{error::Error, time::Duration};
pub mod cli;
pub mod pomodoro;
@@ -8,13 +8,35 @@ pub mod ui;
use ui::draw_ui;
pub fn run() -> Result<(), Box<dyn Error>> {
let mut keep_running;
let mut terminal = ratatui::init();
loop {
draw_ui(&mut terminal)?;
if matches!(event::read().expect("failed to read event"), Event::Key(_)) {
keep_running = process_events()?;
if !keep_running {
break;
}
}
ratatui::restore();
Ok(())
}
fn process_events() -> Result<bool, Box<dyn Error>> {
if !event::poll(Duration::from_secs(0))? {
return Ok(true);
}
if let Event::Key(key) = event::read()? {
return Ok(handle_key(key.code));
}
Ok(true)
}
fn handle_key(code: KeyCode) -> bool {
if let KeyCode::Char('q') = code {
return false;
}
true
}

View File

@@ -7,7 +7,7 @@ use ratatui::{
Constraint::{Length, Min, Percentage},
Layout,
},
widgets::{Block, Borders},
widgets::{Block, Borders, Gauge},
};
pub fn draw_ui<B: ratatui::backend::Backend>(
@@ -31,16 +31,24 @@ fn draw(frame: &mut Frame) {
let timer_layout = Layout::vertical([Percentage(65), Percentage(35)]);
let [pomodoro_area, utilities_area] = timer_layout.areas(app_area);
let pomodoro_block = Block::bordered().title("Pomodoro");
let timer_label = format!("{}:{} / 25:00", 17, 32);
let timer_ratio = (17 * 60 + 32) as f64 / (25 * 60) as f64;
let pomodoro_timer = Gauge::default()
.block(Block::bordered().title("Pomodoro"))
.label(timer_label)
.ratio(timer_ratio);
frame.render_widget(pomodoro_block, pomodoro_area);
frame.render_widget(pomodoro_timer, pomodoro_area);
let utilities_layout = Layout::horizontal([Percentage(75), Percentage(25)]);
let [pomodori, controls] = utilities_layout.areas(utilities_area);
let pomodori_block = Block::bordered().title("Pomodori");
let pomodori_completed = Gauge::default()
.block(Block::bordered().title("Pomodori"))
.label("3 / 4")
.ratio(0.75);
let controls_block = Block::bordered().title("Controls");
frame.render_widget(pomodori_block, pomodori);
frame.render_widget(pomodori_completed, pomodori);
frame.render_widget(controls_block, controls);
}