diff --git a/Cargo.lock b/Cargo.lock index d38b615..45635d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1459,7 +1459,7 @@ dependencies = [ [[package]] name = "pomodoro-cli" -version = "1.2.1" +version = "1.2.2" dependencies = [ "chrono", "clap", diff --git a/Cargo.toml b/Cargo.toml index 8564186..f067033 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pomodoro-cli" -version = "1.2.1" +version = "1.2.2" authors = ["Jussi Kallio "] license = "MIT" description = "A simple command line Pomodoro timer." diff --git a/README.md b/README.md index c3f71e5..daed819 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Pomodoro timer is a simple timer that helps you to stay focused on your tasks. ### Download binary -- [pomodoro cli (v.1.2.1)](https://github.com/jkallio/pomodoro-cli/releases/tag/v1.2.1) +- [pomodoro cli (latest release)](https://github.com/jkallio/pomodoro-cli/releases/latest) ### Cargo @@ -43,6 +43,7 @@ Options for `start`: - `--notify` Triggers system notification when the timer is finished (default: disabled) - `--silent` Do not play alarm sound when the timer is finished (default: enabled) - `--wait` Wait for the timer to finish (default: disabled) +- `--add` Add more time to a running timer instead of starting a new timer (default: disabled) ### Start/Stop the timer @@ -63,8 +64,8 @@ $ pomodoro-cli pause ### Add more time to a running timer ```bash -# Call start again while the timer is running to add more time to the timer -$ pomodoro-cli start --duration 5m +# Add 10 minutes to the timer (instead of starting a new timer) +$ pomodoro-cli start -d 10 --add ``` ### Query the timer status diff --git a/src/app.rs b/src/app.rs index 48d79ac..f2596b9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -17,8 +17,9 @@ pub fn run(args: &Cli) -> AppResult<()> { silent, notify, wait, + add, } => { - start_timer(parse_duration(duration.clone()), *silent, *notify)?; + start_timer(parse_duration(duration.clone()), *silent, *notify, *add)?; if *wait { wait_for_timer()?; } @@ -38,15 +39,16 @@ pub fn run(args: &Cli) -> AppResult<()> { } /// Start the timer. If the timer is already running, the duration is added to the current duration. -pub fn start_timer(duration: i64, silent: bool, notify: bool) -> AppResult<()> { +pub fn start_timer(duration: i64, silent: bool, notify: bool, add: bool) -> AppResult<()> { let mut timer_info = TimerInfo::from_file_or_default()?; - if timer_info.is_running() { + if add && timer_info.is_running() { timer_info.duration += duration; } else { + let now = chrono::Utc::now().timestamp() + 1; let elapsed = timer_info.pause_time - timer_info.start_time; timer_info.duration = duration - elapsed; - timer_info.start_time = chrono::Utc::now().timestamp(); - timer_info.pause_time = timer_info.start_time; + timer_info.start_time = now; + timer_info.pause_time = now; timer_info.silent = silent; timer_info.notify = notify; timer_info.state = TimerState::Running; @@ -64,7 +66,12 @@ pub fn pause_timer() -> AppResult<()> { timer_info.state = TimerState::Paused; timer_info.write_to_file()?; } else { - start_timer(timer_info.duration, timer_info.silent, timer_info.notify)?; + start_timer( + timer_info.duration, + timer_info.silent, + timer_info.notify, + false, + )?; } Ok(()) } diff --git a/src/args.rs b/src/args.rs index 5fc46a4..13e9c51 100644 --- a/src/args.rs +++ b/src/args.rs @@ -29,6 +29,9 @@ pub enum SubCommand { #[arg(long, default_value_t = false, help = "Wait for the timer to finish")] wait: bool, + + #[arg(long, default_value_t = false, help = "Add more time to the timer")] + add: bool, }, /// Stop the timer Stop,