From eb203ebe95aacecc8f479cf50eed433fbfdbdfc3 Mon Sep 17 00:00:00 2001 From: Aman Kumar Sinha <45752299+Perniciosius@users.noreply.github.com> Date: Thu, 21 Oct 2021 17:57:32 +0530 Subject: [PATCH] feat(fill): add disabled option for fill module (#3158) * add disabled option for fill module * update tests * update docs --- docs/config/README.md | 1 + src/configs/fill.rs | 2 ++ src/modules/fill.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/docs/config/README.md b/docs/config/README.md index 8b32f787..c68060b7 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -1135,6 +1135,7 @@ other modules. | ---------- | -------------- | -------------------------------------- | | `symbol` | `"."` | The symbol used to fill the line. | | `style` | `"bold black"` | The style for the module. | +| `disabled` | `false` | Disables the `fill` module | ### Example diff --git a/src/configs/fill.rs b/src/configs/fill.rs index f0bb468f..fc0af31f 100644 --- a/src/configs/fill.rs +++ b/src/configs/fill.rs @@ -7,6 +7,7 @@ use starship_module_config_derive::ModuleConfig; pub struct FillConfig<'a> { pub style: &'a str, pub symbol: &'a str, + pub disabled: bool, } impl<'a> Default for FillConfig<'a> { @@ -14,6 +15,7 @@ impl<'a> Default for FillConfig<'a> { FillConfig { style: "bold black", symbol: ".", + disabled: false, } } } diff --git a/src/modules/fill.rs b/src/modules/fill.rs index edbabbee..1b7127c9 100644 --- a/src/modules/fill.rs +++ b/src/modules/fill.rs @@ -10,6 +10,10 @@ pub fn module<'a>(context: &'a Context) -> Option> { let mut module = context.new_module("fill"); let config: FillConfig = FillConfig::try_load(module.config); + if config.disabled { + return None; + } + let style = parse_style_string(config.style); module.set_segments(vec![Segment::fill(style, config.symbol)]); @@ -35,4 +39,30 @@ mod tests { assert_eq!(expected, actual); } + + #[test] + fn module_disabled() { + let actual = ModuleRenderer::new("fill") + .config(toml::toml! { + [fill] + disabled = true + }) + .collect(); + let expected = Option::::None; + + assert_eq!(expected, actual); + } + + #[test] + fn module_enabled() { + let actual = ModuleRenderer::new("fill") + .config(toml::toml! { + [fill] + disabled = false + }) + .collect(); + let expected = Some(format!("{}", Color::Black.bold().paint("."))); + + assert_eq!(expected, actual); + } }