aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2021-04-07 21:29:02 +0200
committerAndreas Grois <andi@grois.info>2021-04-18 20:25:00 +0200
commit99c3480323f2df0c1cd455e2e03e832c1196050a (patch)
tree02331612925d9ce8a02d47fc471626701c364682 /src/config.rs
parent1c394103886ed58b72016c971a6ab54dbd64d55b (diff)
First semi-working implementation.
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/config.rs b/src/config.rs
deleted file mode 100644
index 2c44978..0000000
--- a/src/config.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-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);
-
-}