diff --git a/config/main.template.toml b/config/main.template.toml new file mode 100644 index 0000000..70b5387 --- /dev/null +++ b/config/main.template.toml @@ -0,0 +1,6 @@ +seperator=" | " + +[plugins] +blacklist=["example_c", "example_rust"] +as_whitelist=false +template=["counter", "battery", "clock"] diff --git a/config/main.toml b/config/main.toml new file mode 100644 index 0000000..70b5387 --- /dev/null +++ b/config/main.toml @@ -0,0 +1,6 @@ +seperator=" | " + +[plugins] +blacklist=["example_c", "example_rust"] +as_whitelist=false +template=["counter", "battery", "clock"] diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..01a5779 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,55 @@ +use std::path::{Path, PathBuf}; + +use serde::{Deserialize, Serialize}; + + +#[derive(Debug, Serialize, Deserialize, Default)] +pub struct Config { + pub seperator: String, + pub plugins: ConfigPlugins, + + #[serde(skip)] + pub config_dir: PathBuf, +} + +#[derive(Debug, Serialize, Deserialize, Default)] +pub struct ConfigPlugins { + pub blacklist: Vec, + pub as_whitelist: bool, + pub template: Vec, +} + +impl Config { + pub fn new(path: &Path) -> Result { + let path = path.join("main.toml"); + + if !path.exists() { + println!("ERROR: {:?} doesnt exist", path); + } + + let mut cfg: Self = toml::from_str( + &std::fs::read_to_string(&path)? + )?; + + cfg.config_dir = path.to_path_buf(); + Ok(cfg) + } +} + +#[allow(dead_code)] +#[derive(Debug)] +pub enum ConfigError { + IoError(std::io::Error), + TomlDeserialiseError(toml::de::Error) +} + +impl From for ConfigError { + fn from(e: std::io::Error) -> Self { + Self::IoError(e) + } +} +impl From for ConfigError { + fn from(e: toml::de::Error) -> Self { + Self::TomlDeserialiseError(e) + } +}