mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-01 01:04:00 +00:00
perf(crystal): Lazily evaluate version command (#2129)
* perf(crystal): Lazily evaluate version command This updates the module to lazily execute the `crystal --version` command only when the `version` variable is used in the format string. * perf(crystal): Update format string Update format string to handle the `$version` variable not being set.
This commit is contained in:
parent
d49ff412f6
commit
f640db87a4
@ -568,10 +568,10 @@ The module will be shown if any of the following conditions are met:
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ---------------------------------- | --------------------------------------------------------- |
|
| ---------- | ------------------------------------ | --------------------------------------------------------- |
|
||||||
| `symbol` | `"🔮 "` | The symbol used before displaying the version of crystal. |
|
| `symbol` | `"🔮 "` | The symbol used before displaying the version of crystal. |
|
||||||
| `style` | `"bold red"` | The style for the module. |
|
| `style` | `"bold red"` | The style for the module. |
|
||||||
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
| `disabled` | `false` | Disables the `crystal` module. |
|
| `disabled` | `false` | Disables the `crystal` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
@ -13,7 +13,7 @@ pub struct CrystalConfig<'a> {
|
|||||||
impl<'a> RootModuleConfig<'a> for CrystalConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for CrystalConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
CrystalConfig {
|
CrystalConfig {
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
symbol: "🔮 ",
|
symbol: "🔮 ",
|
||||||
style: "bold red",
|
style: "bold red",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
@ -20,8 +20,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let crystal_version = utils::exec_cmd("crystal", &["--version"])?.stdout;
|
|
||||||
|
|
||||||
let mut module = context.new_module("crystal");
|
let mut module = context.new_module("crystal");
|
||||||
let config: CrystalConfig = CrystalConfig::try_load(module.config);
|
let config: CrystalConfig = CrystalConfig::try_load(module.config);
|
||||||
|
|
||||||
@ -36,7 +34,10 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
"version" => format_crystal_version(&crystal_version).map(Ok),
|
"version" => format_crystal_version(
|
||||||
|
utils::exec_cmd("crystal", &["--version"])?.stdout.as_str(),
|
||||||
|
)
|
||||||
|
.map(Ok),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
|
Loading…
Reference in New Issue
Block a user