Some minor improvements.
This commit is contained in:
parent
63706d90e8
commit
a42e1130a1
2 changed files with 24 additions and 25 deletions
26
src/alarm.rs
26
src/alarm.rs
|
@ -86,8 +86,6 @@ impl AlarmRoster {
|
||||||
|
|
||||||
if let Some(i) = input.find('/') {
|
if let Some(i) = input.find('/') {
|
||||||
label = input[(i + 1)..].trim().to_string();
|
label = input[(i + 1)..].trim().to_string();
|
||||||
// TODO: Make decision yes/no.
|
|
||||||
//label.truncate(24);
|
|
||||||
time_str = &input[..i].trim();
|
time_str = &input[..i].trim();
|
||||||
} else {
|
} else {
|
||||||
label = input.clone();
|
label = input.clone();
|
||||||
|
@ -162,17 +160,19 @@ 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, String)> {
|
countdown: &mut Countdown,
|
||||||
|
) -> Option<(u32, &String)>
|
||||||
let mut ret: Option<(u32, String)> = None;
|
{
|
||||||
|
let mut ret = None;
|
||||||
let mut index = 0;
|
let mut index = 0;
|
||||||
|
let size = self.list.len() as u16;
|
||||||
|
|
||||||
for alarm in &mut self.list {
|
for alarm in &mut self.list {
|
||||||
// Ignore alarms marked exceeded.
|
// Ignore alarms marked exceeded.
|
||||||
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, alarm.label.clone()));
|
ret = Some((alarm.time, &alarm.label));
|
||||||
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;
|
||||||
|
@ -194,9 +194,7 @@ impl AlarmRoster {
|
||||||
|
|
||||||
// Compensate for "hidden" items in the alarm roster.
|
// Compensate for "hidden" items in the alarm roster.
|
||||||
// TODO: Make this more elegant and robust.
|
// TODO: Make this more elegant and robust.
|
||||||
if let Some(offset) = (self.list.len() as u16)
|
if let Some(offset) = size.checked_sub(layout.roster_height + 1) {
|
||||||
.checked_sub(layout.roster_height + 1) {
|
|
||||||
|
|
||||||
if index <= offset{
|
if index <= offset{
|
||||||
// Draw next to placeholder ("[...]").
|
// Draw next to placeholder ("[...]").
|
||||||
line = layout.roster.line;
|
line = layout.roster.line;
|
||||||
|
@ -248,7 +246,7 @@ impl AlarmRoster {
|
||||||
color::Bg(COLOR[alarm.color_index]),
|
color::Bg(COLOR[alarm.color_index]),
|
||||||
color::Bg(color::Reset),
|
color::Bg(color::Reset),
|
||||||
style::Bold,
|
style::Bold,
|
||||||
alarm.label,
|
&alarm.label,
|
||||||
style::Reset)
|
style::Reset)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
} else {
|
} else {
|
||||||
|
@ -257,7 +255,7 @@ impl AlarmRoster {
|
||||||
cursor::Goto(layout.roster.col, layout.roster.line + index),
|
cursor::Goto(layout.roster.col, layout.roster.line + index),
|
||||||
color::Bg(COLOR[alarm.color_index]),
|
color::Bg(COLOR[alarm.color_index]),
|
||||||
color::Bg(color::Reset),
|
color::Bg(color::Reset),
|
||||||
alarm.label)
|
&alarm.label)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
index += 1;
|
index += 1;
|
||||||
|
@ -271,8 +269,8 @@ impl AlarmRoster {
|
||||||
let length = str_length(&alarm.label);
|
let length = str_length(&alarm.label);
|
||||||
if length > width { width = length };
|
if length > width { width = length };
|
||||||
}
|
}
|
||||||
// Actual width is 3 columns wider if it's not 0.
|
// Actual width is 4 columns wider if it's not 0.
|
||||||
if width == 0 { 0 } else { width.saturating_add(3) }
|
if width == 0 { 0 } else { width.saturating_add(4) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset every alarm.
|
// Reset every alarm.
|
||||||
|
@ -284,7 +282,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, label: String) -> 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;
|
||||||
|
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -26,10 +26,11 @@ use common::{Config, str_length};
|
||||||
const NAME: &str = env!("CARGO_PKG_NAME");
|
const NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
const VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const USAGE: &str = concat!("USAGE: ", env!("CARGO_PKG_NAME"),
|
const USAGE: &str = concat!("USAGE: ", env!("CARGO_PKG_NAME"),
|
||||||
" [-h|-v] [-e|--exec COMMAND] [-p] [-q] [ALARM TIME(s)]
|
" [-h|-v] [-e|--exec COMMAND] [-p] [-q] [ALARM[/LABEL]]
|
||||||
|
|
||||||
PARAMETERS:
|
PARAMETERS:
|
||||||
[ALARM TIME] None or multiple alarm times (HH:MM:SS).
|
[ALARM TIME[/LABEL]] Any number of alarm times (HH:MM:SS) with optional
|
||||||
|
label.
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-h, --help Show this help.
|
-h, --help Show this help.
|
||||||
|
@ -280,7 +281,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, label);
|
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");
|
||||||
|
@ -444,7 +445,7 @@ fn parse_args(config: &mut Config, alarm_roster: &mut AlarmRoster) {
|
||||||
// for process::Command::new().
|
// for process::Command::new().
|
||||||
fn parse_to_command(input: &str) -> Vec<String> {
|
fn parse_to_command(input: &str) -> Vec<String> {
|
||||||
let mut command: Vec<String> = Vec::new();
|
let mut command: Vec<String> = Vec::new();
|
||||||
let mut subs: String = String::new();
|
let mut buffer: String = String::new();
|
||||||
let mut quoted = false;
|
let mut quoted = false;
|
||||||
let mut escaped = false;
|
let mut escaped = false;
|
||||||
|
|
||||||
|
@ -455,22 +456,22 @@ fn parse_to_command(input: &str) -> Vec<String> {
|
||||||
escaped = true;
|
escaped = true;
|
||||||
continue;
|
continue;
|
||||||
},
|
},
|
||||||
' ' if escaped || quoted => { &subs.push(' '); },
|
' ' if escaped || quoted => { &buffer.push(' '); },
|
||||||
' ' => {
|
' ' => {
|
||||||
if !&subs.is_empty() {
|
if !&buffer.is_empty() {
|
||||||
command.push(subs.clone());
|
command.push(buffer.clone());
|
||||||
&subs.clear();
|
&buffer.clear();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'"' | '\'' if !escaped => quoted = !quoted,
|
'"' | '\'' if !escaped => quoted = !quoted,
|
||||||
_ => {
|
_ => {
|
||||||
if escaped { &subs.push('\\'); }
|
if escaped { &buffer.push('\\'); }
|
||||||
&subs.push(byte);
|
&buffer.push(byte);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
escaped = false;
|
escaped = false;
|
||||||
}
|
}
|
||||||
command.push(subs);
|
command.push(buffer);
|
||||||
command.shrink_to_fit();
|
command.shrink_to_fit();
|
||||||
command
|
command
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue