i3status_rs/blocks/packages/
zypper.rs

1use tokio::process::Command;
2
3use super::*;
4
5#[derive(Default)]
6pub struct Zypper;
7
8impl Zypper {
9    pub fn new() -> Self {
10        Default::default()
11    }
12}
13
14#[async_trait]
15impl Backend for Zypper {
16    fn name(&self) -> Cow<'static, str> {
17        "zypper".into()
18    }
19
20    async fn get_updates_list(&self) -> Result<Vec<String>> {
21        let stdout = Command::new("zypper")
22            .env("LC_ALL", "C")
23            .args(["--quiet", "list-updates"])
24            .output()
25            .await
26            .error("Failed to run `zypper list-updates`")?
27            .stdout;
28
29        let updates = String::from_utf8(stdout).error("zypper produced non-UTF8 output")?;
30        let updates_list: Vec<String> = updates
31            .lines()
32            .filter(|line| line.starts_with("v"))
33            .map(|line| line.to_string())
34            .collect();
35
36        Ok(updates_list)
37    }
38}