summaryrefslogtreecommitdiffstats
path: root/src/plymouthd.rs
blob: 9e991e6968842577babebe5b29b49a765ed9d4c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::path::Path;
use std::io;

use ini::Ini;

pub struct Plymouthd {
    conf: Ini,
}

impl Plymouthd {
    pub fn from_ini(conf: Ini) -> Self {
        Self { conf }
    }

    pub fn from_file<P: AsRef<Path>>(filename: P) -> io::Result<Self> {
        let conf = Ini::load_from_file(filename).map_err(|e| super::ini_to_io_err(e))?;
        Ok(Self { conf })
    }

    pub fn default() -> io::Result<Self> {
        Self::from_file("/etc/plymouth/plymouthd.conf")
    }

    pub fn current_theme(&self) -> Option<&str> {
        self.conf
            .section(Some("Daemon"))
            .and_then(|s| s.get("Theme"))
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn default_theme_from_ini() {
        let mut ini = Ini::new();
        ini.with_section(Some("Daemon")).set("Theme", "spinner");

        let conf = Plymouthd::from_ini(ini);
        assert!(conf.current_theme().unwrap() == "spinner");
    }
}