diff options
| author | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 17:34:15 +0530 |
|---|---|---|
| committer | Saiyed Shizain <saiyedshizain@gmail.com> | 2026-01-18 17:34:15 +0530 |
| commit | cde182d44fe4dcaa3d206ceb5cf093f74de6c85e (patch) | |
| tree | a54f3c265116a8f17aa1977db7b135fcabc4ba69 | |
| parent | d79abb6f44c6ecf2bc08da875f8aa8bad2c334ad (diff) | |
| download | pomoru-cde182d44fe4dcaa3d206ceb5cf093f74de6c85e.tar.xz pomoru-cde182d44fe4dcaa3d206ceb5cf093f74de6c85e.zip | |
add a simple countdown logic
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/pomo.rs | 27 |
2 files changed, 32 insertions, 1 deletions
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"); + } +} |