diff options
| author | Andreas Grois <andi@grois.info> | 2021-04-07 13:03:25 +0200 |
|---|---|---|
| committer | Andreas Grois <andi@grois.info> | 2021-04-07 13:03:25 +0200 |
| commit | 1c394103886ed58b72016c971a6ab54dbd64d55b (patch) | |
| tree | 17097e5e0009d5270314f9db009e6272d18b3399 /src | |
Initial commit. Borked, so don't use
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 45 | ||||
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/module_communication.rs | 18 |
3 files changed, 69 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..2c44978 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,45 @@ +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize, Debug)] +pub struct SwaystatusConfig { + separator : Option<String>, //Separator character between elements. + plugin_path : Option<String>, //path to load plugins from. If unset, hardcoded value is used. + elements : Option<Vec<(String,String)>>, //plugins to display and their config section. +} + +fn create_default_config() -> SwaystatusConfig { + return SwaystatusConfig{ + separator : Some(String::from(", ")), + plugin_path : Some(String::from("")), + //elements : Some(Vec::new())}; + elements : Some(vec!((String::from("time"), String::from("format = \"yyyy-mm-dd hh-mm-ss\"")))) + }; +} + +pub enum SwaystatusConfigErrors +{ + FileNotFound, + ParsingError { + message : String + } +} + +pub fn print_sample_config() { + let default_config = create_default_config(); + let output = toml::to_string(&default_config).unwrap(); + print!("{}", output); +} + +pub fn read_config(path : &std::path::Path) -> Result<SwaystatusConfig,SwaystatusConfigErrors> { + let config_file = match std::fs::read_to_string(path) { + Ok(x) => x, + Err (_) => return Err(SwaystatusConfigErrors::FileNotFound) + }; + let result = match toml::from_str(&config_file) { + Ok(x) => x, + Err(e) => return Err(SwaystatusConfigErrors::ParsingError{message: e.to_string()}) + }; + + return Ok(result); + +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c85aaa1 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,6 @@ +mod module_communication; +mod config; + +fn main() { + config::print_sample_config(); +} diff --git a/src/module_communication.rs b/src/module_communication.rs new file mode 100644 index 0000000..3d4aefe --- /dev/null +++ b/src/module_communication.rs @@ -0,0 +1,18 @@ +pub enum MsgMainToModule { + Quit, +} +pub enum MsgModuleToMain { + UpdateText { + text : Result<String, String> + } +} + +pub trait SwayStatusModule { + fn new(from_main : crossbeam_channel::Receiver<MsgMainToModule>, + to_main : crossbeam_channel::Sender<MsgModuleToMain>, + module_settings : &str) -> Result<Box<Self>,String>; + + fn get_name(&self) -> &'static str; + + fn run(&self); +} |
