perf(kotlin): Lazy eval kotlin (#2186)
* perf(kotlin): evaluate version lazily * fix(kotlin): update format string; update tests Co-authored-by: Moritz Vetter <mv@3yourmind.com>
This commit is contained in:
parent
98b89b9432
commit
00afc82049
|
@ -1444,8 +1444,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 Kotlin. |
|
| `symbol` | `"🅺 "` | A format string representing the symbol of Kotlin. |
|
||||||
| `style` | `"bold blue"` | The style for the module. |
|
| `style` | `"bold blue"` | The style for the module. |
|
||||||
| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
|
| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct KotlinConfig<'a> {
|
||||||
impl<'a> RootModuleConfig<'a> for KotlinConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for KotlinConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
KotlinConfig {
|
KotlinConfig {
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
symbol: "🅺 ",
|
symbol: "🅺 ",
|
||||||
style: "bold blue",
|
style: "bold blue",
|
||||||
kotlin_binary: "kotlin",
|
kotlin_binary: "kotlin",
|
||||||
|
|
|
@ -23,7 +23,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
|
||||||
let mut module = context.new_module("kotlin");
|
let mut module = context.new_module("kotlin");
|
||||||
let config = KotlinConfig::try_load(module.config);
|
let config = KotlinConfig::try_load(module.config);
|
||||||
let kotlin_version = format_kotlin_version(&get_kotlin_version(&config.kotlin_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 {
|
||||||
|
@ -35,7 +34,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
"version" => Some(Ok(&kotlin_version)),
|
"version" => {
|
||||||
|
let kotlin_version =
|
||||||
|
format_kotlin_version(&get_kotlin_version(&config.kotlin_binary)?)?;
|
||||||
|
Some(Ok(kotlin_version))
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
|
|
Loading…
Reference in New Issue