summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMoritz Vetter <moritz.vetter@gmx.de>2021-01-19 05:42:28 +0100
committerGitHub <noreply@github.com>2021-01-18 22:42:28 -0600
commit2391a2863c24b1cc33fba302dcd127d839c23ade (patch)
tree35a6d02985cbdd40f789784fe5e545a4e19f7b8c
parent45bab3a42cbbb8ff6784e76aa88099256a7c240d (diff)
perf: evaluate swift version lazily (#2159)
* perf(swift): evaluate version lazily * fix(swift): update format string Co-authored-by: Moritz Vetter <mv@3yourmind.com>
-rw-r--r--docs/config/README.md12
-rw-r--r--src/configs/swift.rs2
-rw-r--r--src/modules/swift.rs15
3 files changed, 15 insertions, 14 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 427b90f45..da64c2ffc 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -2316,12 +2316,12 @@ 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 Swift |
-| `style` | `"bold 202"` | The style for the module. |
-| `disabled` | `false` | Disables the `swift` module. |
+| Option | Default | Description |
+| ---------- | ------------------------------------ | ------------------------------------------------ |
+| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
+| `symbol` | `"🐦 "` | A format string representing the symbol of Swift |
+| `style` | `"bold 202"` | The style for the module. |
+| `disabled` | `false` | Disables the `swift` module. |
### Variables
diff --git a/src/configs/swift.rs b/src/configs/swift.rs
index 0ee7617a1..9bedc2170 100644
--- a/src/configs/swift.rs
+++ b/src/configs/swift.rs
@@ -13,7 +13,7 @@ pub struct SwiftConfig<'a> {
impl<'a> RootModuleConfig<'a> for SwiftConfig<'a> {
fn new() -> Self {
SwiftConfig {
- format: "via [$symbol$version]($style) ",
+ format: "via [$symbol($version )]($style)",
symbol: "🐦 ",
style: "bold 202",
disabled: false,
diff --git a/src/modules/swift.rs b/src/modules/swift.rs
index ec7a2b8f5..18695c4c1 100644
--- a/src/modules/swift.rs
+++ b/src/modules/swift.rs
@@ -19,8 +19,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
- let swift_version = utils::exec_cmd("swift", &["--version"])?.stdout;
-
let mut module = context.new_module("swift");
let config: SwiftConfig = SwiftConfig::try_load(module.config);
@@ -35,7 +33,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
_ => None,
})
.map(|variable| match variable {
- "version" => parse_swift_version(&swift_version).map(Ok),
+ "version" => {
+ let swift_version = utils::exec_cmd("swift", &["--version"])?.stdout;
+ parse_swift_version(&swift_version).map(Ok)
+ }
_ => None,
})
.parse(None)
@@ -99,8 +100,8 @@ mod tests {
File::create(dir.path().join("Package.swift"))?.sync_all()?;
let actual = ModuleRenderer::new("swift").path(dir.path()).collect();
let expected = Some(format!(
- "via {} ",
- Color::Fixed(202).bold().paint("🐦 v5.2.2")
+ "via {}",
+ Color::Fixed(202).bold().paint("🐦 v5.2.2 ")
));
assert_eq!(expected, actual);
dir.close()
@@ -112,8 +113,8 @@ mod tests {
File::create(dir.path().join("main.swift"))?.sync_all()?;
let actual = ModuleRenderer::new("swift").path(dir.path()).collect();
let expected = Some(format!(
- "via {} ",
- Color::Fixed(202).bold().paint("🐦 v5.2.2")
+ "via {}",
+ Color::Fixed(202).bold().paint("🐦 v5.2.2 ")
));
assert_eq!(expected, actual);
dir.close()