1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-09 20:02:20 +00:00

perf(elixir): evaluate version lazily (#2172)

This commit is contained in:
David Knaack 2021-01-20 18:59:21 +01:00 committed by GitHub
parent 2532251a13
commit bb160d9207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 12 deletions

View File

@ -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

View File

@ -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,

View File

@ -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<otp>\\d+)[^\\n]+
@ -21,7 +23,7 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
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<Module<'a>> {
_ => 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();