feat(fill): add disabled option for fill module (#3158)

* add disabled option for fill module

* update tests

* update docs
This commit is contained in:
Aman Kumar Sinha 2021-10-21 17:57:32 +05:30 committed by GitHub
parent a0cadb32e9
commit eb203ebe95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -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

View File

@ -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,
}
}
}

View File

@ -10,6 +10,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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::<String>::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);
}
}