feat(fill): add disabled option for fill module (#3158)
* add disabled option for fill module * update tests * update docs
This commit is contained in:
parent
a0cadb32e9
commit
eb203ebe95
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue