mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +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
@ -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
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user