mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 15:56:28 +00:00
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>
This commit is contained in:
parent
5cf1c8a7bd
commit
98b89b9432
@ -1556,8 +1556,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 Lua. |
|
| `symbol` | `"🌙 "` | A format string representing the symbol of Lua. |
|
||||||
| `style` | `"bold blue"` | The style for the module. |
|
| `style` | `"bold blue"` | The style for the module. |
|
||||||
| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. |
|
| `lua_binary` | `"lua"` | Configures the lua binary that Starship executes when getting the version. |
|
||||||
|
@ -14,7 +14,7 @@ pub struct LuaConfig<'a> {
|
|||||||
impl<'a> RootModuleConfig<'a> for LuaConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for LuaConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
LuaConfig {
|
LuaConfig {
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
symbol: "🌙 ",
|
symbol: "🌙 ",
|
||||||
style: "bold blue",
|
style: "bold blue",
|
||||||
lua_binary: "lua",
|
lua_binary: "lua",
|
||||||
|
@ -27,7 +27,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
|
|
||||||
let mut module = context.new_module("lua");
|
let mut module = context.new_module("lua");
|
||||||
let config = LuaConfig::try_load(module.config);
|
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| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|var, _| match var {
|
.map_meta(|var, _| match var {
|
||||||
@ -39,7 +38,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.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,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
@ -103,7 +105,7 @@ mod tests {
|
|||||||
let dir = tempfile::tempdir()?;
|
let dir = tempfile::tempdir()?;
|
||||||
File::create(dir.path().join("main.lua"))?.sync_all()?;
|
File::create(dir.path().join("main.lua"))?.sync_all()?;
|
||||||
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -114,7 +116,7 @@ mod tests {
|
|||||||
File::create(dir.path().join(".lua-version"))?.sync_all()?;
|
File::create(dir.path().join(".lua-version"))?.sync_all()?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -126,7 +128,7 @@ mod tests {
|
|||||||
fs::create_dir_all(&lua_dir)?;
|
fs::create_dir_all(&lua_dir)?;
|
||||||
|
|
||||||
let actual = ModuleRenderer::new("lua").path(dir.path()).collect();
|
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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
@ -146,7 +148,7 @@ mod tests {
|
|||||||
.config(config)
|
.config(config)
|
||||||
.collect();
|
.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);
|
assert_eq!(expected, actual);
|
||||||
dir.close()
|
dir.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user