mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-26 06:00:21 +00:00
other: skip battery duration draw if unknown (#974)
* other: skip battery duration draw if unknown * increase others * update changelog
This commit is contained in:
parent
316891d476
commit
571ec08291
3 changed files with 29 additions and 31 deletions
|
@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
## Changes
|
## Changes
|
||||||
|
|
||||||
|
- [#974](https://github.com/ClementTsang/bottom/pull/974): Hide battery duration section if the value is unknown. Also update shortened text.
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
|
|
||||||
## [0.7.1] - 2023-01-06
|
## [0.7.1] - 2023-01-06
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ impl App {
|
||||||
'k' => self.on_up_key(),
|
'k' => self.on_up_key(),
|
||||||
'j' => self.on_down_key(),
|
'j' => self.on_down_key(),
|
||||||
'f' => {
|
'f' => {
|
||||||
self.frozen_state.toggle(&self.data_collection); // TODO: Unthawing should force a full data refresh and redraw immediately.
|
self.frozen_state.toggle(&self.data_collection); // TODO: Thawing should force a full data refresh and redraw immediately.
|
||||||
}
|
}
|
||||||
'c' => {
|
'c' => {
|
||||||
if let BottomWidgetType::Proc = self.current_widget.widget_type {
|
if let BottomWidgetType::Proc = self.current_widget.widget_type {
|
||||||
|
|
|
@ -142,56 +142,52 @@ impl Painter {
|
||||||
format!("{}h {}m {}s", time.whole_hours(), num_minutes, num_seconds,)
|
format!("{}h {}m {}s", time.whole_hours(), num_minutes, num_seconds,)
|
||||||
}
|
}
|
||||||
|
|
||||||
let s: String; // Brought out due to lifetimes.
|
let mut battery_rows = Vec::with_capacity(4);
|
||||||
let time_text = {
|
battery_rows.push(Row::new(vec![
|
||||||
|
Cell::from("Charge %").style(self.colours.text_style),
|
||||||
|
Cell::from(bars).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.high_battery_colour
|
||||||
|
}),
|
||||||
|
]));
|
||||||
|
battery_rows.push(
|
||||||
|
Row::new(vec!["Consumption", &battery_details.watt_consumption])
|
||||||
|
.style(self.colours.text_style),
|
||||||
|
);
|
||||||
|
|
||||||
|
let s: String; // Keep string in scope.
|
||||||
|
{
|
||||||
let style = self.colours.text_style;
|
let style = self.colours.text_style;
|
||||||
match &battery_details.battery_duration {
|
match &battery_details.battery_duration {
|
||||||
BatteryDuration::ToEmpty(secs) => {
|
BatteryDuration::ToEmpty(secs) => {
|
||||||
if half_width > 25 {
|
if half_width > 25 {
|
||||||
s = long_time(*secs);
|
s = long_time(*secs);
|
||||||
Row::new(vec!["Time to empty", &s]).style(style)
|
battery_rows.push(Row::new(vec!["Time to empty", &s]).style(style));
|
||||||
} else {
|
} else {
|
||||||
s = short_time(*secs);
|
s = short_time(*secs);
|
||||||
Row::new(vec!["Empty", &s]).style(style)
|
battery_rows.push(Row::new(vec!["To empty", &s]).style(style));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BatteryDuration::ToFull(secs) => {
|
BatteryDuration::ToFull(secs) => {
|
||||||
if half_width > 25 {
|
if half_width > 25 {
|
||||||
s = long_time(*secs);
|
s = long_time(*secs);
|
||||||
Row::new(vec!["Time to full", &s]).style(style)
|
battery_rows.push(Row::new(vec!["Time to full", &s]).style(style));
|
||||||
} else {
|
} else {
|
||||||
s = short_time(*secs);
|
s = short_time(*secs);
|
||||||
Row::new(vec!["Full", &s]).style(style)
|
battery_rows.push(Row::new(vec!["To full", &s]).style(style));
|
||||||
}
|
|
||||||
}
|
|
||||||
BatteryDuration::Unknown => {
|
|
||||||
// TODO: Potentially just don't draw this?
|
|
||||||
if half_width > 20 {
|
|
||||||
Row::new(vec!["Time to full/empty", "N/A"]).style(style)
|
|
||||||
} else {
|
|
||||||
Row::new(vec!["Empty/full", "N/A"]).style(style)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BatteryDuration::Unknown => {}
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
let battery_rows = vec![
|
battery_rows.push(
|
||||||
Row::new(vec![
|
|
||||||
Cell::from("Charge %").style(self.colours.text_style),
|
|
||||||
Cell::from(bars).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.high_battery_colour
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
Row::new(vec!["Consumption", &battery_details.watt_consumption])
|
|
||||||
.style(self.colours.text_style),
|
|
||||||
time_text,
|
|
||||||
Row::new(vec!["Health %", &battery_details.health])
|
Row::new(vec!["Health %", &battery_details.health])
|
||||||
.style(self.colours.text_style),
|
.style(self.colours.text_style),
|
||||||
];
|
);
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
|
|
Loading…
Reference in a new issue