mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-01 09:13:54 +00:00
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>
This commit is contained in:
parent
527ffbaede
commit
b065758b1c
@ -849,8 +849,8 @@ The module will be shown if any of the following conditions are met:
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ---------------------------------- | ----------------------------------------------- |
|
| ---------- | ------------------------------------ | ----------------------------------------------- |
|
||||||
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
| `symbol` | `"🌳 "` | A format string representing the symbol of Elm. |
|
| `symbol` | `"🌳 "` | A format string representing the symbol of Elm. |
|
||||||
| `style` | `"cyan bold"` | The style for the module. |
|
| `style` | `"cyan bold"` | The style for the module. |
|
||||||
| `disabled` | `false` | Disables the `elm` module. |
|
| `disabled` | `false` | Disables the `elm` module. |
|
||||||
|
@ -13,7 +13,7 @@ pub struct ElmConfig<'a> {
|
|||||||
impl<'a> RootModuleConfig<'a> for ElmConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for ElmConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
ElmConfig {
|
ElmConfig {
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
symbol: "🌳 ",
|
symbol: "🌳 ",
|
||||||
style: "cyan bold",
|
style: "cyan bold",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
@ -24,9 +24,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
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 mut module = context.new_module("elm");
|
||||||
let config: ElmConfig = ElmConfig::try_load(module.config);
|
let config: ElmConfig = ElmConfig::try_load(module.config);
|
||||||
|
|
||||||
@ -41,7 +38,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.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,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
@ -79,7 +80,7 @@ mod tests {
|
|||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
File::create(dir.path().join("elm.json"))?.sync_all()?;
|
File::create(dir.path().join("elm.json"))?.sync_all()?;
|
||||||
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -89,7 +90,7 @@ mod tests {
|
|||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
File::create(dir.path().join("elm-package.json"))?.sync_all()?;
|
File::create(dir.path().join("elm-package.json"))?.sync_all()?;
|
||||||
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -99,7 +100,7 @@ mod tests {
|
|||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
File::create(dir.path().join(".elm-version"))?.sync_all()?;
|
File::create(dir.path().join(".elm-version"))?.sync_all()?;
|
||||||
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -110,7 +111,7 @@ mod tests {
|
|||||||
let elmstuff = dir.path().join("elm-stuff");
|
let elmstuff = dir.path().join("elm-stuff");
|
||||||
fs::create_dir_all(&elmstuff)?;
|
fs::create_dir_all(&elmstuff)?;
|
||||||
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -120,7 +121,7 @@ mod tests {
|
|||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
File::create(dir.path().join("main.elm"))?.sync_all()?;
|
File::create(dir.path().join("main.elm"))?.sync_all()?;
|
||||||
let actual = ModuleRenderer::new("elm").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user