diff --git a/src/main.rs b/src/main.rs index 7f379d9..31842c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,5 @@ use std::{ - io::{self, stdout}, - sync::mpsc, - thread, - time::Duration, + io::{self, stdout}, sync::{Arc, Mutex, mpsc}, thread, time::Duration, }; use crossterm::{ @@ -51,6 +48,7 @@ struct Termato { time_remaining_in_sec: u32, show_help: bool, enable_notifications: bool, + enable_visualizer: bool, } impl Termato { @@ -64,6 +62,7 @@ impl Termato { time_remaining_in_sec: work_mins * SECONDS_PER_MIN, show_help: false, enable_notifications: false, + enable_visualizer: false, } } @@ -72,6 +71,11 @@ impl Termato { self } + fn with_visualizer(mut self, enable: bool) -> Self { + self.enable_visualizer = enable; + self + } + fn toggle_running(&mut self) { self.is_running = !self.is_running; } @@ -145,6 +149,7 @@ fn main() -> Result<(), io::Error> { println!(" -n, --notify Enable desktop notifications"); println!(" -h, --help Print this help message"); println!(" -v, --version Print the version number"); + println!(" -z, --visualizer Display visualizer of playing audio"); println!(); println!("Defaults: work_minutes = 25, break_minutes = 5"); return Ok(()); @@ -161,15 +166,21 @@ fn main() -> Result<(), io::Error> { let mut terminal = Terminal::new(backend)?; let font = Toilet::smblock().unwrap(); + let enable_visualizer = args.iter().any(|arg| arg == "-z" || arg == "--visualizer"); 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") + .filter(|arg| { + *arg != "-n" && *arg != "--notify" && *arg != "-vx" && *arg != "--visualizer" + }) .collect(); - let work_mins = positional_args.get(0).and_then(|s| s.parse().ok()).unwrap_or(25); + let work_mins = positional_args.first().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 mut termato = Termato::new(work_mins, break_mins) + .with_notifications(enable_notifications) + .with_visualizer(enable_visualizer); let (tx, rx) = mpsc::channel(); @@ -297,7 +308,7 @@ mod tests { use super::*; #[test] - fn termato_when_called_it_should_return_expected_starting_state() { + fn termato_new_when_called_it_should_return_expected_starting_state() { let result = Termato::new(25, 5); assert_eq!(result.work_mins, 25); @@ -306,6 +317,9 @@ mod tests { assert!(!result.is_running); assert_eq!(result.duration_in_secs, 1500); assert_eq!(result.time_remaining_in_sec, 1500); + assert!(!result.show_help); + assert!(!result.enable_notifications); + assert!(!result.enable_visualizer); } #[test]