diff --git a/docs/config/README.md b/docs/config/README.md index fdc89a69..97c3095a 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -808,12 +808,12 @@ The module will be shown if any of the following conditions are met: ### Options -| Option | Default | Description | -| ---------- | ------------------------------------------------------- | --------------------------------------------------------------- | -| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. | -| `style` | `"bold purple"` | The style for the module. | -| `format` | `'via [$symbol$version \(OTP $otp_version\)]($style) '` | The format for the module elixir. | -| `disabled` | `false` | Disables the `elixir` module. | +| Option | Default | Description | +| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- | +| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. | +| `style` | `"bold purple"` | The style for the module. | +| `format` | `'via [$symbol($version \(OTP $otp_version\) )]($style)'` | The format for the module elixir. | +| `disabled` | `false` | Disables the `elixir` module. | ### Variables diff --git a/src/configs/elixir.rs b/src/configs/elixir.rs index 21a99cc9..ebe2a271 100644 --- a/src/configs/elixir.rs +++ b/src/configs/elixir.rs @@ -13,7 +13,7 @@ pub struct ElixirConfig<'a> { impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> { fn new() -> Self { ElixirConfig { - format: "via [$symbol$version \\(OTP $otp_version\\)]($style) ", + format: "via [$symbol($version \\(OTP $otp_version\\) )]($style)", symbol: "💧 ", style: "bold purple", disabled: false, diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs index 921e97af..3fd31fa2 100644 --- a/src/modules/elixir.rs +++ b/src/modules/elixir.rs @@ -4,7 +4,9 @@ use crate::configs::elixir::ElixirConfig; use crate::formatter::StringFormatter; use crate::utils; +use once_cell::sync::Lazy; use regex::Regex; +use std::ops::Deref; const ELIXIR_VERSION_PATTERN: &str = "\ Erlang/OTP (?P\\d+)[^\\n]+ @@ -21,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option> { return None; } - let (otp_version, elixir_version) = get_elixir_version()?; + let versions = Lazy::new(get_elixir_version); let mut module = context.new_module("elixir"); let config = ElixirConfig::try_load(module.config); @@ -36,8 +38,16 @@ pub fn module<'a>(context: &'a Context) -> Option> { _ => None, }) .map(|variable| match variable { - "version" => Some(Ok(&elixir_version)), - "otp_version" => Some(Ok(&otp_version)), + "version" => versions + .deref() + .as_ref() + .map(|(_, elixir_version)| elixir_version) + .map(Ok), + "otp_version" => versions + .deref() + .as_ref() + .map(|(otp_version, _)| otp_version) + .map(Ok), _ => None, }) .parse(None) @@ -110,8 +120,8 @@ Elixir 1.10 (compiled with Erlang/OTP 22) File::create(dir.path().join("mix.exs"))?.sync_all()?; let expected = Some(format!( - "via {} ", - Color::Purple.bold().paint("💧 1.10 (OTP 22)") + "via {}", + Color::Purple.bold().paint("💧 1.10 (OTP 22) ") )); let output = ModuleRenderer::new("elixir").path(dir.path()).collect();