summaryrefslogtreecommitdiffstats
path: root/src/plymouthd.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/plymouthd.rs')
-rw-r--r--src/plymouthd.rs43
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");
+ }
+}