diff options
Diffstat (limited to 'src/modules/java.rs')
-rw-r--r-- | src/modules/java.rs | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/modules/java.rs b/src/modules/java.rs index 177e95451..faf7d8c6e 100644 --- a/src/modules/java.rs +++ b/src/modules/java.rs @@ -1,6 +1,7 @@ use crate::configs::java::JavaConfig; +use crate::formatter::StringFormatter; -use super::{Context, Module, RootModuleConfig, SegmentConfig}; +use super::{Context, Module, RootModuleConfig}; use crate::modules::utils::java_version_parser; use crate::utils; @@ -25,12 +26,31 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { Some(java_version) => { let mut module = context.new_module("java"); let config: JavaConfig = JavaConfig::try_load(module.config); - module.set_style(config.style); - let formatted_version = format_java_version(java_version)?; - module.create_segment("symbol", &config.symbol); - module.create_segment("version", &SegmentConfig::new(&formatted_version)); + let parsed = StringFormatter::new(config.format).and_then(|formatter| { + formatter + .map_meta(|var, _| match var { + "symbol" => Some(config.symbol), + _ => None, + }) + .map_style(|variable| match variable { + "style" => Some(Ok(config.style)), + _ => None, + }) + .map(|variable| match variable { + "version" => Some(Ok(&formatted_version)), + _ => None, + }) + .parse(None) + }); + module.set_segments(match parsed { + Ok(segments) => segments, + Err(error) => { + log::warn!("Error in module `java`:\n{}", error); + return None; + } + }); Some(module) } None => None, |