From 9fae66d7cdbba8fd68d835c23e2fd7739c185024 Mon Sep 17 00:00:00 2001 From: Agathe Porte Date: Sun, 12 Jul 2020 00:34:37 +0200 Subject: initial commit --- src/plymouthd.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/plymouthd.rs (limited to 'src/plymouthd.rs') 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>(filename: P) -> io::Result { + 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::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"); + } +} -- cgit v1.2.3