Merge pull request #3 from wezm/flash-timer

Blink timer when it finishes
This commit is contained in:
Jimmy 2022-08-03 18:59:44 +08:00 committed by GitHub
commit 228faf45c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,11 +47,7 @@ impl Timer {
pub(crate) fn remaining_time(&self) -> Duration { pub(crate) fn remaining_time(&self) -> Duration {
if let Some(end_at) = self.ended_at { if let Some(end_at) = self.ended_at {
let now = Local::now(); let now = Local::now();
if end_at <= now { end_at.signed_duration_since(now)
Duration::zero()
} else {
end_at.signed_duration_since(now)
}
} else { } else {
self.duration self.duration
} }
@ -60,7 +56,17 @@ impl Timer {
impl Widget for &Timer { impl Widget for &Timer {
fn render(self, area: Rect, buf: &mut Buffer) { fn render(self, area: Rect, buf: &mut Buffer) {
let time_str = format_duration(self.remaining_time(), self.format); let remaining_time = self.remaining_time();
let time_str = if remaining_time < Duration::zero() {
if remaining_time.num_seconds() % 2 == 0 {
return;
} else {
format_duration(Duration::zero(), self.format)
}
} else {
format_duration(remaining_time, self.format)
};
let text = BricksText::new(time_str.as_str(), self.size, self.size, self.style); let text = BricksText::new(time_str.as_str(), self.size, self.size, self.style);
let footer = if self.is_paused() { let footer = if self.is_paused() {
Some("PAUSED (press <SPACE> to resume)".to_string()) Some("PAUSED (press <SPACE> to resume)".to_string())