feat(erlang): Configure when the module is shown (#2346)
* feat(erlang): Configure when the module is shown This makes it possible to configure when the erlang 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. * Update docs/config/README.md Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com> Co-authored-by: Shu Kutsuzawa <cappyzawa@gmail.com>
This commit is contained in:
parent
7331e4bec6
commit
873a005c42
|
@ -944,19 +944,22 @@ default = "unknown shell"
|
||||||
## Erlang
|
## Erlang
|
||||||
|
|
||||||
The `erlang` module shows the currently installed version of Erlang/OTP.
|
The `erlang` module shows the currently installed version of 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 `rebar.config` file.
|
- The current directory contains a `rebar.config` file.
|
||||||
- The current directory contains a `erlang.mk` file.
|
- The current directory contains a `erlang.mk` file.
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| ---------- | ---------------------------------- | -------------------------------------------------------- |
|
| ------------------- | ------------------------------------ | -------------------------------------------------------- |
|
||||||
| `symbol` | `" "` | The symbol used before displaying the version of erlang. |
|
| `symbol` | `" "` | The symbol used before displaying the version of erlang. |
|
||||||
| `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. |
|
| `detect_extensions` | `[]` | Which extensions should trigger this module. |
|
||||||
| `disabled` | `false` | Disables the `erlang` module. |
|
| `detect_files` | `["rebar.config", "elang.mk"]` | Which filenames should trigger this module. |
|
||||||
|
| `detect_folders` | `[]` | Which folders should trigger this modules. |
|
||||||
|
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `erlang` module. |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,9 @@ pub struct ErlangConfig<'a> {
|
||||||
pub symbol: &'a str,
|
pub symbol: &'a str,
|
||||||
pub style: &'a str,
|
pub style: &'a str,
|
||||||
pub disabled: bool,
|
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 ErlangConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for ErlangConfig<'a> {
|
||||||
|
@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for ErlangConfig<'a> {
|
||||||
symbol: " ",
|
symbol: " ",
|
||||||
style: "bold red",
|
style: "bold red",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
detect_extensions: vec![],
|
||||||
|
detect_files: vec!["rebar.config", "erlang.mk"],
|
||||||
|
detect_folders: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,21 @@ use crate::configs::erlang::ErlangConfig;
|
||||||
use crate::formatter::StringFormatter;
|
use crate::formatter::StringFormatter;
|
||||||
|
|
||||||
/// Create a module with the current Erlang version
|
/// Create a module with the current Erlang version
|
||||||
///
|
|
||||||
/// Will display the Erlang version if any of the following criteria are met:
|
|
||||||
/// - Current directory contains a rebar.config file
|
|
||||||
/// - Current directory contains a erlang.mk file
|
|
||||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
|
let mut module = context.new_module("erlang");
|
||||||
|
let config = ErlangConfig::try_load(module.config);
|
||||||
|
|
||||||
let is_erlang_project = context
|
let is_erlang_project = context
|
||||||
.try_begin_scan()?
|
.try_begin_scan()?
|
||||||
.set_files(&["rebar.config", "erlang.mk"])
|
.set_files(&config.detect_files)
|
||||||
|
.set_extensions(&config.detect_extensions)
|
||||||
|
.set_folders(&config.detect_folders)
|
||||||
.is_match();
|
.is_match();
|
||||||
|
|
||||||
if !is_erlang_project {
|
if !is_erlang_project {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut module = context.new_module("erlang");
|
|
||||||
let config = ErlangConfig::try_load(module.config);
|
|
||||||
|
|
||||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||||
formatter
|
formatter
|
||||||
.map_meta(|variable, _| match variable {
|
.map_meta(|variable, _| match variable {
|
||||||
|
|
Loading…
Reference in New Issue