feat(zig): Configure when the module is shown (#2311)

* feat(zig): Configure when the module is shown

* remove outdated comment
This commit is contained in:
David Knaack 2021-02-14 22:21:44 +01:00 committed by GitHub
parent d14736dbfe
commit d4843545aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 14 deletions

View File

@ -2559,19 +2559,22 @@ format = "via [⍱ $version](bold white) "
## Zig
The `zig` module shows the currently installed version of Zig.
By default the the `zig` module shows the currently installed version of Zig.
The module will be shown if any of the following conditions are met:
- The current directory contains a `.zig` file
### Options
| Option | Default | Description |
| ---------- | ------------------------------------ | ----------------------------------------------------- |
| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. |
| `style` | `"bold yellow"` | The style for the module. |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `disabled` | `false` | Disables the `zig` module. |
| Option | Default | Description |
| ------------------- | ------------------------------------ | ----------------------------------------------------- |
| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. |
| `style` | `"bold yellow"` | The style for the module. |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `disabled` | `false` | Disables the `zig` module. |
| `detect_extensions` | `["zig"]` | Which extensions should trigger this module. |
| `detect_files` | `[]` | Which filenames should trigger this module. |
| `detect_folders` | `[]` | Which folders should trigger this module. |
### Variables

View File

@ -8,6 +8,9 @@ pub struct ZigConfig<'a> {
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}
impl<'a> RootModuleConfig<'a> for ZigConfig<'a> {
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ZigConfig<'a> {
symbol: "",
style: "bold yellow",
disabled: false,
detect_extensions: vec!["zig"],
detect_files: vec![],
detect_folders: vec![],
}
}
}

View File

@ -4,22 +4,21 @@ use crate::configs::zig::ZigConfig;
use crate::formatter::StringFormatter;
/// Creates a module with the current Zig version
///
/// Will display the Zig version if any of the following criteria are met:
/// - The current directory contains a file with extension `.zig`
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("zig");
let config = ZigConfig::try_load(module.config);
let is_zig_project = context
.try_begin_scan()?
.set_extensions(&["zig"])
.set_files(&config.detect_files)
.set_extensions(&config.detect_extensions)
.set_folders(&config.detect_folders)
.is_match();
if !is_zig_project {
return None;
}
let mut module = context.new_module("zig");
let config = ZigConfig::try_load(module.config);
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|variable, _| match variable {