diff options
author | Zhenhui Xie <xiezh0831@yahoo.co.jp> | 2019-11-07 11:38:30 +0800 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-11-07 12:38:30 +0900 |
commit | 5bb7467b566437241aee92f548a2ecd8f580625c (patch) | |
tree | 5a52b2ba6a5bd3fd7968d1c7b16377eb1d63eb30 /src/modules | |
parent | a3d5ea3e432434fd5b2100ce4611e5193236c1bd (diff) |
refactor: Cleanup after module config refactor (#630)
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/cmd_duration.rs | 8 | ||||
-rw-r--r-- | src/modules/env_var.rs | 8 | ||||
-rw-r--r-- | src/modules/hostname.rs | 10 |
3 files changed, 9 insertions, 17 deletions
diff --git a/src/modules/cmd_duration.rs b/src/modules/cmd_duration.rs index 7b31c80c3..938549f64 100644 --- a/src/modules/cmd_duration.rs +++ b/src/modules/cmd_duration.rs @@ -1,4 +1,4 @@ -use super::{Context, Module}; +use super::{Context, Module, SegmentConfig}; use crate::config::RootModuleConfig; use crate::configs::cmd_duration::CmdDurationConfig; @@ -36,10 +36,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { }; module.set_style(module_color); - module.new_segment( - "cmd_duration", - &format!("{}{}", config.prefix, render_time(elapsed)), - ); + let cmd_duration_stacked = &format!("{}{}", config.prefix, render_time(elapsed)); + module.create_segment("cmd_duration", &SegmentConfig::new(&cmd_duration_stacked)); module.get_prefix().set_value(""); Some(module) diff --git a/src/modules/env_var.rs b/src/modules/env_var.rs index f4905fda3..733f1e169 100644 --- a/src/modules/env_var.rs +++ b/src/modules/env_var.rs @@ -1,6 +1,6 @@ use std::env; -use super::{Context, Module}; +use super::{Context, Module, SegmentConfig}; use crate::config::RootModuleConfig; use crate::configs::env_var::EnvVarConfig; @@ -25,10 +25,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { } // TODO: Use native prefix and suffix instead of stacking custom ones together with env_value. - module.new_segment( - "env_var", - &format!("{}{}{}", config.prefix, env_value, config.suffix), - ); + let env_var_stacked = format!("{}{}{}", config.prefix, env_value, config.suffix); + module.create_segment("env_var", &SegmentConfig::new(&env_var_stacked)); Some(module) } diff --git a/src/modules/hostname.rs b/src/modules/hostname.rs index 0c5a0f34a..74c617a7c 100644 --- a/src/modules/hostname.rs +++ b/src/modules/hostname.rs @@ -1,6 +1,6 @@ use std::env; -use super::{Context, Module}; +use super::{Context, Module, SegmentConfig}; use std::ffi::OsString; use crate::config::RootModuleConfig; @@ -30,8 +30,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { } }; - let trim_at = module.config_value_str("trim_at").unwrap_or("."); - //rustc doesn't let you do an "if" and an "if let" in the same if statement // if this changes in the future this can become a lot cleaner let host = if config.trim_at != "" { @@ -45,10 +43,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> { }; module.set_style(config.style); - module.new_segment( - "hostname", - &format!("{}{}{}", config.prefix, host, config.suffix), - ); + let hostname_stacked = format!("{}{}{}", config.prefix, host, config.suffix); + module.create_segment("hostname", &SegmentConfig::new(&hostname_stacked)); module.get_prefix().set_value("on "); Some(module) |