From 63706d90e886f6bf85fb7111675826d70be54c70 Mon Sep 17 00:00:00 2001 From: shy Date: Fri, 9 Apr 2021 17:01:42 +0200 Subject: [PATCH] Make label available to --command. --- src/alarm.rs | 10 +++++----- src/main.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/alarm.rs b/src/alarm.rs index b0593df..7e70c06 100644 --- a/src/alarm.rs +++ b/src/alarm.rs @@ -162,9 +162,9 @@ impl AlarmRoster { pub fn check(&mut self, clock: &mut Clock, layout: &Layout, - countdown: &mut Countdown) -> Option { + countdown: &mut Countdown) -> Option<(u32, String)> { - let mut ret: Option = None; + let mut ret: Option<(u32, String)> = None; let mut index = 0; for alarm in &mut self.list { @@ -172,7 +172,7 @@ impl AlarmRoster { if !alarm.exceeded { if alarm.time <= clock.elapsed { // Found alarm to raise. - ret = Some(alarm.time); + ret = Some((alarm.time, alarm.label.clone())); alarm.exceeded = true; clock.color_index = Some(alarm.color_index); countdown.value = 0; @@ -284,7 +284,7 @@ impl AlarmRoster { } // Execute the command given on the command line. -pub fn exec_command(config: &Config, elapsed: u32) -> Option { +pub fn exec_command(config: &Config, elapsed: u32, label: String) -> Option { let mut args: Vec = Vec::new(); let time: String; @@ -298,7 +298,7 @@ pub fn exec_command(config: &Config, elapsed: u32) -> Option { // Replace every occurrence of "{}". args.reserve_exact(command.len()); for s in command { - args.push(s.replace("{}", &time)); + args.push(s.replace("{t}", &time).replace("{l}", &label)); } match Command::new(&command[0]).args(&args[1..]) diff --git a/src/main.rs b/src/main.rs index e746f46..17a1402 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,9 +34,9 @@ PARAMETERS: OPTIONS: -h, --help Show this help. -v, --version Show version information. - -e, --exec [COMMAND] Execute COMMAND on alarm. Every occurrence of {} - will be replaced by the elapsed time in (HH:)MM:SS - format. + -e, --exec [COMMAND] Execute COMMAND on alarm. Occurrences of {t} will + be replaced by the alarm time in (HH:)MM:SS format. + Occurrences of {l} by alarm label. -p, --plain Use simpler block chars. -q, --quit Quit program after last alarm. @@ -272,7 +272,7 @@ fn main() { layout.update(clock.elapsed >= 3600, clock.elapsed == 3600); // Check for exceeded alarms. - if let Some(time) = alarm_roster.check(&mut clock, &layout, &mut countdown) { + if let Some((time, label)) = alarm_roster.check(&mut clock, &layout, &mut countdown) { // Write ASCII bell code. write!(stdout, "{}", 0x07 as char).unwrap(); layout.force_redraw = true; @@ -280,7 +280,7 @@ fn main() { // Run command if configured. if config.command.is_some() { if spawned.is_none() { - spawned = exec_command(&config, time); + spawned = exec_command(&config, time, label); } else { // The last command is still running. eprintln!("Not executing command, as its predecessor is still running");