bug: Fix inverted battery colours (#331)

Fixes colour theming for batteries being flipped.
This commit is contained in:
Clement Tsang 2020-11-26 19:14:27 -05:00 committed by GitHub
parent 380571cf73
commit 41b8dd61d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 39 deletions

View file

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.5.3] - 2020-11-26
## Bug Fixes
- [#331](https://github.com/ClementTsang/bottom/pull/331): Fixes custom battery colour levels being inverted.
## [0.5.2] - 2020-11-25
## Bug Fixes

View file

@ -23,8 +23,9 @@ pub struct CanvasColours {
pub text_style: Style,
pub widget_title_style: Style,
pub graph_style: Style,
// Full, Medium, Low
pub battery_bar_styles: Vec<Style>,
pub high_battery_colour: Style,
pub medium_battery_colour: Style,
pub low_battery_colour: Style,
pub invalid_query_style: Style,
pub disabled_text_style: Style,
}
@ -65,18 +66,9 @@ impl Default for CanvasColours {
text_style: Style::default().fg(text_colour),
widget_title_style: Style::default().fg(text_colour),
graph_style: Style::default().fg(text_colour),
battery_bar_styles: vec![
Style::default().fg(Color::Red),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Yellow),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
Style::default().fg(Color::Green),
],
high_battery_colour: Style::default().fg(Color::Green),
medium_battery_colour: Style::default().fg(Color::Yellow),
low_battery_colour: Style::default().fg(Color::Red),
invalid_query_style: Style::default().fg(tui::style::Color::Red),
disabled_text_style: Style::default().fg(Color::DarkGray),
}
@ -293,26 +285,17 @@ impl CanvasColours {
}
pub fn set_high_battery_color(&mut self, colour: &str) -> error::Result<()> {
let style = get_style_from_config(colour)?;
self.battery_bar_styles[0] = style;
self.battery_bar_styles[1] = style;
self.battery_bar_styles[2] = style;
self.battery_bar_styles[3] = style;
self.battery_bar_styles[4] = style;
self.battery_bar_styles[5] = style;
self.high_battery_colour = get_style_from_config(colour)?;
Ok(())
}
pub fn set_medium_battery_color(&mut self, colour: &str) -> error::Result<()> {
let style = get_style_from_config(colour)?;
self.battery_bar_styles[6] = style;
self.battery_bar_styles[7] = style;
self.battery_bar_styles[8] = style;
self.medium_battery_colour = get_style_from_config(colour)?;
Ok(())
}
pub fn set_low_battery_color(&mut self, colour: &str) -> error::Result<()> {
self.battery_bar_styles[9] = get_style_from_config(colour)?;
self.low_battery_colour = get_style_from_config(colour)?;
Ok(())
}
}

View file

@ -138,22 +138,15 @@ impl BatteryDisplayWidget for Painter {
["Health %", &battery_details.health],
];
let battery_rows = battery_items.iter().enumerate().map(|(itx, item)| {
let battery_rows = battery_items.iter().map(|item| {
Row::StyledData(
item.iter(),
if itx == 0 {
let colour_index = ((charge_percentage
* self.colours.battery_bar_styles.len() as f64)
/ 100.0)
.ceil() as usize
- 1;
*self
.colours
.battery_bar_styles
.get(colour_index)
.unwrap_or(&self.colours.text_style)
if charge_percentage < 10.0 {
self.colours.low_battery_colour
} else if charge_percentage < 50.0 {
self.colours.medium_battery_colour
} else {
self.colours.text_style
self.colours.high_battery_colour
},
)
});