aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2018-03-02 22:01:25 -0500
committerJesse Luehrs <doy@tozt.net>2018-03-02 22:01:25 -0500
commit8670a96f4b0008e5a4189708f27461f5833dc7f2 (patch)
treeedad58d0fdd561e1a058ab2d8ae54d153d2a600b
parent5d7d8c61be28af23576260c7fa757700a03c6397 (diff)
downloadfancy-prompt-8670a96f4b0008e5a4189708f27461f5833dc7f2.tar.gz
fancy-prompt-8670a96f4b0008e5a4189708f27461f5833dc7f2.zip
handle overfull battery properly
-rw-r--r--src/prompt.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/prompt.rs b/src/prompt.rs
index 98d2e7b..8c8eece 100644
--- a/src/prompt.rs
+++ b/src/prompt.rs
@@ -146,15 +146,17 @@ impl Prompt {
let charging = self.data.power_info.charging();
let color = battery_discharge_color(battery_usage, charging);
let filled = (battery_usage * (len as f64)).ceil() as usize;
- let unfilled = len - filled;
- if unfilled > 0 {
+ if len > filled {
+ let unfilled = len - filled;
self.colors.print(color, &"-".repeat(unfilled));
}
- if charging {
- self.colors.print("battery_charging", "<");
- }
- else {
- self.colors.print(color, ">");
+ if len >= filled {
+ if charging {
+ self.colors.print("battery_charging", "<");
+ }
+ else {
+ self.colors.print(color, ">");
+ }
}
if filled > 1 {
self.colors