diff options
author | Agathe Porte <microjoe@microjoe.org> | 2020-07-12 00:34:37 +0200 |
---|---|---|
committer | Agathe Porte <microjoe@microjoe.org> | 2020-07-14 10:38:23 +0200 |
commit | 9fae66d7cdbba8fd68d835c23e2fd7739c185024 (patch) | |
tree | 78c9acab70f41a8ca4b580ff4ad8298c995bde8e /src/plymouthd.rs | |
download | plymouth-rs-9fae66d7cdbba8fd68d835c23e2fd7739c185024.tar.gz plymouth-rs-9fae66d7cdbba8fd68d835c23e2fd7739c185024.zip |
initial commit
Diffstat (limited to 'src/plymouthd.rs')
-rw-r--r-- | src/plymouthd.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/plymouthd.rs b/src/plymouthd.rs new file mode 100644 index 0000000..9e991e6 --- /dev/null +++ b/src/plymouthd.rs @@ -0,0 +1,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"); + } +} |