summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Vetter <moritz.vetter@gmx.de>2021-01-20 18:49:26 +0100
committerGitHub <noreply@github.com>2021-01-20 18:49:26 +0100
commitb065758b1c562638a26bb0bdc891ccc2ff8a6cb4 (patch)
treee7dac6558f9ee04137e3e3582b4aa7f3ca4b6378
parent527ffbaede6a7b487805beb6b5791bd6f8ed99e2 (diff)
perf(elm): Lazy eval elm (#2167)
* perf(elm): evaluate version lazily * fix(elm): update format string * fix: use suggested format string Co-authored-by: Moritz Vetter <mv@3yourmind.com>
-rw-r--r--docs/config/README.md12
-rw-r--r--src/configs/elm.rs2
-rw-r--r--src/modules/elm.rs19
3 files changed, 17 insertions, 16 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 1c97e6b13..44a9cf224 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -848,12 +848,12 @@ The module will be shown if any of the following conditions are met:
### Options
-| Option | Default | Description |
-| ---------- | ---------------------------------- | ----------------------------------------------- |
-| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
-| `symbol` | `"🌳 "` | A format string representing the symbol of Elm. |
-| `style` | `"cyan bold"` | The style for the module. |
-| `disabled` | `false` | Disables the `elm` module. |
+| Option | Default | Description |
+| ---------- | ------------------------------------ | ----------------------------------------------- |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `symbol` | `"🌳 "` | A format string representing the symbol of Elm. |
+| `style` | `"cyan bold"` | The style for the module. |
+| `disabled` | `false` | Disables the `elm` module. |
### Variables
diff --git a/src/configs/elm.rs b/src/configs/elm.rs
index b88b2edea..17dc35686 100644
--- a/src/configs/elm.rs
+++ b/src/configs/elm.rs
@@ -13,7 +13,7 @@ pub struct ElmConfig<'a> {
impl<'a> RootModuleConfig<'a> for ElmConfig<'a> {
fn new() -> Self {
ElmConfig {
- format: "via [$symbol$version]($style) ",
+ format: "via [$symbol($version )]($style)",
symbol: "🌳 ",
style: "cyan bold",
disabled: false,
diff --git a/src/modules/elm.rs b/src/modules/elm.rs
index a7da023be..b4773c467 100644
--- a/src/modules/elm.rs
+++ b/src/modules/elm.rs
@@ -24,9 +24,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
- let elm_version = utils::exec_cmd("elm", &["--version"])?.stdout;
- let module_version = Some(format!("v{}", elm_version.trim()))?;
-
let mut module = context.new_module("elm");
let config: ElmConfig = ElmConfig::try_load(module.config);
@@ -41,7 +38,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
- "version" => Some(Ok(&module_version)),
+ "version" => {
+ let elm_version = utils::exec_cmd("elm", &["--version"])?.stdout;
+ let module_version = Some(format!("v{}", elm_version.trim()))?;
+ Some(Ok(module_version))
+ }
_ => None,
})
.parse(None)
@@ -79,7 +80,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("elm.json"))?.sync_all()?;
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
+ let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -89,7 +90,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("elm-package.json"))?.sync_all()?;
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
+ let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -99,7 +100,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join(".elm-version"))?.sync_all()?;
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
+ let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -110,7 +111,7 @@ mod tests {
let elmstuff = dir.path().join("elm-stuff");
fs::create_dir_all(&elmstuff)?;
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
+ let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -120,7 +121,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("main.elm"))?.sync_all()?;
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
+ let expected = Some(format!("via {}", Color::Cyan.bold().paint("🌳 v0.19.1 ")));
assert_eq!(expected, actual);
dir.close()
}