summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Vetter <moritz.vetter@gmx.de>2021-01-21 23:01:30 +0100
committerGitHub <noreply@github.com>2021-01-21 23:01:30 +0100
commit00afc82049c094ccac6a3363043c4972746cafee (patch)
tree4c3c753f5cfe0e6133a80626e54dab6580fc8779
parent98b89b94321f3d764da57a51fd2570a011bb4a86 (diff)
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>
-rw-r--r--docs/config/README.md14
-rw-r--r--src/configs/kotlin.rs2
-rw-r--r--src/modules/kotlin.rs15
3 files changed, 17 insertions, 14 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 4eb8f3cb5..78f05d8f3 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1443,13 +1443,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 Kotlin. |
-| `style` | `"bold blue"` | The style for the module. |
-| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
-| `disabled` | `false` | Disables the `kotlin` module. |
+| Option | Default | Description |
+| --------------- | ------------------------------------ | ----------------------------------------------------------------------------- |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `symbol` | `"🅺 "` | A format string representing the symbol of Kotlin. |
+| `style` | `"bold blue"` | The style for the module. |
+| `kotlin_binary` | `"kotlin"` | Configures the kotlin binary that Starship executes when getting the version. |
+| `disabled` | `false` | Disables the `kotlin` module. |
### Variables
diff --git a/src/configs/kotlin.rs b/src/configs/kotlin.rs
index 9e65da2ce..33763a9fd 100644
--- a/src/configs/kotlin.rs
+++ b/src/configs/kotlin.rs
@@ -14,7 +14,7 @@ pub struct KotlinConfig<'a> {
impl<'a> RootModuleConfig<'a> for KotlinConfig<'a> {
fn new() -> Self {
KotlinConfig {
- format: "via [$symbol$version]($style) ",
+ format: "via [$symbol($version )]($style)",
symbol: "🅺 ",
style: "bold blue",
kotlin_binary: "kotlin",
diff --git a/src/modules/kotlin.rs b/src/modules/kotlin.rs
index 31d979b44..267b5378e 100644
--- a/src/modules/kotlin.rs
+++ b/src/modules/kotlin.rs
@@ -23,7 +23,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("kotlin");
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| {
formatter
.map_meta(|var, _| match var {
@@ -35,7 +34,11 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.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,
})
.parse(None)
@@ -99,7 +102,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("main.kt"))?.sync_all()?;
let actual = ModuleRenderer::new("kotlin").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🅺 v1.4.21")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🅺 v1.4.21 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -109,7 +112,7 @@ mod tests {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("main.kts"))?.sync_all()?;
let actual = ModuleRenderer::new("kotlin").path(dir.path()).collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🅺 v1.4.21")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🅺 v1.4.21 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -129,7 +132,7 @@ mod tests {
.config(config)
.collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🅺 v1.4.21")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🅺 v1.4.21 ")));
assert_eq!(expected, actual);
dir.close()
}
@@ -149,7 +152,7 @@ mod tests {
.config(config)
.collect();
- let expected = Some(format!("via {} ", Color::Blue.bold().paint("🅺 v1.4.21")));
+ let expected = Some(format!("via {}", Color::Blue.bold().paint("🅺 v1.4.21 ")));
assert_eq!(expected, actual);
dir.close()
}