Fix when acpi line has "unavailable" with 0%

This commit is contained in:
Stephen Seo 2023-06-05 15:45:25 +09:00
parent c60629864d
commit 3568bebb22
1 changed files with 8 additions and 1 deletions

View File

@ -127,7 +127,14 @@ impl BattInfo {
cmd_builder.arg("-b");
let output = cmd_builder.output()?;
let string = String::from_utf8(output.stdout)?;
let regex_captures_result = self.regex.captures(&string);
let mut last_line = "unknown".to_owned();
for line in string.lines() {
if !line.contains("unavailable") {
last_line = line.to_owned();
break;
}
}
let regex_captures_result = self.regex.captures(&last_line);
if regex_captures_result.is_none() {
self.acpi_error = true;
return Err(Error::Generic("battinfo: regex captured nothing".into()));