From cde182d44fe4dcaa3d206ceb5cf093f74de6c85e Mon Sep 17 00:00:00 2001 From: Saiyed Shizain Date: Sun, 18 Jan 2026 17:34:15 +0530 Subject: add a simple countdown logic --- src/main.rs | 6 +++++- src/pomo.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/pomo.rs (limited to 'src') diff --git a/src/main.rs b/src/main.rs index e7a11a9..324d34e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ +mod pomo; +use pomo::Pomo; + fn main() { - println!("Hello, world!"); + let mut app = Pomo::new(); + app.run(); } diff --git a/src/pomo.rs b/src/pomo.rs new file mode 100644 index 0000000..a5042ef --- /dev/null +++ b/src/pomo.rs @@ -0,0 +1,27 @@ +use std::{ thread, time::Duration }; + +pub struct Pomo { + pub time_remaining: Duration, +} + +impl Pomo { + pub fn new() -> Self { + Self { + time_remaining: Duration::from_secs(25 * 60), + } + } + + pub fn tick(&mut self) { + self.time_remaining -= Duration::from_secs(1); + } + + pub fn run(&mut self) { + self.time_remaining = Duration::from_secs(10); + while self.time_remaining > Duration::from_secs(0) { + println!("{}", self.time_remaining.as_secs()); + self.tick(); + thread::sleep(Duration::from_secs(1)); + } + println!("Done"); + } +} -- cgit v1.2.3