Merge pull request #13 from wezm/start-paused

Add option to start the timer paused
This commit is contained in:
Jimmy 2022-08-16 09:54:53 +08:00 committed by GitHub
commit d6014dc7c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -38,6 +38,10 @@ pub(crate) enum Mode {
#[clap(long = "no-millis", short = 'M', takes_value = false)]
no_millis: bool,
/// Start the timer paused
#[clap(long = "paused", short = 'P', takes_value = false)]
paused: bool,
/// Command to run when the timer ends
#[clap(long, short, multiple = true, allow_hyphen_values = true)]
execute: Vec<String>,
@ -110,6 +114,7 @@ impl App {
Mode::Timer {
duration,
no_millis,
paused,
execute,
} => {
let format = if *no_millis {
@ -122,6 +127,7 @@ impl App {
self.size,
style,
format,
*paused,
execute.to_owned(),
));
}

View file

@ -24,6 +24,7 @@ impl Timer {
size: u16,
style: Style,
format: DurationFormat,
paused: bool,
execute: Vec<String>,
) -> Self {
Self {
@ -32,7 +33,7 @@ impl Timer {
execute,
style,
format,
ended_at: Some(Local::now() + duration),
ended_at: (!paused).then(|| Local::now() + duration),
execute_result: RefCell::new(None),
}
}