feat(elixir): Configure when module is shown (#2340)
This makes it possible to configure when the elixir module is shown based on the contents of a directory. This should make it possible to be a lot more granular when configuring the module.
This commit is contained in:
parent
37d3425d21
commit
9313e90773
|
@ -790,12 +790,12 @@ when there is a csproj file in the current directory.
|
|||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ------------------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
|
||||
| ------------------- | ------------------------------------------------------------------------------------------------------- | -------------------------------------------------------- |
|
||||
| `format` | `"[$symbol($version )(🎯 $tfm )]($style)"` | The format for the module. |
|
||||
| `symbol` | `"•NET "` | The symbol used before displaying the version of dotnet. |
|
||||
| `heuristic` | `true` | Use faster version detection to keep starship snappy. |
|
||||
| `detect_extensions` | `["sln", "csproj", "fsproj", "xproj"]` | Which extensions should trigger this module. |
|
||||
| `detect_files` | `[ "global.json", "project.json", "Directory.Build.props", "Directory.Build.targets", "Packages.props"]` | Which filenames should trigger this module. |
|
||||
| `detect_files` | `["global.json", "project.json", "Directory.Build.props", "Directory.Build.targets", "Packages.props"]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||
| `style` | `"bold blue"` | The style for the module. |
|
||||
| `disabled` | `false` | Disables the `dotnet` module. |
|
||||
|
@ -825,15 +825,18 @@ heuristic = false
|
|||
## Elixir
|
||||
|
||||
The `elixir` module shows the currently installed version of Elixir and Erlang/OTP.
|
||||
The module will be shown if any of the following conditions are met:
|
||||
By default the module will be shown if any of the following conditions are met:
|
||||
|
||||
- The current directory contains a `mix.exs` file.
|
||||
|
||||
### Options
|
||||
|
||||
| Option | Default | Description |
|
||||
| ---------- | --------------------------------------------------------- | --------------------------------------------------------------- |
|
||||
| ------------------- | --------------------------------------------------------- | --------------------------------------------------------------- |
|
||||
| `symbol` | `"💧 "` | The symbol used before displaying the version of Elixir/Erlang. |
|
||||
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
|
||||
| `detect_files` | `["mix.exs"]` | Which filenames should trigger this module. |
|
||||
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||
| `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. |
|
||||
|
|
|
@ -8,6 +8,9 @@ pub struct ElixirConfig<'a> {
|
|||
pub symbol: &'a str,
|
||||
pub style: &'a str,
|
||||
pub disabled: bool,
|
||||
pub detect_extensions: Vec<&'a str>,
|
||||
pub detect_files: Vec<&'a str>,
|
||||
pub detect_folders: Vec<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
|
||||
|
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ElixirConfig<'a> {
|
|||
symbol: "💧 ",
|
||||
style: "bold purple",
|
||||
disabled: false,
|
||||
detect_extensions: vec![],
|
||||
detect_files: vec!["mix.exs"],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,11 +12,16 @@ Erlang/OTP (?P<otp>\\d+)[^\\n]+
|
|||
Elixir (?P<elixir>\\d[.\\d]+).*";
|
||||
|
||||
/// Create a module with the current Elixir version
|
||||
///
|
||||
/// Will display the Elixir version if any of the following criteria are met:
|
||||
/// - Current directory contains a `mix.exs` file
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let is_elixir_project = context.try_begin_scan()?.set_files(&["mix.exs"]).is_match();
|
||||
let mut module = context.new_module("elixir");
|
||||
let config = ElixirConfig::try_load(module.config);
|
||||
|
||||
let is_elixir_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&config.detect_files)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.set_folders(&config.detect_folders)
|
||||
.is_match();
|
||||
|
||||
if !is_elixir_project {
|
||||
return None;
|
||||
|
@ -24,8 +29,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||
|
||||
let versions = Lazy::new(|| get_elixir_version(context));
|
||||
|
||||
let mut module = context.new_module("elixir");
|
||||
let config = ElixirConfig::try_load(module.config);
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|var, _| match var {
|
||||
|
|
Loading…
Reference in New Issue