]> git.seodisparate.com - swaybar_info/commitdiff
Fix when acpi line has "unavailable" with 0%
authorStephen Seo <seo.disparate@gmail.com>
Mon, 5 Jun 2023 06:45:25 +0000 (15:45 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 5 Jun 2023 06:45:25 +0000 (15:45 +0900)
src/builtin.rs

index 0f53c6a5b09b4a48e65031902b90b9db1f99b144..06892ead60f6b3bc7aa0b61eb8305718bf106792 100644 (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()));