diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-09-09 21:26:03 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-09-09 21:26:03 +0530 |
commit | 684deaa6b7d35a2fc22c0cffe892b117db1e18be (patch) | |
tree | 4f59f3f8b3d412f8d350df1f02b76157fb3ef1df /src | |
parent | c865aa3c0e7c57113a705ccc28ded659c1adc46a (diff) |
showing remaining time like a normal timer, not time elapsed
Diffstat (limited to 'src')
-rw-r--r-- | src/client/listener.rs | 11 | ||||
-rw-r--r-- | src/daemon/pomo.rs | 6 |
2 files changed, 11 insertions, 6 deletions
diff --git a/src/client/listener.rs b/src/client/listener.rs index 0b403b2..e70c2b3 100644 --- a/src/client/listener.rs +++ b/src/client/listener.rs @@ -69,8 +69,8 @@ pub fn start_listener() { } } -// TODO: show remaining time, not time elapsed -fn format_time(secs: u16) -> String { +fn format_time(elapsed_secs: u16, total_secs: u16) -> String { + let secs = total_secs - elapsed_secs; format!("{:02}:{:02}", secs / 60, secs % 60) } @@ -93,8 +93,13 @@ fn pretty_print(f: &Format, p: Pomo) { State::LongBreakIdle => &f.format_long_break_idle, }; + let total_secs: u16 = match p.current_state { + State::WorkIdle | State::Work | State::WorkPaused => p.work_duration, + State::BreakIdle | State::Break | State::BreakPaused => p.break_duration, + State::LongBreakIdle | State::LongBreak | State::LongBreakPaused => p.long_break_duration, + }; println!("{}", format - .replace("{time}", format_time(p.secs_elapsed).as_str()) + .replace("{time}", format_time(p.secs_elapsed, total_secs).as_str()) .replace("{counter}", format!("{}", p.counter).as_str())); } diff --git a/src/daemon/pomo.rs b/src/daemon/pomo.rs index 1f4d8ef..2ed7294 100644 --- a/src/daemon/pomo.rs +++ b/src/daemon/pomo.rs @@ -33,10 +33,10 @@ pub enum State { #[derive(Encode, Decode)] pub struct Pomo { - work_duration: u16, - break_duration: u16, - long_break_duration: u16, long_break_interval: u16, + pub work_duration: u16, + pub break_duration: u16, + pub long_break_duration: u16, // only these are supposed to change pub secs_elapsed: u16, |