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)
|
||||||
|
|
Loading…
Reference in New Issue