summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Vetter <moritz.vetter@gmx.de>2021-01-21 23:00:12 +0100
committerGitHub <noreply@github.com>2021-01-21 23:00:12 +0100
commit98b89b94321f3d764da57a51fd2570a011bb4a86 (patch)
tree7b3bf4aa69c011af78b8f3f890945c63bf790dc4
parent5cf1c8a7bdc9cd385d37dd1310b09099a966796d (diff)
perf(lua): Lazy eval lua (#2185)
* perf(lua): evaluate version lazily * fix(lua): update format string * test(lua): update tests Co-authored-by: Moritz Vetter <mv@3yourmind.com>
-rw-r--r--docs/config/README.md14
-rw-r--r--src/configs/lua.rs2
-rw-r--r--src/modules/lua.rs14
3 files changed, 16 insertions, 14 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index db507b828..4eb8f3cb5 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1555,13 +1555,13 @@ 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 Lua. |
-| `style` | `"bold blue"` | The style for the module. |
-| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. |
-| `disabled` | `false` | Disables the `lua` module. |
+| Option | Default | Description |
+| ------------ | ------------------------------------ | ----------------------------------------------------------------------------- |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `symbol` | `"🌙 "` | A format string representing the symbol of Lua. |
+| `style` | `"bold blue"` | The style for the module. |
+| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. |
+| `disabled` | `false` | Disables the `lua` module. |
### Variables
diff --git a/src/configs/lua.rs b/src/configs/lua.rs
index fb715f470..6ba8593f9 100644
--- a/src/configs/lua.rs
+++ b/src/configs/lua.rs
@@ -14,7 +14,7 @@ pub struct LuaConfig<'a> {
impl<'a> RootModuleConfig<'a> for LuaConfig<'a> {
fn new() -> Self {
LuaConfig {
- format: "via [$symbol$version]($style) ",
+ format: "via [$symbol($version )]($style)",
symbol: "🌙 ",
style: "bold blue",
lua_binary: "lua",
diff --git a/src/modules/lua.rs b/src/modules/lua.rs
index 9bea92668..3b30eb1c6 100644
--- a/src/modules/lua.rs
+++ b/src/modules/lua.rs
@@ -27,7 +27,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("lua");
let config = LuaConfig::try_load(module.config);
- let lua_version = format_lua_version(&get_lua_version(&config.lua_binary)?)?;
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
formatter
.map_meta(|var, _| match var {
@@ -39,7 +38,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
- "version" => Some(Ok(&lua_version)),
+ "version" => {
+ let lua_version = format_lua_version(&get_lua_version(&config.lua_binary)?)?;
+ Some(Ok(lua_version))
+ }
_ => None,
})
.parse(None)
@@ -103,7 +105,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("main.lua"))?.sync_all()?;
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🌙 v5.4.0")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🌙 v5.4.0 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -114,7 +116,7 @@ mod tests {
File::create(dir.path().join(".lua-version"))?.sync_all()?;
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🌙 v5.4.0")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🌙 v5.4.0 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -126,7 +128,7 @@ mod tests {
fs::create_dir_all(&lua_dir)?;
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🌙 v5.4.0")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🌙 v5.4.0 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -146,7 +148,7 @@ mod tests {
.config(config)
.collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🌙 v2.0.5")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🌙 v2.0.5 ")));
assert_eq!(expected, actual);
dir.close()
}