perf(zig): Lazy eval zig (#2187)

* perf(zig): evaluate version lazily

* fix(zig): update format string; update tests

* refact(zig): remove redundant clone and put everything to do with version eval into match statement

* tiny optimization

Co-authored-by: David Knaack <davidkna@users.noreply.github.com>

Co-authored-by: Moritz Vetter <mv@3yourmind.com>
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
This commit is contained in:
Moritz Vetter 2021-01-22 18:08:36 +01:00 committed by GitHub
parent 212dbc4e6b
commit 4e7f73da50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 15 deletions

View File

@ -2499,10 +2499,10 @@ The module will be shown if any of the following conditions are met:
### Options ### Options
| Option | Default | Description | | Option | Default | Description |
| ---------- | ---------------------------------- | ----------------------------------------------------- | | ---------- | ------------------------------------ | ----------------------------------------------------- |
| `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. | | `symbol` | `"↯ "` | The symbol used before displaying the version of Zig. |
| `style` | `"bold yellow"` | The style for the module. | | `style` | `"bold yellow"` | The style for the module. |
| `format` | `"via [$symbol$version]($style) "` | The format for the module. | | `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `disabled` | `false` | Disables the `zig` module. | | `disabled` | `false` | Disables the `zig` module. |
### Variables ### Variables

View File

@ -13,7 +13,7 @@ pub struct ZigConfig<'a> {
impl<'a> RootModuleConfig<'a> for ZigConfig<'a> { impl<'a> RootModuleConfig<'a> for ZigConfig<'a> {
fn new() -> Self { fn new() -> Self {
ZigConfig { ZigConfig {
format: "via [$symbol$version]($style) ", format: "via [$symbol($version )]($style)",
symbol: "", symbol: "",
style: "bold yellow", style: "bold yellow",
disabled: false, disabled: false,

View File

@ -18,12 +18,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None; return None;
} }
let zig_version_output = utils::exec_cmd("zig", &["version"])?
.stdout
.trim()
.to_string();
let zig_version = format!("v{}", zig_version_output);
let mut module = context.new_module("zig"); let mut module = context.new_module("zig");
let config = ZigConfig::try_load(module.config); let config = ZigConfig::try_load(module.config);
@ -38,7 +32,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None, _ => None,
}) })
.map(|variable| match variable { .map(|variable| match variable {
"version" => Some(Ok(zig_version.clone())), "version" => {
let zig_version_output = utils::exec_cmd("zig", &["version"])?.stdout;
let zig_version = format!("v{}", zig_version_output.trim());
Some(Ok(zig_version))
}
_ => None, _ => None,
}) })
.parse(None) .parse(None)