aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/listener.rs
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.com>2025-09-09 21:26:03 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.com>2025-09-09 21:26:03 +0530
commit684deaa6b7d35a2fc22c0cffe892b117db1e18be (patch)
tree4f59f3f8b3d412f8d350df1f02b76157fb3ef1df /src/client/listener.rs
parentc865aa3c0e7c57113a705ccc28ded659c1adc46a (diff)
showing remaining time like a normal timer, not time elapsed
Diffstat (limited to 'src/client/listener.rs')
-rw-r--r--src/client/listener.rs11
1 files changed, 8 insertions, 3 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()));
}