diff options
| -rw-r--r-- | swaystatus/src/config/mod.rs | 4 | ||||
| -rw-r--r-- | swaystatus/src/config/tests.rs | 4 | ||||
| -rw-r--r-- | swaystatus/src/main.rs | 17 |
3 files changed, 18 insertions, 7 deletions
diff --git a/swaystatus/src/config/mod.rs b/swaystatus/src/config/mod.rs index c851a25..6a6859f 100644 --- a/swaystatus/src/config/mod.rs +++ b/swaystatus/src/config/mod.rs @@ -120,6 +120,10 @@ impl<'p> SwaystatusPluginConfig<'p> { pub fn get_name(&'p self) -> &'p str { &self.plugin } + pub fn get_non_plugin_settings(&self) -> &SwaystatusElementNonPluginOptions { + &self.general + + } } pub enum SwaystatusConfigErrors diff --git a/swaystatus/src/config/tests.rs b/swaystatus/src/config/tests.rs index 712968c..9a30722 100644 --- a/swaystatus/src/config/tests.rs +++ b/swaystatus/src/config/tests.rs @@ -81,7 +81,7 @@ fn custom_deserialize_optional_field_settings() { let p = get_plugin_database_with_test_plugin(); let test_config = String::from( - "[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 2\nskull = \"skully\"\n"); + "[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 2\nskull = \"skully\"\n\n[Element.General]\nBeforeText = \"\"\nAfterText = \"\"\n"); let deserialized = SwaystatusConfig::deserialize(&test_config, &p).unwrap(); let serialized = toml::to_string(&deserialized).unwrap(); //println!("{}", serialized); @@ -107,7 +107,7 @@ fn custom_deserialize_multiple_plugins() { let p = get_plugin_database_with_test_plugin(); let test_config = String::from( - "[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 2\nskull = \"bones\"\n\n[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 5\nskull = \"pirate\"\n"); + "[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 2\nskull = \"bones\"\n\n[Element.General]\nBeforeText = \"\"\nAfterText = \"\"\n\n[[Element]]\nPlugin = \"TestPlugin\"\n\n[Element.Config]\nlines = 5\nskull = \"pirate\"\n\n[Element.General]\nBeforeText = \"\"\nAfterText = \"\"\n"); let deserialized = SwaystatusConfig::deserialize(&test_config, &p).unwrap(); let serialized = toml::to_string(&deserialized).unwrap(); //println!("{}", serialized); diff --git a/swaystatus/src/main.rs b/swaystatus/src/main.rs index c8a477f..e4847d9 100644 --- a/swaystatus/src/main.rs +++ b/swaystatus/src/main.rs @@ -105,11 +105,11 @@ fn core_loop(plugin_path : &std::path::Path, config_path : &std::path::Path) -> }, communication::Message::External{text, element_number} => { handle_message_from_element(&mut texts, &elements[element_number].get_name(), element_number, text); - print_texts(&texts, &main_config); + print_texts(&texts, &main_config, &elements); }, communication::Message::ThreadCrash{element_number} => { handle_crash_from_element(&mut texts, &elements[element_number].get_name(), element_number); - print_texts(&texts, &main_config); + print_texts(&texts, &main_config, &elements); } } } @@ -172,11 +172,18 @@ fn handle_message_from_element(texts : &mut Vec<String>, plugin : &str, element_ } } -fn print_texts(texts : &[String], settings : &config::SwaystatusMainConfig) { +fn print_texts(texts : &[String], settings : &config::SwaystatusMainConfig, element_settings : &[config::SwaystatusPluginConfig]) { //Once we do more than just printing, we might want a more advanced code here... let separators = std::iter::once("").chain(std::iter::repeat(&settings.separator[..])); - for (separator, text) in separators.zip(texts) { - print!("{}{}",separator,text); + let before_texts = element_settings.iter().map(|x| &x.get_non_plugin_settings().before_text); + let after_texts = element_settings.iter().map(|x| &x.get_non_plugin_settings().after_text); + let text_with_after = texts.iter().zip(after_texts); + let complete_text = before_texts.zip(text_with_after); + + let final_iterator = separators.zip(complete_text); + + for (separator, (before,(text,after))) in final_iterator { + print!("{}{}{}{}",separator,before,text,after); } println!(); //Previosly there was an explicit flush here, but printnl should do that for us. } |
