aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornc <[email protected]>2020-07-20 00:50:53 +0100
committernc <[email protected]>2020-07-20 00:50:53 +0100
commit852e5dc3a9a92761d019aaad1f1f36649610d815 (patch)
treeddb413753d693078bf1991c0a5e770694274da8c
parentc357ba5e2bd9bc1cb95f6d38412e1d84752aa70e (diff)
fix divide by zero for #5
-rw-r--r--src/views.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/views.rs b/src/views.rs
index e11b844..24c8a4d 100644
--- a/src/views.rs
+++ b/src/views.rs
@@ -81,8 +81,8 @@ where
81 let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>(); 81 let remaining = week.iter().map(|&i| self.remaining(i)).sum::<u32>();
82 let completions = weekly_goal - remaining; 82 let completions = weekly_goal - remaining;
83 let full = CONFIGURATION.view_width - 8; 83 let full = CONFIGURATION.view_width - 8;
84 let bars_to_fill = (completions * full as u32) / weekly_goal; 84 let bars_to_fill = if weekly_goal > 0 {(completions * full as u32) / weekly_goal} else {0};
85 let percentage = (completions as f64 * 100.) / weekly_goal as f64; 85 let percentage = if weekly_goal > 0 {(completions as f64 * 100.) / weekly_goal as f64} else {0.0};
86 printer.with_style(future_style, |p| { 86 printer.with_style(future_style, |p| {
87 p.print((4, line_nr), &"─".repeat(full)); 87 p.print((4, line_nr), &"─".repeat(full));
88 }); 88 });