summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Vetter <moritz.vetter@gmx.de>2021-01-22 18:08:36 +0100
committerGitHub <noreply@github.com>2021-01-22 18:08:36 +0100
commit4e7f73da50f095d5f4ddd428dce3d13f3d90d34a (patch)
treebbbe2c8042b4cf241cd26fac0aa5f4f62b36bd9e
parent212dbc4e6b913fa4752f3f2702c1b2b399119298 (diff)
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>
-rw-r--r--docs/config/README.md12
-rw-r--r--src/configs/zig.rs2
-rw-r--r--src/modules/zig.rs14
3 files changed, 13 insertions, 15 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index b67b21df8..5fc98c76c 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -2498,12 +2498,12 @@ The module will be shown if any of the following conditions are met:
### 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. |
### Variables
diff --git a/src/configs/zig.rs b/src/configs/zig.rs
index 7dacca0ac..b8cafc4a4 100644
--- a/src/configs/zig.rs
+++ b/src/configs/zig.rs
@@ -13,7 +13,7 @@ pub struct ZigConfig<'a> {
impl<'a> RootModuleConfig<'a> for ZigConfig<'a> {
fn new() -> Self {
ZigConfig {
- format: "via [$symbol$version]($style) ",
+ format: "via [$symbol($version )]($style)",
symbol: "↯ ",
style: "bold yellow",
disabled: false,
diff --git a/src/modules/zig.rs b/src/modules/zig.rs
index b4f711f94..b8b3eac30 100644
--- a/src/modules/zig.rs
+++ b/src/modules/zig.rs
@@ -18,12 +18,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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 config = ZigConfig::try_load(module.config);
@@ -38,7 +32,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.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,
})
.parse(None)
@@ -77,7 +75,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("main.zig"))?.sync_all()?;
let actual = ModuleRenderer::new("zig").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Yellow.bold().paint("↯ v0.6.0")));
+ let expected = Some(format!("via {}", Color::Yellow.bold().paint("↯ v0.6.0 ")));
assert_eq!(expected, actual);
dir.close()
}