Make label available to --command.
This commit is contained in:
parent
299ef7fbe6
commit
63706d90e8
2 changed files with 10 additions and 10 deletions
10
src/alarm.rs
10
src/alarm.rs
|
@ -162,9 +162,9 @@ impl AlarmRoster {
|
||||||
pub fn check(&mut self,
|
pub fn check(&mut self,
|
||||||
clock: &mut Clock,
|
clock: &mut Clock,
|
||||||
layout: &Layout,
|
layout: &Layout,
|
||||||
countdown: &mut Countdown) -> Option<u32> {
|
countdown: &mut Countdown) -> Option<(u32, String)> {
|
||||||
|
|
||||||
let mut ret: Option<u32> = None;
|
let mut ret: Option<(u32, String)> = None;
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
|
||||||
for alarm in &mut self.list {
|
for alarm in &mut self.list {
|
||||||
|
@ -172,7 +172,7 @@ impl AlarmRoster {
|
||||||
if !alarm.exceeded {
|
if !alarm.exceeded {
|
||||||
if alarm.time <= clock.elapsed {
|
if alarm.time <= clock.elapsed {
|
||||||
// Found alarm to raise.
|
// Found alarm to raise.
|
||||||
ret = Some(alarm.time);
|
ret = Some((alarm.time, alarm.label.clone()));
|
||||||
alarm.exceeded = true;
|
alarm.exceeded = true;
|
||||||
clock.color_index = Some(alarm.color_index);
|
clock.color_index = Some(alarm.color_index);
|
||||||
countdown.value = 0;
|
countdown.value = 0;
|
||||||
|
@ -284,7 +284,7 @@ impl AlarmRoster {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute the command given on the command line.
|
// Execute the command given on the command line.
|
||||||
pub fn exec_command(config: &Config, elapsed: u32) -> Option<Child> {
|
pub fn exec_command(config: &Config, elapsed: u32, label: String) -> Option<Child> {
|
||||||
let mut args: Vec<String> = Vec::new();
|
let mut args: Vec<String> = Vec::new();
|
||||||
let time: String;
|
let time: String;
|
||||||
|
|
||||||
|
@ -298,7 +298,7 @@ pub fn exec_command(config: &Config, elapsed: u32) -> Option<Child> {
|
||||||
// Replace every occurrence of "{}".
|
// Replace every occurrence of "{}".
|
||||||
args.reserve_exact(command.len());
|
args.reserve_exact(command.len());
|
||||||
for s in command {
|
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..])
|
match Command::new(&command[0]).args(&args[1..])
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -34,9 +34,9 @@ PARAMETERS:
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-h, --help Show this help.
|
-h, --help Show this help.
|
||||||
-v, --version Show version information.
|
-v, --version Show version information.
|
||||||
-e, --exec [COMMAND] Execute COMMAND on alarm. Every occurrence of {}
|
-e, --exec [COMMAND] Execute COMMAND on alarm. Occurrences of {t} will
|
||||||
will be replaced by the elapsed time in (HH:)MM:SS
|
be replaced by the alarm time in (HH:)MM:SS format.
|
||||||
format.
|
Occurrences of {l} by alarm label.
|
||||||
-p, --plain Use simpler block chars.
|
-p, --plain Use simpler block chars.
|
||||||
-q, --quit Quit program after last alarm.
|
-q, --quit Quit program after last alarm.
|
||||||
|
|
||||||
|
@ -272,7 +272,7 @@ fn main() {
|
||||||
layout.update(clock.elapsed >= 3600, clock.elapsed == 3600);
|
layout.update(clock.elapsed >= 3600, clock.elapsed == 3600);
|
||||||
|
|
||||||
// Check for exceeded alarms.
|
// 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 ASCII bell code.
|
||||||
write!(stdout, "{}", 0x07 as char).unwrap();
|
write!(stdout, "{}", 0x07 as char).unwrap();
|
||||||
layout.force_redraw = true;
|
layout.force_redraw = true;
|
||||||
|
@ -280,7 +280,7 @@ fn main() {
|
||||||
// Run command if configured.
|
// Run command if configured.
|
||||||
if config.command.is_some() {
|
if config.command.is_some() {
|
||||||
if spawned.is_none() {
|
if spawned.is_none() {
|
||||||
spawned = exec_command(&config, time);
|
spawned = exec_command(&config, time, label);
|
||||||
} else {
|
} else {
|
||||||
// The last command is still running.
|
// The last command is still running.
|
||||||
eprintln!("Not executing command, as its predecessor is still running");
|
eprintln!("Not executing command, as its predecessor is still running");
|
||||||
|
|
Loading…
Reference in a new issue