mirror of
https://github.com/starship/starship.git
synced 2024-12-25 00:28:52 +01:00
perf(php): Lazy eval php (#2190)
* perf(php): evaluate version lazily * fix(php): update format string; update tests Co-authored-by: Moritz Vetter <mv@3yourmind.com>
This commit is contained in:
parent
60be1e9540
commit
d10a83ce6b
@ -1965,8 +1965,8 @@ The module will be shown if any of the following conditions are met:
|
|||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ---------------------------------- | ----------------------------------------------------- |
|
| ---------- | ------------------------------------ | ----------------------------------------------------- |
|
||||||
| `format` | `"via [$symbol$version]($style) "` | The format for the module. |
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
| `symbol` | `"🐘 "` | The symbol used before displaying the version of PHP. |
|
| `symbol` | `"🐘 "` | The symbol used before displaying the version of PHP. |
|
||||||
| `style` | `"147 bold"` | The style for the module. |
|
| `style` | `"147 bold"` | The style for the module. |
|
||||||
| `disabled` | `false` | Disables the `php` module. |
|
| `disabled` | `false` | Disables the `php` module. |
|
||||||
|
@ -15,7 +15,7 @@ impl<'a> RootModuleConfig<'a> for PhpConfig<'a> {
|
|||||||
PhpConfig {
|
PhpConfig {
|
||||||
symbol: "🐘 ",
|
symbol: "🐘 ",
|
||||||
style: "147 bold",
|
style: "147 bold",
|
||||||
format: "via [$symbol$version]($style) ",
|
format: "via [$symbol($version )]($style)",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
match utils::exec_cmd(
|
|
||||||
"php",
|
|
||||||
&[
|
|
||||||
"-nr",
|
|
||||||
"echo PHP_MAJOR_VERSION.\".\".PHP_MINOR_VERSION.\".\".PHP_RELEASE_VERSION;",
|
|
||||||
],
|
|
||||||
) {
|
|
||||||
Some(php_cmd_output) => {
|
|
||||||
let mut module = context.new_module("php");
|
let mut module = context.new_module("php");
|
||||||
let config: PhpConfig = PhpConfig::try_load(module.config);
|
let config: PhpConfig = PhpConfig::try_load(module.config);
|
||||||
|
|
||||||
@ -42,7 +34,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.map(|variable| match variable {
|
.map(|variable| match variable {
|
||||||
"version" => Some(Ok(format_php_version(&php_cmd_output.stdout))),
|
"version" => {
|
||||||
|
let php_cmd_output = utils::exec_cmd(
|
||||||
|
"php",
|
||||||
|
&[
|
||||||
|
"-nr",
|
||||||
|
"echo PHP_MAJOR_VERSION.\".\".PHP_MINOR_VERSION.\".\".PHP_RELEASE_VERSION;",
|
||||||
|
],
|
||||||
|
)?;
|
||||||
|
Some(Ok(format_php_version(&php_cmd_output.stdout)))
|
||||||
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
.parse(None)
|
.parse(None)
|
||||||
@ -58,9 +59,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
|
|
||||||
Some(module)
|
Some(module)
|
||||||
}
|
}
|
||||||
None => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format_php_version(php_version: &str) -> String {
|
fn format_php_version(php_version: &str) -> String {
|
||||||
format!("v{}", php_version)
|
format!("v{}", php_version)
|
||||||
|
Loading…
Reference in New Issue
Block a user