Skip to content

Commit 800ed64

Browse files
authored
Fix charge capacity signs (grouzen#51)
* Fix charge capacity signs * Use underscore syntax in pattern matching
1 parent 04ffdf0 commit 800ed64

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/framework/fingerprint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ impl Fingerprint {
2222
.get_fp_led_level()
2323
.map_err(|error| Report::from(EcErrorWrapper(error)))?
2424
{
25-
(.., Some(..)) => FpLedBrightnessCapability::Percentage,
26-
(.., None) => FpLedBrightnessCapability::Level,
25+
(_, Some(_)) => FpLedBrightnessCapability::Percentage,
26+
(_, None) => FpLedBrightnessCapability::Level,
2727
};
2828

2929
Ok(Self {

src/tui/component/charge_panel.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,9 @@ impl ChargePanelComponent {
218218
) {
219219
let capacity_loss_text = match info.capacity_loss_percentage {
220220
Some(capacity_loss_percentage) => {
221-
if capacity_loss_percentage > 0.0 {
222-
format!("-{:.2}%", capacity_loss_percentage)
223-
} else {
224-
format!("+{:.2}%", capacity_loss_percentage)
225-
}
221+
let inverted = -capacity_loss_percentage;
222+
223+
format!("{:+.2}%", inverted)
226224
}
227225
_ => "N/A".to_string(),
228226
};
@@ -275,13 +273,15 @@ impl ChargePanelComponent {
275273
None => Style::default(),
276274
};
277275
let capacity_loss_per_cycle_text = match capacity_loss_per_cycle {
278-
Some(capacity_loss_per_cycle) if capacity_loss_per_cycle > NORMAL_CAPACITY_LOSS_MAX => {
279-
format!(
280-
"{:.3}% (normal loss is 0.025-0.048%)",
281-
capacity_loss_per_cycle
282-
)
276+
Some(capacity_loss_per_cycle) => {
277+
let inverted = -capacity_loss_per_cycle;
278+
279+
if capacity_loss_per_cycle > NORMAL_CAPACITY_LOSS_MAX {
280+
format!("{:+.3}% (expected 0.025-0.048%)", inverted)
281+
} else {
282+
format!("{:+.3}%", inverted)
283+
}
283284
}
284-
Some(capacity_loss_per_cycle) => format!("{:.3}%", capacity_loss_per_cycle),
285285
_ => "N/A".to_string(),
286286
};
287287

src/tui/control.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ impl AdjustableControl {
1717

1818
pub fn is_focused(&self) -> bool {
1919
match self {
20-
AdjustableControl::Percentage(focused, ..) => *focused,
21-
AdjustableControl::Range(focused, ..) => *focused,
20+
AdjustableControl::Percentage(focused, _) => *focused,
21+
AdjustableControl::Range(focused, _, _) => *focused,
2222
}
2323
}
2424

2525
pub fn get_percentage_value(&self) -> Option<u8> {
2626
match self {
27-
AdjustableControl::Percentage(.., value) => Some(*value),
27+
AdjustableControl::Percentage(_, value) => Some(*value),
2828
_ => None,
2929
}
3030
}

0 commit comments

Comments
 (0)