mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-23 21:55:11 +02:00
bug: Fix inverted battery colours (#331)
Fixes colour theming for batteries being flipped.
This commit is contained in:
parent
380571cf73
commit
41b8dd61d0
@ -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/),
|
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).
|
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
|
## [0.5.2] - 2020-11-25
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
@ -23,8 +23,9 @@ pub struct CanvasColours {
|
|||||||
pub text_style: Style,
|
pub text_style: Style,
|
||||||
pub widget_title_style: Style,
|
pub widget_title_style: Style,
|
||||||
pub graph_style: Style,
|
pub graph_style: Style,
|
||||||
// Full, Medium, Low
|
pub high_battery_colour: Style,
|
||||||
pub battery_bar_styles: Vec<Style>,
|
pub medium_battery_colour: Style,
|
||||||
|
pub low_battery_colour: Style,
|
||||||
pub invalid_query_style: Style,
|
pub invalid_query_style: Style,
|
||||||
pub disabled_text_style: Style,
|
pub disabled_text_style: Style,
|
||||||
}
|
}
|
||||||
@ -65,18 +66,9 @@ impl Default for CanvasColours {
|
|||||||
text_style: Style::default().fg(text_colour),
|
text_style: Style::default().fg(text_colour),
|
||||||
widget_title_style: Style::default().fg(text_colour),
|
widget_title_style: Style::default().fg(text_colour),
|
||||||
graph_style: Style::default().fg(text_colour),
|
graph_style: Style::default().fg(text_colour),
|
||||||
battery_bar_styles: vec![
|
high_battery_colour: Style::default().fg(Color::Green),
|
||||||
Style::default().fg(Color::Red),
|
medium_battery_colour: Style::default().fg(Color::Yellow),
|
||||||
Style::default().fg(Color::Yellow),
|
low_battery_colour: Style::default().fg(Color::Red),
|
||||||
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),
|
|
||||||
],
|
|
||||||
invalid_query_style: Style::default().fg(tui::style::Color::Red),
|
invalid_query_style: Style::default().fg(tui::style::Color::Red),
|
||||||
disabled_text_style: Style::default().fg(Color::DarkGray),
|
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<()> {
|
pub fn set_high_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
||||||
let style = get_style_from_config(colour)?;
|
self.high_battery_colour = 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;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_medium_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
pub fn set_medium_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
||||||
let style = get_style_from_config(colour)?;
|
self.medium_battery_colour = get_style_from_config(colour)?;
|
||||||
self.battery_bar_styles[6] = style;
|
|
||||||
self.battery_bar_styles[7] = style;
|
|
||||||
self.battery_bar_styles[8] = style;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_low_battery_color(&mut self, colour: &str) -> error::Result<()> {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,22 +138,15 @@ impl BatteryDisplayWidget for Painter {
|
|||||||
["Health %", &battery_details.health],
|
["Health %", &battery_details.health],
|
||||||
];
|
];
|
||||||
|
|
||||||
let battery_rows = battery_items.iter().enumerate().map(|(itx, item)| {
|
let battery_rows = battery_items.iter().map(|item| {
|
||||||
Row::StyledData(
|
Row::StyledData(
|
||||||
item.iter(),
|
item.iter(),
|
||||||
if itx == 0 {
|
if charge_percentage < 10.0 {
|
||||||
let colour_index = ((charge_percentage
|
self.colours.low_battery_colour
|
||||||
* self.colours.battery_bar_styles.len() as f64)
|
} else if charge_percentage < 50.0 {
|
||||||
/ 100.0)
|
self.colours.medium_battery_colour
|
||||||
.ceil() as usize
|
|
||||||
- 1;
|
|
||||||
*self
|
|
||||||
.colours
|
|
||||||
.battery_bar_styles
|
|
||||||
.get(colour_index)
|
|
||||||
.unwrap_or(&self.colours.text_style)
|
|
||||||
} else {
|
} else {
|
||||||
self.colours.text_style
|
self.colours.high_battery_colour
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user