From b12059ce3dc184d3fd3124531d4861af77fdb179 Mon Sep 17 00:00:00 2001 From: Stevan Freeborn <65925598+StevanFreeborn@users.noreply.github.com> Date: Wed, 22 Jul 2026 23:16:44 -0500 Subject: [PATCH] feat: allow notifications to be configurable --- src/main.rs | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index df413dd..7f379d9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -50,6 +50,7 @@ struct Termato { duration_in_secs: u32, time_remaining_in_sec: u32, show_help: bool, + enable_notifications: bool, } impl Termato { @@ -62,9 +63,15 @@ impl Termato { duration_in_secs: work_mins * SECONDS_PER_MIN, time_remaining_in_sec: work_mins * SECONDS_PER_MIN, show_help: false, + enable_notifications: false, } } + fn with_notifications(mut self, enable: bool) -> Self { + self.enable_notifications = enable; + self + } + fn toggle_running(&mut self) { self.is_running = !self.is_running; } @@ -86,9 +93,11 @@ impl Termato { self.time_remaining_in_sec -= 1; if self.time_remaining_in_sec == 0 { - match self.mode { - TimerMode::Work => send_desktop_notification("Work Done", "Time to take a break."), - TimerMode::Break => send_desktop_notification("Break Over", "Time to focus."), + if self.enable_notifications { + match self.mode { + TimerMode::Work => send_desktop_notification("Work Done", "Time to take a break."), + TimerMode::Break => send_desktop_notification("Break Over", "Time to focus."), + } } self.toggle_mode(); @@ -130,7 +139,13 @@ fn main() -> Result<(), io::Error> { let args: Vec = std::env::args().collect(); if args.iter().any(|arg| arg == "-h" || arg == "--help") { - println!("Usage: termato [work_minutes] [break_minutes]"); + println!("Usage: termato [options] [work_minutes] [break_minutes]"); + println!(); + println!("Options:"); + println!(" -n, --notify Enable desktop notifications"); + println!(" -h, --help Print this help message"); + println!(" -v, --version Print the version number"); + println!(); println!("Defaults: work_minutes = 25, break_minutes = 5"); return Ok(()); } @@ -146,9 +161,15 @@ fn main() -> Result<(), io::Error> { let mut terminal = Terminal::new(backend)?; let font = Toilet::smblock().unwrap(); - let work_mins = args.get(1).and_then(|s| s.parse().ok()).unwrap_or(25); - let break_mins = args.get(2).and_then(|s| s.parse().ok()).unwrap_or(5); - let mut termato = Termato::new(work_mins, break_mins); + let enable_notifications = args.iter().any(|arg| arg == "-n" || arg == "--notify"); + let positional_args: Vec<&String> = args.iter() + .skip(1) + .filter(|arg| *arg != "-n" && *arg != "--notify") + .collect(); + + let work_mins = positional_args.get(0).and_then(|s| s.parse().ok()).unwrap_or(25); + let break_mins = positional_args.get(1).and_then(|s| s.parse().ok()).unwrap_or(5); + let mut termato = Termato::new(work_mins, break_mins).with_notifications(enable_notifications); let (tx, rx) = mpsc::channel(); @@ -406,4 +427,13 @@ mod tests { assert!(!termato.show_help); } + + #[test] + fn termato_notifications_when_called_it_should_verify_opt_in_behavior() { + let result = Termato::new(25, 5); + assert!(!result.enable_notifications); + + let result = result.with_notifications(true); + assert!(result.enable_notifications); + } }